@wiitate/utilities
v1.4.1
Published
## Summary
Downloads
3
Readme
@wiitate/utilities
Summary
This package consists of some useful functions
Core
- getArrayGroups()
getArrayGroups([1, 2, 3, 4, 5, 6], 3);
# => [[1, 2,] [3, 4,] [5, 6]]
- isJsonString()
isJsonString('"value"');
# => false
isJsonString('{ "key": "value" }');
# => true
- nameComparison()
nameComparison('AbC', 'aBc');
# => true
- arrayBreakdown()
arrayBreakdown([1, 2, 3]);
# => [[1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
- trimObject()
trimObject({a: 'a b c', b: ' abc', c: 'abc '});
# => { a: 'a b c', b: 'abc', c: 'abc' }
- camelizeKeys()
camelizeKeys({ full_name: 'fullName', obj_key: { child_key: 'value' } });
# => { fullName: 'fullName', 'objKey': { childKey: 'value' } }
- wait()
console.time("time");
await wait(5000);
console.timeEnd("time");
# => time: 5s
- parseJsonString()
console.log(parseJsonString('{"key":"value"}'))
# => { key: 'value' }
Mongoose
- convertObject()
new Schema(
{ ... },
{
...
toJSON: {
transform: (_, ret) => convertObject(ret),
...
},
toObject: {
transform: (_, ret) => convertObject(ret),
...
},
},
);
- convertSelectFieldsToProjection()
convertSelectFieldsToProjection(['_id', 'name']);
# => { _id: 1, name: 1 }