@sustainhawaii/object-utils

1.12.6 • Public • Published

buildstatus codecov

Object-manupulation utilities.

Change Log

Functions

mapValuesDeep(o, iter, [recursionTest], [params])object

Recursively map an objects values with a function and optional parameters.

mapValuesDeepAsync(obj, iter, [recursionTest], [params], [currentPath])object

Recursively map an objects values with an async function and optional parameters.

isEqualByPath(o1, o2, path)boolean

Return true if objects o1 and o2 are equal at specified path

objArray2KeyValuePairs(arr, key, valKey)*

Convert array of objects to an object whose keys are the values of one key and whose values are the values of another key of each object.

mergeRestrictClean(oldData, newData, [allowedKeys], [options])object | void

Merge newData over oldData. Optionally restrict newData to certain keys before merging. Remove all keys in resulting object that are undefined, null, or empty strings. Return resulting object.

objectHasNewValue(o1, o2, path)boolean

Return true if object o2 has a non-null, non-undefined value different than object o1 at specified path

objectHasNewValues(o1, o2, paths)boolean

Return true if object o2 has a non-null, non-undefined value different than object o1 at any of the specified paths

objectChangesAtPaths(o1, o2, paths)object

Return object with just the changed values at the specified dot-notation paths. Returns empty object if no changes.

pickPathsBy(obj, paths, predicate)*

Combination of lodash pick and pickBy methods. Lets you pick keys from an object using a list of paths, and then filter them by a truthy predicate function.

valueHasInfo(v)boolean

Return true if input value has some information; e.g.: input value is not null, undefined, empty object, array or string

pickPathsWithInfo(obj, paths)object

Return object with selected keys from input obj, excluding values that don't contain any information, such as null, undefined, empty objects, arrays or strings

objectWithoutNonInfoValues(obj)object

Return object excluding values that don't contain any information, such as null, undefined, empty objects, arrays or strings.

addValuesOfObjects(objs)object

Given an array of objects whose values are all numeric, return a single object with the same keys as the FIRST object, with all values summed for each key. Ignores keys from subsequent objects that are not present in first object.

mapValuesToJSON(o)object

Return object with all plain object values as JSON. Useful for breaking up large forms to post as multipart/form-data.

str2bool(str, [tf])boolean | void

Returns true, false, or undefined for 'true', 'false', or other.

mapStringValsToBooleans(obj)object

Recursively converts all of an object's 'true' and 'false' string values to boolean.

mapBooleanValsToStrings(obj, params)object

Recursively converts all of an object's boolean values to 'true' or 'false'

mapValuesDeep(o, iter, [recursionTest], [params]) ⇒ object

Recursively map an objects values with a function and optional parameters.

Kind: global function
Params

  • o object
  • iter function - accepts parameters {val, currentKey, params}
  • [recursionTest] function - if passed, only recurse if returns true
  • [params] object - optional params to pass with each call to iter

mapValuesDeepAsync(obj, iter, [recursionTest], [params], [currentPath]) ⇒ object

Recursively map an objects values with an async function and optional parameters.

Kind: global function
Params

  • obj object
  • iter function - async function; accepts parameters {val, currentPath, params}
  • [recursionTest] function - if passed, only recurse if returns true
  • [params] object - optional params to pass with each call to iter
  • [currentPath] string - cumulative dot-path; only passed on recursive calls

isEqualByPath(o1, o2, path) ⇒ boolean

Return true if objects o1 and o2 are equal at specified path

Kind: global function
Params

  • o1 object
  • o2 object
  • path string

objArray2KeyValuePairs(arr, key, valKey) ⇒ *

Convert array of objects to an object whose keys are the values of one key and whose values are the values of another key of each object.

Kind: global function
Params

  • arr
  • key
  • valKey

mergeRestrictClean(oldData, newData, [allowedKeys], [options]) ⇒ object | void

Merge newData over oldData. Optionally restrict newData to certain keys before merging. Remove all keys in resulting object that are undefined, null, or empty strings. Return resulting object.

Kind: global function
Params

objectHasNewValue(o1, o2, path) ⇒ boolean

Return true if object o2 has a non-null, non-undefined value different than object o1 at specified path

Kind: global function
Params

  • o1 object
  • o2 object
  • path string

objectHasNewValues(o1, o2, paths) ⇒ boolean

Return true if object o2 has a non-null, non-undefined value different than object o1 at any of the specified paths

Kind: global function
Params

  • o1 object
  • o2 object
  • paths Array.<string>

objectChangesAtPaths(o1, o2, paths) ⇒ object

Return object with just the changed values at the specified dot-notation paths. Returns empty object if no changes.

