Data-Mate: `Transforms Record Transform`
Table of contents
Variables
Functions
Variables
repository
• Const
repository: Repository
Defined in
data-mate/src/transforms/record-transform.ts:6
Functions
copyField
▸ copyField(input
, _parentContext
, args
): ts.AnyObject
| null
Will copy a field to another field
Parameters
Name | Type |
---|---|
input | RecordInput |
_parentContext | RecordInput |
args | Object |
args.from | string |
args.to | string |
Returns
ts.AnyObject
| null
object
Example
const obj = { hello: 'world', other: 'stuff' };
const config = { from: 'other', to: 'myCopy' };
const results = RecordTransform.copyField(cloneDeep(obj), cloneDeep(obj), config);
results; // { hello: 'world', other: 'stuff', myCopy: 'stuff' };
Defined in
data-mate/src/transforms/record-transform.ts:213
dedupe
▸ dedupe<T
>(input
, _parentContext?
): T
[] | null
returns an array with only unique values
Type parameters
Name | Type |
---|---|
T | any |
Parameters
Name | Type |
---|---|
input | any [] |
_parentContext? | unknown [] |
Returns
T
[] | null
returns null if input is null/undefined
Example
const results = FieldTransform.dedupe([1, 2, 2, 3, 3, 3, undefined, 4])
results === [1, 2, 3, 4]
const results = RecordTransform.dedupe([
{ hello: 'world' },
{ hello: 'world' },
{ other: 'obj' },
])
results === [{ hello: 'world' }, { other: 'obj' }];
Defined in
data-mate/src/transforms/record-transform.ts:305
dropFields
▸ dropFields(input
, _parentContext
, args
): ts.AnyObject
| null
removes fields from a record
Parameters
Name | Type |
---|---|
input | RecordInput |
_parentContext | RecordInput |
args | Object |
args.fields | string [] |
Returns
ts.AnyObject
| null
object
Example
const obj = { hello: 'world', other: 'stuff', last: 'thing' };
const config = { fields: ['other', 'last']} ;
const results = RecordTransform.dropFields(cloneDeep(obj), cloneDeep(obj), config);
results; // { hello: 'world' };
Defined in
data-mate/src/transforms/record-transform.ts:167
renameField
▸ renameField(input
, _parentContext
, args
): ts.AnyObject
| null
This will migrate a fields value to a new field name
Parameters
Name | Type |
---|---|
input | RecordInput |
_parentContext | RecordInput |
args | Object |
args.from | string |
args.to | string |
Returns
ts.AnyObject
| null
object
Example
const obj = { hello: 'world' };
const config = { from: 'hello', to: 'goodbye' };
const results = RecordTransform.renameField(cloneDeep(obj), cloneDeep(obj), config);
results === { goodbye: 'world' };
Defined in
data-mate/src/transforms/record-transform.ts:80
setField
▸ setField(input
, _parentContext
, args
): ts.AnyObject
| null
Sets a field on a record with the given value
Parameters
Name | Type |
---|---|
input | RecordInput |
_parentContext | RecordInput |
args | Object |
args.field | string |
args.value | any |
Returns
ts.AnyObject
| null
object
Example
const obj = { hello: 'world' };
const config = { field: 'other', value: 'stuff' };
const results = RecordTransform.setField(cloneDeep(obj), cloneDeep(obj), config);
results === { hello: 'world', other: 'stuff' };
Defined in
data-mate/src/transforms/record-transform.ts:125
transformRecord
▸ transformRecord(_input
, _parentContext
, _args
): ts.AnyObject
| null
Will execute a jexl expression. Can use data-mate functions inside the jexl expression. You do not need to specify the parent context argument as that is automatically the document used as to call it.
Parameters
Name | Type |
---|---|
_input | RecordInput |
_parentContext | RecordInput |
_args | any |
Returns
ts.AnyObject
| null
object
Example
const obj = { hello: 'world', other: 'stuff' };
const config = { query: '[hello]', field: 'final' };
const results = RecordTransform.transformRecord(clone, clone, config)
results === { hello: 'world', other: 'stuff', final: ['world'] });
const obj = { foo: 'bar' };
const config = {
jexlExp: 'foo|extract({ jexlExp: "foo|toUpperCase" })', field: 'final'
};
const mixedData = [obj, undefined, null];
const results = RecordTransform.transformRecord(
mixedData, mixedData, config
)
results === [{ foo: 'bar', final: 'BAR' }];