@terascope/data-mate / transforms/field-transform
transforms/field-transform
Index
Interfaces
Interface | Description |
---|---|
FormatDateConfig | - |
ParseDateConfig | - |
Variables
repository
const
repository:Repository
Source
data-mate/src/transforms/field-transform.ts:16
Functions
decodeBase64()
decodeBase64(
input
,_parentContext
?):string
|string
[] |null
decodes a base64 encoded value if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const str = 'hello world';
const encoded = encodeBase64(str);
const results = FieldTransform.decodeBase64(encoded)
results === str
FieldTransform.decodeBase64([encoded]) === [str]
Source
data-mate/src/transforms/field-transform.ts:693
decodeHex()
decodeHex(
input
,_parentContext
?):string
|string
[] |null
decodes the hex encoded input if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const source = 'hello world';
const encoded = encodeHex(source);
FieldTransform.decodeHex(encoded); // source;
FieldTransform.decodeHex([encoded]); // [source];
Source
data-mate/src/transforms/field-transform.ts:798
decodeURL()
decodeURL(
input
,_parentContext
?):string
|string
[] |null
decodes a URL encoded value if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | StringInput | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const source = 'HELLO AND GOODBYE';
const encoded = 'HELLO%20AND%20GOODBYE';
FieldTransform.decodeURL(encoded); // source;
FieldTransform.decodeURL([encoded]); //[source];
Source
data-mate/src/transforms/field-transform.ts:748
encodeBase64()
encodeBase64(
input
,_parentContext
?):string
|string
[] |null
converts a value into a base64 encoded value if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const str = 'hello world';
const encodedValue = FieldTransform.encodeBase64(str);
const arrayOfEncodedValues = FieldTransform.encodeBase64([str]);
Source
data-mate/src/transforms/field-transform.ts:720
encodeHex()
encodeHex(
input
,_parentContext
?):string
|string
[] |null
hex encodes the input if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const source = 'hello world';
FieldTransform.encodeHex(source);
const arrayOfEncodedValues = FieldTransform.encodeHex([source]);
Source
data-mate/src/transforms/field-transform.ts:825
encodeMD5()
encodeMD5(
input
,_parentContext
?):string
|string
[] |null
MD5 encodes the input if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const source = 'hello world';
FieldTransform.encodeMD5(source);
const arrayOfEncodedValues = FieldTransform.encodeHex([source]);
Source
data-mate/src/transforms/field-transform.ts:850
encodeSHA()
encodeSHA(
input
,_parentContext
?,__namedParameters
?):string
|string
[] |null
SHA encodes the input to the hash specified
- if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | * |
_parentContext ? | unknown | - |
__namedParameters ? | object | - |
__namedParameters.digest ? | undefined | string | - |
__namedParameters.hash ? | undefined | string | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
*
* const data = 'some string';
* const config = { hash: 'sha256', digest: 'hex'};
* fieldTransform.encodeSHA(data , {}, config)
* const arrayOfEncodedValues = FieldTransform.encodeSHA([source], {}, config);
*
*
Source
data-mate/src/transforms/field-transform.ts:882
encodeSHA1()
encodeSHA1(
input
,_parentContext
?):string
|string
[] |null
converts the value to a SHA1 encoded value if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const source = 'hello world';
FieldTransform.encodeSHA1(source);
const arrayOfEncodedValues = FieldTransform.encodeSHA([source]);
Source
data-mate/src/transforms/field-transform.ts:917
encodeURL()
encodeURL(
input
,_parentContext
?):string
|string
[] |null
URL encodes a value if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | StringInput | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const source = 'HELLO AND GOODBYE';
const encoded = 'HELLO%20AND%20GOODBYE';
FieldTransform.encodeURL(source); // encoded;
const arrayOfEncodedValues = FieldTransform.encodeURL([source]);
Source
data-mate/src/transforms/field-transform.ts:773
extract()
extract(
_input
,_parentContext
,_args
):any
|null
Can extract values from a string input. You may either specify a regex, a jexl expression, or specify the start and end from which the extraction will take all values between if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type |
---|---|
_input | unknown |
_parentContext | AnyObject |
_args | ExtractFieldConfig |
Returns
any
| null
returns null if input is null/undefined
Example
const config = { start: '<', end: '>' }
const results1 = FieldTransform.extract('<hello>', { field: '<hello>' }, config);
results1; // 'hello';
const results2 = FieldTransform.extract('bar', { foo: 'bar' }, { jexlExp: '[foo]' });
results2; // ['bar'];
const results3 = FieldTransform.extract('hello', { field: 'hello'}, { regex: 'he.*' });
results3; // ['hello'];
const config2 = { regex: 'he.*', isMultiValue: false };
const results = FieldTransform.extract('hello', { field: 'hello'}, config2);
results; // 'hello';
const context = { field: ['<hello>', '<world>'] };
const results = FieldTransform.extract(['<hello>', '<world>'], context, config);
results; // ['hello', 'world'];
Source
data-mate/src/transforms/field-transform.ts:1066
formatDate()
formatDate(
input
,_parentContext
,args
):string
|string
[] |null
Function that will format a number or date string to a given date format provided
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext | unknown | - |
args | FormatDateConfig | format is the shape that the date will be, resolution is only needed when input is a number |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const config = { format: 'MMM do yy' };
const results1 = FieldTransform.formatDate('2020-01-14T20:34:01.034Z', {}, config)
results1 === 'Jan 14th 20';
const results2 = FieldTransform.formatDate('March 3, 2019', {}, { format: 'M/d/yyyy' })
results2 === '3/3/2019';
const config = { format: 'yyyy-MM-dd', resolution: 'seconds' };
const results3 = FieldTransform.formatDate(1581013130, {}, config)
results3 === '2020-02-06';
const config = { format: 'yyyy-MM-dd' };
const results = FieldTransform.formatDate([1581013130856, undefined], {}, config)
results // ['2020-02-06']);
Source
data-mate/src/transforms/field-transform.ts:1356
map()
map(
input
,parentContext
,args
):any
[] |null
This function is used to map an array of values with any FieldTransform method
Parameters
Parameter | Type | Description |
---|---|---|
input | any [] | an array of any value |
parentContext | any [] | - |
args | object | fn any FieldTransform function name, options is an object with any additional parameters needed |
args.fn | string | - |
args.options ? | any | - |
Returns
any
[] | null
returns the mapped values, return null if input is null/undefined
Example
const array = ['hello', 'world', 'goodbye'];
const results = FieldTransform.map(array, array, { fn: 'truncate', options: { size: 3 } }
results === ['hel', 'wor', 'goo']
Source
data-mate/src/transforms/field-transform.ts:345
parseDate()
parseDate(
input
,_parentContext
,args
):Date
| (Date
|null
)[] |null
Will use date-fns parse against the input and return a date object
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext | unknown | - |
args | ParseDateConfig |
Returns
Date
| (Date
| null
)[] | null
returns null if input is null/undefined
Example
const result = FieldTransform.parseDate('2020-01-10-00:00', {}, { format: 'yyyy-MM-ddxxx' })
result === new Date('2020-01-10T00:00:00.000Z');
const result = FieldTransform.parseDate('Jan 10, 2020-00:00', {}, { format: 'MMM dd, yyyyxxx' })
result === new Date('2020-01-10T00:00:00.000Z');
const result = FieldTransform.parseDate(1581025950223, {}, { format: 'T' })
result === new Date('2020-02-06T21:52:30.223Z');
const result = FieldTransform.parseDate(1581025950, {}, { format: 't' })
result === new Date('2020-02-06T21:52:30.000Z');
const result = FieldTransform.parseDate('1581025950', {} { format: 't' })
result === new Date('2020-02-06T21:52:30.000Z');
Source
data-mate/src/transforms/field-transform.ts:1418
parseJSON()
parseJSON(
input
,_parentContext
?):any
|null
Parses the json input if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
Returns
any
| null
returns null if input is null/undefined
Example
const obj = { hello: 'world' };
const json = JSON.stringify(obj);
const results = FieldTransform.parseJSON(json);
results === obj
FieldTransform.parseJSON([json]); // [obj]
Source
data-mate/src/transforms/field-transform.ts:948
replaceLiteral()
replaceLiteral(
input
,_parentContext
,__namedParameters
):string
|string
[] |null
This function replaces the searched value with the replace value
Parameters
Parameter | Type | Description |
---|---|---|
input | StringInput | |
_parentContext | unknown | - |
__namedParameters | ReplaceLiteralConfig | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const context = { key: 'Hi bob' };
FieldTransform.replaceLiteral('Hi bob', context, { search: 'bob', replace: 'mel' }) === 'Hi mel';
FieldTransform.replaceLiteral('Hi Bob', context, { search: 'bob', replace: 'Mel' }) === 'Hi Bob';
const data = ['Hi bob', 'hello bob'];
const config = { search: 'bob', replace: 'mel' };
FieldTransform.replaceLiteral(data, {}, config) // ['Hi mel', 'hello mel'];
Source
data-mate/src/transforms/field-transform.ts:1144
replaceRegex()
replaceRegex(
input
,_parentContext
,__namedParameters
):string
|string
[] |null
This function replaces chars in a string based off the regex value provided
Parameters
Parameter | Type | Description |
---|---|---|
input | StringInput | |
_parentContext | unknown | - |
__namedParameters | ReplaceRegexConfig | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const config1 = { regex: 's|e', replace: 'd' };
const results1 = FieldTransform.replaceRegex('somestring', {}, config1)
results1 === 'domestring'
const config2 = { regex: 's|e', replace: 'd', global: true };
const results2 = FieldTransform.replaceRegex('somestring', {}, config)
results2 === 'domddtring'
const config3 = {
regex: 'm|t', replace: 'W', global: true, ignoreCase: true
};
const results3 = FieldTransform.replaceRegex('soMesTring', {}, config3))
results3 === 'soWesWring'
Source
data-mate/src/transforms/field-transform.ts:1098
setDefault()
setDefault(
input
,_parentContext
,args
):any
This function is used to set a value if input is null or undefined, otherwise the input value is returned
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext | unknown | - |
args | object | value is what will be given when input is null/undefined |
args.value | any | - |
Returns
any
Example
const results = FieldTransform.setDefault(undefined, {}, { value: 'someValue' });
results === 'someValue';
Source
data-mate/src/transforms/field-transform.ts:322
setField()
setField(
_input
,_parentContext
,args
):any
This function is not meant to be used programmatically
please use RecordTransform.setField
instead
Parameters
Parameter | Type | Description |
---|---|---|
_input | unknown | This value will be discarded |
_parentContext | unknown | - |
args | object | value will be used to set field |
args.value | any | - |
Returns
any
Source
data-mate/src/transforms/field-transform.ts:369
splitString()
splitString(
input
,_parentContext
?,args
?):string
[] |string
[][] |null
Converts a string to an array of characters split by the delimiter provided
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
args ? | object | delimter defaults to an empty string |
args.delimiter ? | string | - |
Returns
string
[] | string
[][] | null
Example
FieldTransform.splitString('astring'); // ['a', 's', 't', 'r', 'i', 'n', 'g'];
FieldTransform.splitString('astring', {}, { delimiter: ',' }); // ['astring'];
expect(FieldTransform.splitString(
'a-stri-ng', {}, { delimiter: '-' }
)).toEqual(['a', 'stri', 'ng']);
Source
data-mate/src/transforms/field-transform.ts:1183
toBoolean()
toBoolean(
input
,_parentContext
?):boolean
|boolean
[] |null
Converts values to booleans if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
Returns
boolean
| boolean
[] | null
returns null if input is null/undefined
Example
FieldTransform.toBoolean('0'); // false
FieldTransform.toBoolean(['foo', 'false', null]); // [true, false];
Source
data-mate/src/transforms/field-transform.ts:407
toCamelCase()
toCamelCase(
input
,_parentContext
?):string
|string
[] |null
Will convert a string, or an array of strings to camel case;
Parameters
Parameter | Type | Description |
---|---|---|
input | string | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
FieldTransform.toCamelCase('I need camel case'); // 'iNeedCamelCase';
FieldTransform.toCamelCase('happyBirthday'); // 'happyBirthday';
FieldTransform.toCamelCase('what_is_this'); // 'whatIsThis';
const array = ['what_is_this', 'I need camel case'];
FieldTransform.toCamelCase(array); // ['whatIsThis', 'iNeedCamelCase'];
Source
data-mate/src/transforms/field-transform.ts:1447
toGeoPoint()
toGeoPoint(
input
,_parentContext
?):object
|object
[] |null
Converts the value into a geo-point if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
Returns
object
| object
[] | null
returns null if input is null/undefined
Example
fieldTransform.toGeoPoint('60, 40'); // { lon: 40, lat: 60 };
fieldTransform.toGeoPoint([40, 60]); // { lon: 40, lat: 60 };
fieldTransform.toGeoPoint({ lat: 40, lon: 60 }); // { lon: 60, lat: 40 };
fieldTransform.toGeoPoint({ latitude: 40, longitude: 60 }); // { lon: 60, lat: 40 }
const results = FieldTransform.toGeoPoint(['60, 40', null, [50, 60]]);
results === [{ lon: 40, lat: 60 },{ lon: 50, lat: 60 }];
Source
data-mate/src/transforms/field-transform.ts:1013
toISDN()
toISDN(
input
,_parentContext
?):string
|string
[] |null
Parses a string or number to a fully validated phone number if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | string | string[] | number | number[] |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
a fully validated phone number, returns null if input is null/undefined
Example
FieldTransform.toISDN('+33-1-22-33-44-55'); // '33122334455';
FieldTransform.toISDN('1(800)FloWErs'); // '18003569377';
FieldTransform.toISDN(['1(800)FloWErs','+33-1-22-33-44-55' ]); // ['18003569377', '33122334455'];
Source
data-mate/src/transforms/field-transform.ts:623
toISO8601()
toISO8601(
input
,_parentContext
?,args
?):string
|string
[] |null
Converts a date string or number to an ISO date
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
args ? | object | if input is a number, you may specify the resolution of that number, defaults to seconds |
args.resolution ? | "seconds" | "milliseconds" | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
FieldTransform.toISO8601('2020-01-01'); // '2020-01-01T00:00:00.000Z';
const config = { resolution: 'seconds' };
FieldTransform.toISO8601(1580418907, {}, config); // '2020-01-30T21:15:07.000Z';
const data = ['2020-01-01', '2020-01-02'];
FieldTransform.toISO8601(data); // ['2020-01-01T00:00:00.000Z', '2020-01-02T00:00:00.000Z'];
Source
data-mate/src/transforms/field-transform.ts:1285
toJSON()
toJSON(
input
,_parentContext
?,__namedParameters
?):string
|string
[] |null
Converts input to JSON if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
__namedParameters ? | object | - |
__namedParameters.pretty ? | undefined | boolean | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const obj = { hello: 'world' };
FieldTransform.toJSON(obj); // '{"hello": "world"}'
FieldTransform.toJSON([obj]); // ['{"hello": "world"}']
Source
data-mate/src/transforms/field-transform.ts:976
toKebabCase()
toKebabCase(
input
,_parentContext
?):string
|string
[] |null
Will convert a string, or an array of strings to kebab case
Parameters
Parameter | Type | Description |
---|---|---|
input | string | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
FieldTransform.toKebabCase('I need kebab case'); // 'i-need-kebab-case';
FieldTransform.toKebabCase('happyBirthday'); // 'happy-birthday';
FieldTransform.toKebabCase('what_is_this'); // 'what-is-this';
FieldTransform.toKebabCase('this-should-be-kebab'); // 'this-should-be-kebab';
const array = ['happyBirthday', 'what_is_this']
FieldTransform.toKebabCase(array); // ['happy-birthday', 'what-is-this'];
Source
data-mate/src/transforms/field-transform.ts:1472
toLowerCase()
toLowerCase(
input
,_parentContext
?):string
|string
[] |null
Converts strings to lowercase if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | StringInput | string | string[] |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
FieldTransform.toLowerCase('UPPERCASE'); // 'uppercase';
FieldTransform.toLowerCase(['MixEd', null, 'UPPER']); // ['mixed', 'upper'];
Source
data-mate/src/transforms/field-transform.ts:451
toNumber()
toNumber(
input
,_parentContext
?,args
?):number
|number
[] |null
Converts a value to a number if possible if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
args ? | object | |
args.booleanLike ? | boolean | - |
Returns
number
| number
[] | null
returns null if input is null/undefined
Example
FieldTransform.toNumber('12321'); // 12321;
FieldTransform.toNumber('000011'); // 11;
FieldTransform.toNumber('true', {}, { booleanLike: true }); // 1;
FieldTransform.toNumber(null, {}, { booleanLike: true }); // 0;
FieldTransform.toNumber(null); // null;
FieldTransform.toNumber(['000011', '12321']); // [11, 12321];
Source
data-mate/src/transforms/field-transform.ts:661
toPascalCase()
toPascalCase(
input
,_parentContext
?):string
|string
[] |null
Converts a string, or an array of strings to pascal case
Parameters
Parameter | Type | Description |
---|---|---|
input | string | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
FieldTransform.toPascalCase('I need pascal case'); // 'INeedPascalCase';
FieldTransform.toPascalCase('happyBirthday'); // 'HappyBirthday';
FieldTransform.toPascalCase('what_is_this'); // 'WhatIsThis';
const array = ['happyBirthday', 'what_is_this']
FieldTransform.toKebabCase(array); // ['HappyBirthday', 'WhatIsThis'];
Source
data-mate/src/transforms/field-transform.ts:1496
toSnakeCase()
toSnakeCase(
input
,_parentContext
?):string
|string
[] |null
Converts a string, or an array of strings to snake case
Parameters
Parameter | Type | Description |
---|---|---|
input | string | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
FieldTransform.toSnakeCase('I need snake case'); // 'i_need_snake_case';
FieldTransform.toSnakeCase('happyBirthday'); // 'happy_birthday';
FieldTransform.toSnakeCase('what_is_this'); // 'what_is_this';
const array = ['happyBirthday', 'what_is_this']
FieldTransform.toKebabCase(array); // ['happy_birthday', 'what_is_this'];
Source
data-mate/src/transforms/field-transform.ts:1517
toString()
toString(
input
,_parentContext
?):string
|string
[] |null
Converts values to strings if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
FieldTransform.toString(true); // 'true';
FieldTransform.toString([true, undefined, false]); // ['true', 'false'];
Source
data-mate/src/transforms/field-transform.ts:387
toTitleCase()
toTitleCase(
input
,_parentContext
?):string
|string
[] |null
Converts a string, or an array of strings to title case
Parameters
Parameter | Type | Description |
---|---|---|
input | string | |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
FieldTransform.toTitleCase('I need some capitols'); // 'I Need Some Capitols';
FieldTransform.toTitleCase('happyBirthday'); // 'Happy Birthday';
FieldTransform.toTitleCase('what_is_this'); // 'What Is This';
Source
data-mate/src/transforms/field-transform.ts:1535
toUnixTime()
toUnixTime(
input
,_parentContext
?,__namedParameters
?):number
|number
[] |null
Converts a given date to its time in milliseconds or seconds
Parameters
Parameter | Type | Description |
---|---|---|
input | unknown | |
_parentContext ? | unknown | - |
__namedParameters ? | object | - |
__namedParameters.ms ? | undefined | boolean | - |
Returns
number
| number
[] | null
returns null if input is null/undefined
Example
FieldTransform.toUnixTime('2020-01-01'); // 1577836800;
FieldTransform.toUnixTime('Jan 1, 2020 UTC'); // 1577836800;
FieldTransform.toUnixTime('2020 Jan, 1 UTC'); // 1577836800;
FieldTransform.toUnixTime(1580418907000); // 1580418907;
FieldTransform.toUnixTime(1580418907000, {}, { ms: true }); // 1580418907000;
FieldTransform.toUnixTime(['Jan 1, 2020 UTC', '2020 Jan, 1 UTC']); // [1577836800, 1577836800];
Source
data-mate/src/transforms/field-transform.ts:1239
toUpperCase()
toUpperCase(
input
,_parentContext
?):string
|string
[] |null
Converts strings to UpperCase if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | StringInput | string or string[] |
_parentContext ? | unknown | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
FieldTransform.toUpperCase('lowercase'); // 'LOWERCASE';
FieldTransform.toUpperCase(['MixEd', null, 'lower']); // ['MIXED', 'LOWER'];
Source
data-mate/src/transforms/field-transform.ts:427
trim()
trim(
input
,parentContext
?,args
?):string
|string
[] |null
Will trim the input if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | StringInput | string | string[] |
parentContext ? | unknown | - |
args ? | object | a single char or word that will be cut out |
args.char ? | string | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
FieldTransform.trim('right '); // 'right';
FieldTransform.trim('fast cars race fast', {}, { char: 'fast' }); // ' cars race ';
FieldTransform.trim(' string ')).toBe('string');
FieldTransform.trim(' left')).toBe('left');
FieldTransform.trim('.*.*a regex test.*.*.*.* stuff', {}, { char: '.*' }); // 'a regex test'
FieldTransform.trim('\t\r\rtrim this\r\r', {}, { char: '\r' }); // 'trim this'
FieldTransform.trim(' '); // ''
FieldTransform.trim(['right ', ' left']); // ['right', 'left'];
Source
data-mate/src/transforms/field-transform.ts:482
trimEnd()
trimEnd(
input
,_parentContext
?,args
?):string
|string
[] |null
Will trim the end of the input if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | StringInput | string | string[] |
_parentContext ? | unknown | - |
args ? | object | |
args.char ? | string | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
FieldTransform.trimEnd(' Hello Bob '); // ' Hello Bob';
FieldTransform.trimEnd('iiii-wordiwords-iii', {}, { char: 'i' }); // 'iiii-wordiwords';
FieldTransform.trimEnd([' Hello Bob ', 'right ']); // [' Hello Bob', 'right'];
Source
data-mate/src/transforms/field-transform.ts:545
trimStart()
trimStart(
input
,_parentContext
?,args
?):string
|string
[] |null
Will trim the beginning of the input if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | StringInput | string | string[] |
_parentContext ? | unknown | - |
args ? | object | |
args.char ? | string | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
const config = { char: 'i' };
FieldTransform.trimStart(' Hello Bob '); // 'Hello Bob ';
FieldTransform.trimStart('iiii-wordiwords-iii', {}, config); // '-wordiwords-iii';
FieldTransform.trimStart([' Hello Bob ', 'right ']); // ['Hello Bob ', 'right '];
Source
data-mate/src/transforms/field-transform.ts:513
truncate()
truncate(
input
,_parentContext
,args
):string
|string
[] |null
Will truncate the input to the length of the size given if given an array it will convert everything in the array excluding null/undefined values
Parameters
Parameter | Type | Description |
---|---|---|
input | StringInput | string | string[] |
_parentContext | unknown | - |
args | object | |
args.size | number | - |
Returns
string
| string
[] | null
returns null if input is null/undefined
Example
FieldTransform.truncate('thisisalongstring', {}, { size: 4 }); // 'this';
FieldTransform.truncate(['hello', null, 'world'], {}, { size: 2 }); // ['he', 'wo'];