Kind: global function
Params

  • o1 object
  • o2 object
  • paths Array.<string> - dot-notation paths

pickPathsBy(obj, paths, predicate) ⇒ *

Combination of lodash pick and pickBy methods. Lets you pick keys from an object using a list of paths, and then filter them by a truthy predicate function.

Kind: global function
Params

  • obj
  • paths
  • predicate

valueHasInfo(v) ⇒ boolean

Return true if input value has some information; e.g.: input value is not null, undefined, empty object, array or string

Kind: global function
Params

  • v *

pickPathsWithInfo(obj, paths) ⇒ object

Return object with selected keys from input obj, excluding values that don't contain any information, such as null, undefined, empty objects, arrays or strings

Kind: global function
Params

  • obj object
  • paths array

objectWithoutNonInfoValues(obj) ⇒ object

Return object excluding values that don't contain any information, such as null, undefined, empty objects, arrays or strings.

Kind: global function
Params

  • obj object

addValuesOfObjects(objs) ⇒ object

Given an array of objects whose values are all numeric, return a single object with the same keys as the FIRST object, with all values summed for each key. Ignores keys from subsequent objects that are not present in first object.

Kind: global function
Params

  • objs Array.<object>

mapValuesToJSON(o) ⇒ object

Return object with all plain object values as JSON. Useful for breaking up large forms to post as multipart/form-data.

Kind: global function
Params

  • o object

str2bool(str, [tf]) ⇒ boolean | void

Returns true, false, or undefined for 'true', 'false', or other.

Kind: global function
Params

  • str string
  • [tf] boolean - if set, return true if matches boolified str

mapStringValsToBooleans(obj) ⇒ object

Recursively converts all of an object's 'true' and 'false' string values to boolean.

Kind: global function
Params

  • obj object

mapBooleanValsToStrings(obj, params) ⇒ object

Recursively converts all of an object's boolean values to 'true' or 'false'

Kind: global function
Params

  • obj object
  • params any

Change Log

4.5.1 - 12-01-18

Changed
  • Updated dependencies

4.5.0 - 24-11-17

Added
  • keysAreDirty method

4.4.3 - 24-11-17

Changed
  • minor documentation additions

4.4.2 - 24-11-17

Fixed
  • minor documentation errors

4.4.1 - 24-11-17

Fixed
  • minor documentation errors

4.4.0 - 24-11-17

Added
  • copyPFObjectAttributes method
  • pfObjectMatch method
  • getId method
  • isPFObjectOrPointer method
  • getPFObject method
  • sortPFObjectsByKey method
  • isArrayOfPFObjects method
Changed
  • isPFObject method now checks for ParseObjectSubclass constructor as well as instanceOf Parse.Object
  • constrainQuery and getJoinQuery methods now accept multiple constraints of the same type, such as three equalTo's.
  • getJoinQuery can now be passed pointers.
  • TypeError is now thrown when invalid parameters are passed to getJoinQuery, joinWithTable, unJoinWithTable methods.
  • Switched testing platform from Mocha/Chai to Jest.
  • Switched testing version of mongodb from parse-mockdb to mongodb-memory-server.

4.3.3 - 11-11-17

Changed
  • Remove links from change log as I can't get jsdoc-to-markdown to generate them correctly.

4.3.1 - 4.3.2 - 11-11-17

Fixed
  • README

4.3.0 - 11-11-17

Added
  • constrainQuery method, which newQuery now uses for optional constraints.
Changed
  • newQuery method now supports all query constraints (instead of just limit, skip, select and include).

4.2.1 - 08-11-17

Fixed
  • README

4.2.0 - 08-11-17

Added
  • Support for calling joinWithTable with two Parse.Object instances, while still supporting the original parameter format.
  • Examples for join-table methods.
Changed
  • Improved some other documentation.

4.1.0 - 05-11-17

Fixed
  • getPointer method was generating pseudo pointers that did not have a fetch function.
  • Addressed deprecation notice for the mocha "compilers" option
Added
  • Added optional 'ofClass' param to isPointer method to check if it is a pointer of a specific class.
  • 'include' option to newQuery method
  • Added support for getting nested values from pointer columns to objGetDeep method.

4.0.1 - 26-10-17

(trying to get NPM to update README)

4.0.0 - 26-10-17

BREAKING CHANGES
  • getClass method now creates constructors for special classes 'User,' 'Role,' and 'Session' with 'Parse[],' but still creates constructors for custom classes with 'Parse.Object.extend().'
  • getClass method now throws a TypeError if not passed a string, which it should have done anyway.
  • The above changes to getClass method affect getClassInst method because it always uses getClass method.
  • The above changes to getClass method affect newQuery method because it uses getClass method when passed a string.
  • Added back 'use strict'
