Data
Deep Clone
import { deepClone } from '@basalt-lab/basalt-helper';
const data1: { test: { test: string } } = {
test: {
test: 'test'
}
};
const data2: number[][] = [[1, 2, 3], [4, 5, 6]];
const data3: { test: { test: number[] } } = {
test: {
test: [1, 2, 3]
}
};
const data4: Array<{ test: number[] }> = [
{
test: [1, 2, 3]
},
{
test: [4, 5, 6]
}
];
const clonedData1: { test: { test: string } } = deepClone(data1);
const clonedData2: number[][] = deepClone(data2);
const clonedData3: { test: { test: number[] } } = deepClone(data3);
const clonedData4: Array<{ test: number[] }> = deepClone(data4);
console.log(clonedData1 === data1);
console.log(clonedData2 === data2);
console.log(clonedData3 === data3);
console.log(clonedData4 === data4);
const { deepClone } = require('@basalt-lab/basalt-helper');
const data1 = {
test: {
test: 'test'
}
};
const data2 = [[1, 2, 3], [4, 5, 6]];
const data3 = {
test: {
test: [1, 2, 3]
}
};
const data4 = [
{
test: [1, 2, 3]
},
{
test: [4, 5, 6]
}
];
const clonedData1 = deepClone(data1);
const clonedData2 = deepClone(data2);
const clonedData3 = deepClone(data3);
const clonedData4 = deepClone(data4);
console.log(clonedData1 === data1);
console.log(clonedData2 === data2);
console.log(clonedData3 === data3);
console.log(clonedData4 === data4);
node example.jsfalse
false
false
false
Include only certain keys
import { filterByKeyInclusion } from '@basalt-lab/basalt-helper';
const data: { a: string; b: string; c: string; d: string } = {
a: 'a',
b: 'b',
c: 'c',
d: 'd',
};
const filteredData = filterByKeyInclusion(data, ['a', 'b', 'c']);
console.log(filteredData);
const { filterByKeyInclusion } = require('@basalt-lab/basalt-helper');
const data = {
a: 'a',
b: 'b',
c: 'c',
d: 'd',
};
const filteredData = filterByKeyInclusion(data, ['a', 'b', 'c']);
console.log(filteredData);
node example.js{ a: 'a', b: 'b', c: 'c' }
Include only certain keys and only if they have a value
import { filterByKeyInclusion } from '@basalt-lab/basalt-helper';
const data: { a: string; b: undefined; c: null; d: string } = {
a: 'a',
b: undefined,
c: null,
d: 'd',
};
const filteredData = filterByKeyInclusion(data, ['a', 'b', 'c'], true);
console.log(filteredData);
const { filterByKeyInclusion } = require('@basalt-lab/basalt-helper');
const data = {
a: 'a',
b: undefined,
c: null,
d: 'd',
};
const filteredData = filterByKeyInclusion(data, ['a', 'b', 'c'], true);
console.log(filteredData);
node example.js{ a: 'a' }
Exclude certain keys
import { filterByKeyExclusion } from '@basalt-lab/basalt-helper';
const data: { a: string; b: string; c: string; d: string } = {
a: 'a',
b: 'b',
c: 'c',
d: 'd',
};
const filteredData = filterByKeyExclusion(data, ['a', 'b']);
console.log(filteredData);
const { filterByKeyExclusion } = require('@basalt-lab/basalt-helper');
const data = {
a: 'a',
b: 'b',
c: 'c',
d: 'd',
};
const filteredData = filterByKeyExclusion(data, ['a', 'b']);
console.log(filteredData);
node example.js{ c: 'c', d: 'd' }
Exclude certain keys and exclude those that have no value
import { filterByKeyExclusion } from '@basalt-lab/basalt-helper';
const data: { a: string; b: null; c: undefined; d: string } = {
a: 'a',
b: null,
c: undefined,
d: 'd',
};
const filteredData = filterByKeyExclusion(data, ['a'], true);
console.log(filteredData);
const { filterByKeyExclusion } = require('@basalt-lab/basalt-helper');
const data = {
a: 'a',
b: null,
c: undefined,
d: 'd',
};
const filteredData = filterByKeyExclusion(data, ['a'], true);
console.log(filteredData);
node example.js{ d: 'd' }
Include keys based on a pattern
import { filterByValue } from '@basalt-lab/basalt-helper';
const data: { a: string; b: string; c: string; d: string } = {
a: 'a',
b: 'b',
c: 'c',
d: 'd',
};
const filteredData = filterByValue(data, (value: string): boolean => value === 'a' || value === 'b');
console.log(filteredData);
const { filterByValue } = require('@basalt-lab/basalt-helper');
const data = {
a: 'a',
b: 'b',
c: 'c',
d: 'd',
};
const filteredData = filterByValue(data, (value) => value === 'a' || value === 'b');
console.log(filteredData);
node example.js{ a: 'a', b: 'b' }
Exclude keys based on a pattern
import { filterByValue } from '@basalt-lab/basalt-helper';
const data: { a: string; b: string; c: string; d: string } = {
a: 'a',
b: 'b',
c: 'c',
d: 'd',
};
const filteredData = filterByValue(data, (value: string): boolean => value !== 'a' && value !== 'b');
console.log(filteredData);
const { filterByValue } = require('@basalt-lab/basalt-helper');
const data = {
a: 'a',
b: 'b',
c: 'c',
d: 'd',
};
const filteredData = filterByValue(data, (value) => value !== 'a' && value !== 'b');
console.log(filteredData);
node example.js{ c: 'c', d: 'd' }
Exclude keys based on a pattern and exclude those that have no value
import { filterByValue } from '@basalt-lab/basalt-helper';
const data: { a: string; b: null; c: undefined; d: string } = {
a: 'a',
b: null,
c: undefined,
d: 'd',
};
const filteredData = filterByValue(data, (value: unknown): boolean => value !== 'a', true);
console.log(filteredData);
const { filterByValue } = require('@basalt-lab/basalt-helper');
const data = {
a: 'a',
b: null,
c: undefined,
d: 'd',
};
const filteredData = filterByValue(data, (value) => value !== 'a', true);
console.log(filteredData);
node example.js{ d: 'd' }
import { transformKeys, BasaltCamelCaseTransformer } from '@basalt-lab/basalt-helper';
const data = {
'camelCase': undefined,
'PascalCase': undefined,
'kebab-case': undefined,
'snake_case': undefined
};
console.log(transformKeys(data, new BasaltCamelCaseTransformer()));
const { transformKeys, BasaltCamelCaseTransformer } = require('@basalt-lab/basalt-helper');
const data = {
'camelCase': undefined,
'PascalCase': undefined,
'kebab-case': undefined,
'snake_case': undefined
};
console.log(transformKeys(data, new BasaltCamelCaseTransformer()));
node example.js{
camelCase: undefined,
pascalCase: undefined,
kebabCase: undefined,
snakeCase: undefined
}
import { transformKeys, BasaltPascalCaseTransformer } from '@basalt-lab/basalt-helper';
const data = {
'camelCase': undefined,
'PascalCase': undefined,
'kebab-case': undefined,
'snake_case': undefined
};
console.log(transformKeys(data, new BasaltPascalCaseTransformer()));
const { transformKeys, BasaltPascalCaseTransformer } = require('@basalt-lab/basalt-helper');
const data = {
'camelCase': undefined,
'PascalCase': undefined,
'kebab-case': undefined,
'snake_case': undefined
};
console.log(transformKeys(data, new BasaltPascalCaseTransformer()));
node example.js{
CamelCase: undefined,
PascalCase: undefined,
KebabCase: undefined,
SnakeCase: undefined
}
import { transformKeys, BasaltKebabCaseTransformer } from '@basalt-lab/basalt-helper';
const data = {
'camelCase': undefined,
'PascalCase': undefined,
'kebab-case': undefined,
'snake_case': undefined
};
console.log(transformKeys(data, new BasaltKebabCaseTransformer()));
const { transformKeys, BasaltKebabCaseTransformer } = require('@basalt-lab/basalt-helper');
const data = {
'camelCase': undefined,
'PascalCase': undefined,
'kebab-case': undefined,
'snake_case': undefined
};
console.log(transformKeys(data, new BasaltKebabCaseTransformer()));
node example.js{
'camel-case': undefined,
'pascal-case': undefined,
'kebab-case': undefined,
'snake-case': undefined
}
import { transformKeys, BasaltSnakeCaseTransformer } from '@basalt-lab/basalt-helper';
const data = {
'camelCase': undefined,
'PascalCase': undefined,
'kebab-case': undefined,
'snake_case': undefined
};
console.log(transformKeys(data, new BasaltSnakeCaseTransformer()));
const { transformKeys, BasaltSnakeCaseTransformer } = require('@basalt-lab/basalt-helper');
const data = {
'camelCase': undefined,
'PascalCase': undefined,
'kebab-case': undefined,
'snake_case': undefined
};
console.log(transformKeys(data, new BasaltSnakeCaseTransformer()));
node example.js{
camel_case: undefined,
pascal_case: undefined,
kebab_case: undefined,
snake_case: undefined
}