1
0
mirror of https://github.com/dzeiocom/libs.git synced 2025-04-22 10:52:11 +00:00
libs/packages/object-util
dependabot[bot] 329f1ee06d
Bump ts-node from 9.1.1 to 10.2.1 (#37)
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 9.1.1 to 10.2.1.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](https://github.com/TypeStrong/ts-node/compare/v9.1.1...v10.2.1)

---
updated-dependencies:
- dependency-name: ts-node
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-28 17:40:52 +02:00
..
2021-09-28 11:47:33 +02:00
2021-09-28 11:47:33 +02:00
2020-10-20 15:11:30 +02:00
2021-05-21 16:34:08 +02:00
2020-12-08 15:50:31 +01:00
2021-09-28 11:47:33 +02:00
2020-09-11 10:43:07 +02:00

Object Util

Utility functions to manipulate an object

Usage

  • Import Object Util
import { objectMap, ... } from '@dzeio/object-util'
// or
const {objectMap, ...} = require('@dzeio/object-util')
  • or import it from the browser
<script src="https://cdn.jsdelivr.net/npm/@dzeio/object-util@1/dist/browser.js"></script>
<!-- each functions will be available as window.{objectMap, ...} or {objectMap, ...}-->
  • explore !

// Does the same as Array.map
objectMap(object, (value, key) => value + "pouet")

// does the same as Array.forEach with the addition of stopping if false is returned (like break)
// and return if loop was stopped or not
objectLoop(object, (value, key) => {})

// return the values of an object as an array
objectValues(object)

// return the keys of an object as an array
ObjectKeys(object)

// return the count of an object keys
objectSize(object)

// like Array.sort it sort and return an ordered object
objectSort(object, /*optionnal*/ (key1, key2) => key1 - key2)

// You can also sort by keys
// items not set in the array won't have their order changed and will be after the sorted ones
objectSort(object, ['key2', 'key1']) // => {key2: value, key1: value, key3: value}

// deeply clone an object
cloneObject(object)

// deeply set an object value while creating empty childs if necessary
//ex: this will set {path1, [{path3: 'value'}]} if object is an empty object
objectSet(object, ['path1', 0, 'path3'], 'value')

// deeply compare two objects
objectEqual(object, object2)

// deeply clean an object from undefined, null variables
objectClean(object, /* optionnal, defaults */{cleanUndefined: true, cleanNull: false, deep: true})

// clone (not deeply) an object and remove the keys from the object, 'a' and 'b' for this one
objectOmit(object, 'a', 'b')

// check if a variable is an object
isObject(object)

note: with the exception of isObject, every function will throw an error if the object is not an object