Fixed
  • getUserById was passing the Parse.User constructor rather than an instance of Parse.User to getObjById, which was then trying to use it in a Parse.Query, but Parse.Query requires class instances or names.
Added
  • getPointer method
  • sample code for objGetDeep

3.7.6 - 3.7.7 - 23-10-17

Changed
  • Minor README changes, but published in order to get NPM to show the last few updates to README.

3.7.5 - 23-10-17

Changed
  • Minor jsdoc fixes.

3.7.4 - 23-10-17

Fixes
  • Uses 'browser' field in package.json to hint to webpack, browserify to substitute 'parse' for 'parse/node'

Versions 3.7.1 - 3.7.3 - 22-10-17

Changed
  • Minor README changes

3.7.0 - 22-10-17

Non-Breaking Change:
  • Exports a class with static methods, rather than a frozen singleton instance. It is still used the same way; it's just no longer a frozen instance of the class.
Added
  • setParse method, which allows you to override the instance of the Parse JS SDK used by the module. (By default, the module will try to use the Parse instance from the global scope. If none exists, it will use the node or browser based on which environment is detected by the 'detect-is-node' module.) If you wish to use the setParse method, do it after you initialize your Parse instance and set the masterKey. (See "Usage" section at the top of this file.)

3.6.0 - 21-10-17

Added
  • getClass method.
  • objGetDeep method.
  • classStringOrSpecialClass method.
Changed
  • userHasRole method rejects when passed invalid params
Fixed
  • Switched test framework from jest to mocha+chai because of issue between jest and parse-mockdb module.

3.5.4 - 17-10-17

Fixed
  • The way isPointer recognizes of one of the 3 different types of pointer objects it checks for.

3.5.3 - 17-10-17

Changed
  • isPointer method' recognizes 3 different types of pointer objects.
  • More thorough tests for isPFObject method, including invalidating pointers.
  • More thorough tests for isUser method.

3.5.2 - 16-10-17

Bug fixes
  • isPointer method was restricting to plain objects.

3.5.2 - 16-10-17

Changed
  • Minor jsdoc fixes.

3.5.0 - 16-10-17

Added
  • fetchIfNeeded method.
  • isPointer method.

3.4.0 - 14-10-17

Changed
  • Refactored into two files -- one for node environments and one for browsers. Reason: Runtime environment detection is too unreliable, even using "detect-node" module, because of problems running in webpack-dev-server.
  • a "browser" option in package.json as a hint to babel, browserify, etc. to use the browser version.

3.3.0 - 13-10-17

Added
  • isUser method

3.2.0 - 11-10-17

Added
  • getUserRoles method returns array of names of user's direct roles.

3.1.0 - 08-10-17

Added
  • userHasRole method can check if a user has any or all of an array of roles.
Changed
  • Improved documentation of newQuery method

3.0.0 - 03-10-17

BREAKING CHANGES
  • getJoinQuery signature has changed: The 'select' parameter has been removed. Instead, set a 'select' key in the 2nd options param object for use by newQuery method.
Added
  • newQuery method accepts a 'select' key in its 2nd parameter to select fields to restrict results to.
Other Changed
  • Improved documentation.

2.0.8 - 22-09-17

Changed
  • Improved ci config.
  • Moved Change Log to bottom of README.

2.0.7 - 21-09-17

Changed
  • Removed commitizen.

2.0.6 - 21-09-17

Changed
  • Removed semantic-release for now.

2.0.5 - 21-09-17

Changed
  • Reconfigured ci.

2.0.4 - 21-09-17

Changed
  • codecov reporting and badge.
  • Reduced minimum required node to 4.

2.0.3 - 21-09-17

Changed
  • 100% test coverage with jest.
  • Use different branch of parse-shim to account for parse already being loaded in cloud code.
Bug Fixed
  • Use different branch of parse-shim to correctly detect when running in browser or node to import correct parse version.

2.0.2 - 20-09-17

Added
  • userHasRole method
Changed
  • all methods that access the database now accept optional sessionToken
  • isPFObject now accepts an optional class name param
  • can pass array of field names, in addition to comma-separated list, to getJoinQuery
Breaking Changed
  • If unJoinWithTable can't unjoin objects, it returns a promise that resolves to undefined instead of null.

Package Sidebar

Install

npm i @sustainhawaii/object-utils

Weekly Downloads

2

Version

1.12.6

License

ISC

Unpacked Size

54.2 kB

Total Files

11

Last publish

Collaborators

  • nidhinmathew
  • basavarajaut
  • abhisustain
  • muralisustain
  • anirsustain
  • cksh