{"id":22282006,"url":"https://github.com/xcritical-software/utilitify","last_synced_at":"2025-07-13T19:08:10.756Z","repository":{"id":40791808,"uuid":"211263989","full_name":"xcritical-software/utilitify","owner":"xcritical-software","description":"The utilities for working with a collections such as objects, arrays and primitives such as numbers, strings, etc.","archived":false,"fork":false,"pushed_at":"2023-01-06T02:11:19.000Z","size":1519,"stargazers_count":2,"open_issues_count":31,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-25T23:28:35.360Z","etag":null,"topics":["javascript","json","merge-deep","primitives"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xcritical-software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2019-09-27T07:43:17.000Z","updated_at":"2021-03-19T14:14:59.000Z","dependencies_parsed_at":"2023-02-05T02:31:11.080Z","dependency_job_id":null,"html_url":"https://github.com/xcritical-software/utilitify","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/xcritical-software/utilitify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcritical-software%2Futilitify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcritical-software%2Futilitify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcritical-software%2Futilitify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcritical-software%2Futilitify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xcritical-software","download_url":"https://codeload.github.com/xcritical-software/utilitify/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xcritical-software%2Futilitify/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265191214,"owners_count":23725283,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","json","merge-deep","primitives"],"created_at":"2024-12-03T16:24:30.822Z","updated_at":"2025-07-13T19:08:10.731Z","avatar_url":"https://github.com/xcritical-software.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# utilitify\n\u003e The utilities for working with a collections such as objects, arrays and primitives such as numbers, strings, etc.\n\n[![Build Status](https://travis-ci.com/xcritical-software/utilitify.svg?branch=master)](https://travis-ci.com/xcritical-software/utilitify)\n\n## Install\n\nInstall with [yarn](https://yarnpkg.com/):\n\n```sh\n$ yarn add utilitify\n```\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save utilitify\n```\n\n## Usage\n\nThese utilities include a different methods for working with JavaScript collections and primitives.\n\nFor example, if you want to merge two objects recursively, you can use a method 'mergeDeep':\n\n```js\nimport { mergeDeep } from 'utilitify';\n\nmergeDeep({ a: { b: { c: 'c', d: 'd' } } }, { a: { b: { e: 'e', f: 'f' } } });\n//=\u003e { a: { b: { c: 'c', d: 'd', e: 'e', f: 'f' } } }\n```\n\nYou can find all methods in API section.\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ yarn \u0026\u0026 yarn test\n```\n\n\u003c/details\u003e\n\n## API\n\n#### `mergeDeep`\n\n\u003e Recursively merge values in a javascript object.\n\n```js\nimport { mergeDeep } from 'utilitify';\n\nmergeDeep({ a: 1, b: [2, 3] }, { b: [3, 4], c: 3 });\n//=\u003e { a: 1, b: [2, 3, 4], c: 3 }\n```\n\n#### `cloneDeep`\n\n\u003e Recursively (deep) clone JavaScript native types, like Object, Array, RegExp, Date as well as primitives.\n\n```js\nimport { cloneDeep } from 'utilitify';\n\nconst obj = { a: 'b' };\nconst arr = [obj];\nconst copy = cloneDeep(arr);\nobj.c = 'd';\n \nconsole.log(copy);\n//=\u003e [{ a: 'b' }]\n \nconsole.log(arr);\n//=\u003e [{ a: 'b', c: 'd' }]\n```\n\n#### `cloneShallow`\n\n\u003e Creates a shallow clone of any JavaScript value.\n\n```js\nimport { cloneShallow } from 'utilitify';\n\nconst arr = [{ a: 0 }, { b: 1 }];\nconst foo = cloneShallow(arr);\n// foo =\u003e  [{ 'a': 0 }, { 'b': 1 }]\n \n// array is cloned\nassert(actual === expected); // false\n \n// array elements are not\nassert.deepEqual(actual[0], expected[0]); // true\n```\n\n#### `union`\n\n\u003e Combines a list of arrays, returning a single array with unique values, using strict equality for comparisons.\n\n```js\nimport { union } from 'utilitify';\n\nunion(['a'], ['b', 'c'], ['d', 'e', 'f']);\n//=\u003e ['a', 'b', 'c', 'd', 'e', 'f']\n\nunion(['a', 'a'], ['b', 'c']);\n//=\u003e ['a', 'b', 'c']\n```\n\n#### `isObject`\n\n\u003e Check if any JavaScript value is object.\n\n```js\nimport { isObject } from 'utilitify';\n\nconst obj = { a: 1, b: 2 };\n\nisObject(obj);\n//=\u003e true\n\nisObject(1);\n//=\u003e false\n```\n\n#### `isNil`\n\n\u003e Check if any JavaScript value is null or undefined.\n\n```js\nimport { isNil } from 'utilitify';\n\nconst obj = { a: 1, b: 2 };\n\nisNil(obj);\n//=\u003e false\n\nisNil(null);\n//=\u003e true\n```\n\n#### `isNull`\n\n\u003e Check if any JavaScript value is null.\n\n```js\nimport { isNull } from 'utilitify';\n\nisNull(undefined);\n//=\u003e false\n\nisNull(null);\n//=\u003e true\n```\n\n#### `isUndefined`\n\n\u003e Check if any JavaScript value is undefined.\n\n```js\nimport { isUndefined } from 'utilitify';\n\nisUndefined(null);\n//=\u003e false\n\nisUndefined(undefined);\n//=\u003e true\n```\n\n#### `getObjectWithoutEmptyPropsFrom`\n\n\u003e Remove from object all values which equal 'null', 'undefined' or empty string.\n\n```js\nimport { getObjectWithoutEmptyPropsFrom } from 'utilitify';\n\nconst objectWithEmptyProps = {\n  a: 1,\n  b: null,\n  c: 'string',\n  d: undefined,\n  e: '',\n};\n\ngetObjectWithoutEmptyPropsFrom(objectWithEmptyProps);\n//=\u003e { a: 1, c: 'string' }\n```\n\n#### `getObjectWithoutUndefinedPropsFrom`\n\n\u003e Remove from object all values which equal 'undefined'.\n\n```js\nimport { getObjectWithoutUndefinedPropsFrom } from 'utilitify';\n\nconst objectWithUndefinedProps = {\n  a: 1,\n  b: null,\n  c: 'string',\n  d: undefined,\n  e: '',\n};\n\ngetObjectWithoutUndefinedPropsFrom(objectWithUndefinedProps);\n//=\u003e { a: 1, b: null, c: 'string', e: '' }\n```\n\n#### `getTruncatedString`\n\n\u003e Get truncated string by number of symbols (second argument) with punctuation mark on the end if need.\n\n```js\nimport { getTruncatedString } from 'utilitify';\n\ngetTruncatedString('string', 3);\n//=\u003e str\n\ngetTruncatedString('string', 3, '...');\n//=\u003e str...\n```\n\n#### `upsertObjectToArray`\n\n\u003e Update object in array. If object does not exist, method push new value (third argument) to array.\n\n```js\nimport { upsertObjectToArray } from 'utilitify';\n\nconst arr = [{ a: 1 }, { b: 2 }];\n\nupsertObjectToArray(arr, { a: 1 }, { a: 3 });\nconsole.log(arr);\n//=\u003e [{ a: 3 }, { b: 2 }]\n```\n\n#### `getObjectFromArrayByProp`\n\n\u003e Get object from array by it's property.\n\n```js\nimport { getObjectFromArrayByProp } from 'utilitify';\n\nconst arr = [{ a: 1 }, { b: 2 }];\n\ngetObjectFromArrayByProp(arr, 'a');\n//=\u003e { a: 1 }\n```\n\n#### `getArrayOfObjectsWithoutProp`\n\n\u003e Get new array of objects from which are deleted property (second argument).\n\n```js\nimport { getArrayOfObjectsWithoutProp } from 'utilitify';\n\nconst arr = [{ a: 1, c: 10 }, { b: 2 }];\n\ngetArrayOfObjectsWithoutProp(arr, 'a');\n//=\u003e [{ c: 10 }, { b: 2 }]\n```\n\n#### `isJsonString`\n\n\u003e Check if string is JSON.\n\n```js\nimport { isJsonString } from 'utilitify';\n\nconst str = '{\"a\":2}';\n\nisJsonString(str);\n//=\u003e true\n```\n\n#### `getJsonFromString`\n\n\u003e Get JSON from string if possibly. If string is not valid JSON string, method returns empty object.\n\n```js\nimport { getJsonFromString } from 'utilitify';\n\nconst validStr = '{\"a\":2}';\nconst invalidStr = '{a:2}';\n\ngetJsonFromString(validStr);\n//=\u003e { a: 2 }\n\ngetJsonFromString(invalidStr);\n//=\u003e {}\n```\n\n#### `toPascalCase`\n\n\u003e Convert any string to 'PascalCase' string.\n\n```js\nimport { toPascalCase } from 'utilitify';\n\ntoPascalCase('pascal case');\n//=\u003e PascalCase\n```\n\n#### `compose`\n\n\u003e Compose several functions which return some result.\n\n```js\nimport { compose } from 'utilitify';\n\nconst inc = (value) =\u003e value + 1;\nconst mul2 = (value) =\u003e value * 2;\n\ncompose(inc, mul2)(1);\n//=\u003e 4\n```\n\n#### `setIn`\n\n\u003e Set new value (second argument) in object by property (third argument) and return new object.\n\n```js\nimport { setIn } from 'utilitify';\n\nconst obj = {\n  a: 1,\n  b: 2,\n  c: {\n    d: 3,\n  },\n};\n\nconst result = setIn(obj, 5, 'd.f.r');\nconsole.log(result);\n//=\u003e { a: 1, b: 2, c: { d: 3 }, d: { f: { r: 5 } } }\n```\n\n#### `delIn`\n\n\u003e Delete property (second argument) in object and return new object.\n\n```js\nimport { delIn } from 'utilitify';\n\nconst obj = {\n  a: 1,\n  b: 2,\n  c: {\n    d: 3,\n  },\n};\n\nconst result = delIn(obj, 'c.d');\nconsole.log(result);\n//=\u003e { a: 1, b: 2, c: {} }\n```\n\n#### `difference`\n\n\u003e Compare two objects (or arrays) and return a new object (or array) who represent the diff.\n\n```js\nimport { difference } from 'utilitify';\n\nconst obj = {\n  a: 1,\n  b: 2,\n  c: {\n    d: 3,\n  },\n};\n\nconst obj2 = {\n  c: {\n    d: {\n      f: 5,\n    },\n  },\n  g: 5,\n};\n\nconst testObj = { ...obj, ...obj2 };\n\nconst result = difference(obj, testObj);\nconsole.log(result);\n//=\u003e { c: { d: 3 } }\n```\n\n#### `isDifference`\n\n\u003e Compare two objects (or arrays) and return 'true' if equal or 'false' if not.\n\n```js\nimport { isDifference } from 'utilitify';\n\nconst arr1 = [1, 2, 3];\n\nconst arr2 = [2, 3, 4];\n\nisDifference(arr1, arr2);\n//=\u003e true\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxcritical-software%2Futilitify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxcritical-software%2Futilitify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxcritical-software%2Futilitify/lists"}