> ## Documentation Index
> Fetch the complete documentation index at: https://fuse-docs.swovo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# String Columns

> How to add a string column to your importer through code.

You can add a column to your importer directly through the UI of your Fuse account, or you can do so in code using the documentation below.

The String column is the most versatile column type. It accepts any strings, and has a number of different ways to validate or transform values.

## addColumn Function

The `addColumn` function accepts an object as an argument.

* `internal_key` (String) - required: The internal key used to access a column's value.
* `label` (String) - required: The user-facing column label that is shown in the interface.
* `column_type` (String) - required: Should be "string".
* `required` (String) - required: Whether or not the column is required.
* `position` (Optional): The position or order of the column.
* `unique` (Optional): Whether values should be unique.
* `validations` (Optional): An array of built-in data validations. See [Built-in String Validations](#built-in-string-validations).
* `transformations` (Optional): An array of built-in data transformations. See [Built-in String Transformations](#built-in-string-transformations).

### Example Code

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
      const importer = new FuseImporter();

      importer.getSessionToken = ... // see https://fuse-docs.flatirons.com/getting-started/sessions

      const validations = [
        {
          validation_type: "max_length",
          message: "My Label should not be longer than 18 characters",
          options: {
            max_length: 18,
          },
        },
      ];

      const transformations = [
        {
          transformation_type: "lowercase",
        },
      ];

      importer.addColumn({
        internal_key: "my_key",
        label: "My Label",
        column_type: "string",
        required: true,
        position: 1,
        unique: true,
        validations: validations,
        transformations: transformations,
      });

      importer.show();
    ```
  </Tab>

  <Tab title="TypeScript">
    ```typescript theme={null}
      const importer = new FuseImporter();

      importer.getSessionToken = ... // see https://fuse-docs.flatirons.com/getting-started/sessions

      // ColumnValidations should be imported from "fuse-importer"
      const validations: ColumnValidations<"string">[] = [
        {
          validation_type: "max_length",
          message: "My Label should not be longer than 18 characters",
          options: {
            max_length: 18,
          },
        },
      ];

      // ColumnTransformations should be imported from "fuse-importer"
      const transformations: ColumnTransformations<"string">[] = [
        {
          transformation_type: "lowercase",
        },
      ];

      importer.addColumn({
        internal_key: "my_key",
        label: "My Label",
        column_type: "string",
        required: true,
        position: 1,
        unique: true,
        validations: validations,
        transformations: transformations,
      });

      importer.show();
    ```
  </Tab>
</Tabs>

## Built-in String Validations

The `addColumn` object accepts an array of validations. Each validation has three properties:

* `validation_type:` the name of the validation
* `message:` the message showed to the end user if the validation fails
* `options:` options for the specific validation type

The validations property accepts an array of objects that contains these possible values: `validation_type`, `message` and `options`. As the example below:

```javascript theme={null}
validations: [
  {
    validation_type: "cannot_contain",
    message: "Cannot contain 'john'",
    options: {
      pattern: "john",
    },
  },
];
```

### cannot\_contain

Specifies that the column cannot contain a specific pattern.

```javascript theme={null}
validations: [
  {
    validation_type: "cannot_contain",
    message: "Cannot contain 'john'",
    options: {
      pattern: "john",
    },
  },
];
```

### contain

Specifies that column must contain a specific pattern.

```javascript theme={null}
validations: [
  {
    validation_type: "contain",
    message: "Must contain 'john'",
    options: {
      pattern: "john",
    },
  },
];
```

### max\_length

Specifies the maximum character length of the column.

```javascript theme={null}
validations: [
  {
    validation_type: "max_length",
    message: "Must be less than 10 characters",
    options: {
      max_length: 9,
    },
  },
];
```

### min\_length

Specifies the minimum character length of the column.

```javascript theme={null}
validations: [
  {
    validation_type: "min_length",
    message: "Must be at least 10 characters",
    options: {
      min_length: 10,
    },
  },
];
```

### length\_exactly

Specifies the exact length that the column must have.

```javascript theme={null}
validations: [
  {
    validation_type: "length_exactly",
    message: "Must be exactly 10 characters",
    options: {
      length: 10,
    },
  },
];
```

### unique\_case\_sensitive

Specifies that the value must be unique using case-sensitive comparison.

```javascript theme={null}
validations: [
  {
    validation_type: "unique_case_sensitive",
    message: "Must be unique (case sensitive)",
  },
];
```

### unique\_case\_insensitive

Specifies that the value must be unique using case-insensitive comparison.

```javascript theme={null}
validations: [
  {
    validation_type: "unique_case_insensitive",
    message: "Must be unique (case insensitive)",
  },
];
```

### regex

Specifies that the value must match a regex.

```javascript theme={null}
validations: [
  {
    validation_type: "regex",
    message: "Must be a valid domain name",
    options: {
      pattern: /^[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+$/,
    },
  },
];
```

## Built-in String Transformations

The options property of `addColumn` accepts an array of transformations. For the string transformations, you can specify one property:

* `transformation_type:` the name of the transformation

The transformations property accepts an array of objects that contains these possible values: `transformation_type`. As the example below:

```javascript theme={null}
transformations: [
  {
    transformation_type: "trim_whitespace",
  },
];
```

### sentence\_case

This transformation converts all the strings in the column to sentence case. For example, "hello world" becomes "Hello world".

```javascript theme={null}
transformations: [
  {
    transformation_type: "sentence_case",
  },
];
```

### capitalize

This transformation capitalizes the first letter of each string in the column while making the remaining letters lowercase. For example, "apple" becomes "Apple".

```javascript theme={null}
transformations: [
  {
    transformation_type: "capitalize",
  },
];
```

### uppercase

This transformation converts all the strings in the column to uppercase. For example, "hello" becomes "HELLO".

```javascript theme={null}
transformations: [
  {
    transformation_type: "uppercase",
  },
];
```

### lowercase

This transformation converts all the strings in the column to lowercase. For example, "WORLD" becomes "world".

```javascript theme={null}
transformations: [
  {
    transformation_type: "lowercase",
  },
];
```

### trim\_whitespace

This transformation removes any leading or trailing whitespace characters (spaces, tabs, etc.) from each string in the column. For example, " hello " becomes "hello".

```javascript theme={null}
transformations: [
  {
    transformation_type: "trim_whitespace",
  },
];
```
