@wiitate/utilities
TypeScript icon, indicating that this package has built-in type declarations

1.4.1 • Public • Published

@wiitate/utilities

Summary

This package consists of some useful functions

Core

  1. getArrayGroups()
getArrayGroups([1, 2, 3, 4, 5, 6], 3);
# => [[1, 2,] [3, 4,] [5, 6]]
  1. isJsonString()
isJsonString('"value"');
# => false

isJsonString('{ "key": "value" }');
# => true
  1. nameComparison()
nameComparison('AbC', 'aBc');
# => true
  1. arrayBreakdown()
arrayBreakdown([1, 2, 3]);
# => [[1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
  1. trimObject()
trimObject({a: 'a b c', b: ' abc', c: 'abc '});
# => { a: 'a b c', b: 'abc', c: 'abc' }
  1. camelizeKeys()
camelizeKeys({ full_name: 'fullName', obj_key: { child_key: 'value' } });
# => { fullName: 'fullName', 'objKey': { childKey: 'value' } }
  1. wait()
console.time("time");
await wait(5000);
console.timeEnd("time");
# => time: 5s
  1. parseJsonString()
console.log(parseJsonString('{"key":"value"}'))
# => { key: 'value' }

Mongoose

  1. convertObject()
new Schema(
  { ... },
  {
    ...
    toJSON: {
      transform: (_, ret) => convertObject(ret),
      ...
    },
    toObject: {
      transform: (_, ret) => convertObject(ret),
      ...
    },
  },
);
  1. convertSelectFieldsToProjection()
convertSelectFieldsToProjection(['_id', 'name']);
# => { _id: 1, name: 1 }

Readme

Keywords

none

Package Sidebar

Install

npm i @wiitate/utilities

Weekly Downloads

0

Version

1.4.1

License

MIT

Unpacked Size

18.2 kB

Total Files

12

Last publish

Collaborators

  • gknguyen