@lowdefy/helpers
Lowdefy helper functions
Usage
applyArrayIndices
(arrayIndices: number[], name: string): string
Apply arrayIndices to a object id. Substitutes all instances of $ character in name with a index from arrayIndices, until there are no more indices or $'s.
applyArrayIndices([1, 2], 'array.$.subArr.
get
(
target: any,
path: string | number,
options?: {
default?: any,
}
): any
Get a value from a target object, using path with dot-notation. Returns undefined or the optional default value if the value is not found.
get({ a: [{ b: 1 }] }, 'a.0.b'); // returns 1
get({ a: [{ b: 1 }] }, 'a.7.b', { default: 4 }); // returns 4
mergeObjects
(objects: objects[]): object
Merges an array of objects using lodash.merge
mergeObjects([
{ a: 1, c: 4 },
{ a: 2, b: 3 },
]); // returns { a: 2, b: 3, c: 4 }
omit
(object: object, list: string[]): object
Remove an array of keys from a object. Uses unset from this package.
omit({ a: 1, b: 2, c: 3, d: 4 }, ['a', 'd']); // returns { b: 2, c: 3 }
serializer
serializer.copy
serializer.deserialize
serializer.deserializeFromString
serializer.serialize
serializer.serializeToString
set
(
target: any,
path: string,
value: any
): void
Sets a value in a object at a key given by path.
const obj = { a: 1 };
set(obj, 'b.c', 2);
// obj becomes { a: 1, b: { c: 2 } }
stableStringify
(
object: any
options?: {
cmp?: function,
cycles?: boolean,
space?: string | number,
replacer?: function
}
)
Derived from https://github.com/substack/json-stable-stringify
Returns a deterministic JSON stringified object.
swap
(
arr: any[],
from: number,
to: number
)
Swaps the object at the from index with the object at the to index.
swap([0, 1, 2, 3, 4], 2, 3); // returns [0, 1, 3, 2, 4]
type
unset
(object: object, property: 'string')
Unset a property on a object. Supports dot-notation.
const obj = { a: { b: [] } };
unset(obj, 'a.b'); //
// obj becomes { a: {} }
urlQuery
urlQuery.parse
(string: string): object
Parse a urlQuery serialized by urlQuery.stringify.
urlQuery.parse('a=%7B%22b%22%3A%221%22%7D'); // returns { a: { b: '1' } }
urlQuery.stringify
(object: object): string
Serialize a urlQuery object to use as URL query parameters. Nested objects are serialized using serializer.serializeToString.
urlQuery.stringify({ a: { b: '1' } }); // returns 'a=%7B%22b%22%3A%221%22%7D'
More Lowdefy resources
- Getting started with Lowdefy - https://docs.lowdefy.com/tutorial-start
- Lowdefy docs - https://docs.lowdefy.com
- Lowdefy website - https://lowdefy.com
- Community forum - https://github.com/lowdefy/lowdefy/discussions
- Bug reports and feature requests - https://github.com/lowdefy/lowdefy/issues
Licence
); // returns 'array.1.subArr.2'
get
__CODE_BLOCK_2__Get a value from a target object, using path with dot-notation. Returns __INLINE_CODE_4__ or the optional default value if the value is not found.
__CODE_BLOCK_3__mergeObjects
__CODE_BLOCK_4__Merges an array of objects using __INLINE_CODE_5__
__CODE_BLOCK_5__omit
__CODE_BLOCK_6__Remove an array of keys from a object. Uses __INLINE_CODE_6__ from this package.
__CODE_BLOCK_7__serializer
serializer.copy
serializer.deserialize
serializer.deserializeFromString
serializer.serialize
serializer.serializeToString
set
__CODE_BLOCK_8__Sets a value in a object at a key given by path.
__CODE_BLOCK_9__stableStringify
__CODE_BLOCK_10__Derived from https://github.com/substack/json-stable-stringify
Returns a deterministic JSON stringified object.
swap
__CODE_BLOCK_11__Swaps the object at the from index with the object at the to index.
__CODE_BLOCK_12__type
unset
__CODE_BLOCK_13__Unset a property on a object. Supports dot-notation.
__CODE_BLOCK_14__urlQuery
urlQuery.parse
__CODE_BLOCK_15__Parse a urlQuery serialized by urlQuery.stringify.
__CODE_BLOCK_16__urlQuery.stringify
__CODE_BLOCK_17__Serialize a urlQuery object to use as URL query parameters. Nested objects are serialized using __INLINE_CODE_7__.
__CODE_BLOCK_18__More Lowdefy resources
- Getting started with Lowdefy - https://docs.lowdefy.com/tutorial-start
- Lowdefy docs - https://docs.lowdefy.com
- Lowdefy website - https://lowdefy.com
- Community forum - https://github.com/lowdefy/lowdefy/discussions
- Bug reports and feature requests - https://github.com/lowdefy/lowdefy/issues