{"id":27443056,"url":"https://github.com/mrbing47/qutyl","last_synced_at":"2025-04-15T01:18:44.944Z","repository":{"id":214152799,"uuid":"735826807","full_name":"mrbing47/qutyl","owner":"mrbing47","description":"A directory containing some of the useful utility functions.","archived":false,"fork":false,"pushed_at":"2024-02-03T06:39:50.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T01:18:29.695Z","etag":null,"topics":["assert","compare","difference","groupby","intersection","javascript","merge","parent","range","set","symmetricdifference","union","utility","utility-library","zip"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/qutyl","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrbing47.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-26T07:29:13.000Z","updated_at":"2023-12-30T04:37:51.000Z","dependencies_parsed_at":"2023-12-30T05:20:58.281Z","dependency_job_id":"970dc9c3-74a6-47f9-80b9-d6b9f824315c","html_url":"https://github.com/mrbing47/qutyl","commit_stats":null,"previous_names":["mrbing47/util","mrbing47/qutyl","mrbing47/qutil"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrbing47%2Fqutyl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrbing47%2Fqutyl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrbing47%2Fqutyl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrbing47%2Fqutyl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrbing47","download_url":"https://codeload.github.com/mrbing47/qutyl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986312,"owners_count":21194025,"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":["assert","compare","difference","groupby","intersection","javascript","merge","parent","range","set","symmetricdifference","union","utility","utility-library","zip"],"created_at":"2025-04-15T01:18:44.334Z","updated_at":"2025-04-15T01:18:44.922Z","avatar_url":"https://github.com/mrbing47.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\n\nThis is a repository containing some of the useful util functions.\n\n## Install\n\nTo use this library in your code,\n\n```bash\nnpm i qutyl\n```\n\nHowever, you can install the package from any other package-manager (like yarn, bun, etc.) which forks from NPM Registry.\n\n---\n\n## addParent\n\nThis function creates a **deep copy** and adds the reference to the parent object in `this` for function to access the object tree.\n\n#### Usage\n\n```Javascript\n\nconst { addParent } = require(\"qutyl\");\n\nconst obj = {\n\ta: 10,\n\tfoo: {\n\t\tbar(){\n\t\t\tconsole.log(this.parent.a);\n\t\t}\n\t}\n}\n\nconst newObj = addParent(obj);\n\nnewObj.foo.bar();\n// 10\n```\n\n## assert\n\nThis is a function accepts a predicate function and returns a function accepting _value_ and _...message_ and throws an **error** if predicate is returns true with _value_ or returns the _value_.\n\n#### Usage\n\n```Javascript\nconst { assert } = require(\"qutyl\");\n\nconst assertFalsey = assert((value) =\u003e !!value);\n\ntry{\n\tassertFalsey(\"\", \"Error: A falsey value has been passed.\");\n}catch(error){\n\tconsole.log(error.message);\n\t// Error: A falsey value has been passed.\n}\n\nconst assertUndefined = assert((value) =\u003e value == undefined);\n\ntry{\n\tassertUndefined(undefined, \"Error: An undefined value has been passed.\");\n}catch(error){\n\tconsole.log(error.message);\n\t// Error: An undefined value has been passed.\n}\n\ntry{\n\tlet value = assertUndefined(10, \"Error: Can not perform binary operation on undefined.\");\n\tconsole.log(value);\n\t// 10\n}catch(error){\n\tconsole.log(error.message);\n}\n```\n\n## compare\n\nThis function performs a deep **SameValueZero** check on all the values of an object and array or on a simple primitive variable. For object type, it checks for keys and values, for arrays, it first sorts the values and then compares the values, for other, **SameValueZero** is used.\n\n#### Flags\n\nIn order to tune the the comparision according to your needs, use the following flags:\n\n```Javascript\nconst { compare } = require(\"qutyl\")\n\ncompare.TYPE\n// Only checks for the type of two values.\n\ncompare.LENGTH\n// For objects, arrays and string, first checks the type and then it checks for length, skipping the elements comparision.\n\ncompare.SKIP.SORT\n// For arrays, the function first sorts them in order to compare them, but if you have know that passed arguments are sorted, use this flag to skip the sorting process.\n```\n\n#### Usage\n\n```Javascript\nconst { compare } = require(\"qutyl\");\n\nconst foo = {\n\ta: 1,\n\twow: {\n\t\tx: {\n\t\t\ty: {\n\t\t\t\tz: 20\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst temp = {\n\ta: 1,\n\twow: {\n\t\tx: {\n\t\t\ty: {\n\t\t\t\tz: 20\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst bar = {\n\tb: 2,\n\te: 10\n};\n\nconst blah = {\n\tc: 2,\n\td: 3,\n\tf: 20\n};\n\n\n\ncompare(foo, bar);\n// false\n\ncompare(foo, temp);\n// true\n\ncompare(blah, bar);\n// false\n\ncompare(foo, bar, compare.TYPE);\n// true\n\ncompare(foo, bar, compare.LENGTH);\n// true\n\ncompare(foo, blah, compare.LENGTH);\n// false\n\n\n```\n\n```Javascript\nconst { compare } = require(\"qutyl\");\n\nconst foo = [1,2,3]\nconst bar = [1,2,3,4]\nconst blah = [2,3,1]\nconst wow = {\n\ta: 2\n}\n\ncompare(foo, bar);\n// false\n\ncompare(foo, bar, compare.SKIP.SORT); // does not influence the result but saves extra processing time.\n// false\n\ncompare(foo, bar, compare.TYPE);\n// true\n\ncompare(foo, bar, compare.LENGTH);\n// false\n\ncompare(foo, blah);\n// true\n\ncompare(foo, wow, compare.TYPE);\n// false\n```\n\n```Javascript\nconst { compare } = require(\"qutyl\");\n\ncompare(10, \"10\");\n// false\n\ncompare(10, 10);\n// true\n\ncompare(10, 1);\n// false\n\ncompare(10, 1, compare.TYPE);\n// true\n\ncompare(\"hello\", \"world\")\n// false\n\ncompare(\"hello\", \"world\", compare.LENGTH)\n// true\n\ncompare(NaN, NaN)\n// true\n\ncompare(+0, -0)\n// true\n```\n\n## groupBy\n\nThis function returns an **Object** which contains the classes (defined by passing each element in _classifier_) containing the elements of the array.\n\n\u003e **NOTE:** This has been implemented as **Object.groupBy()** in most browsers but not supported by some runtimes.\n\n#### Usage\n\n```Javascript\nconst { groupBy } = require(\"qutyl\");\n\nconst array = [1,2,3,4,5,6,7,8,9,0];\n\nconst classifier = (element) =\u003e element % 2 ? \"odd\" : \"even\";\n\ngroupBy(array, classifier);\n// {odd: [1,3,5,7,9], even: [2,4,6,8,0]}\n```\n\n## merge\n\nThis function merges the _...args_ arrays passed to it based on the value returned by _evaluator()_.\n\n#### Usage\n\n```Javascript\nconst { merge } = require(\"qutyl\");\n\nconst foo = [2,3,4,7,9];\nconst bar = [0,1,8];\nconst blah = [5,6];\n\nconst evaluator = (element) =\u003e element;\n\nmerge(evaluator, foo, bar, blah)\n// [0,1,2,3,4,5,6,7,8,9]\n```\n\n## range\n\nThis function returns an array containing the elements from including _start_ to excluding _end_ where each element is incremented by _steps_ (default = 1) which should not be equal to 0.\n\nThis function takes either `(end)(start = 1, steps = 1)` or `(start, end)(steps = 1)` or `(start, end, steps)`.\n\n\u003e **NOTE:** This is a mimic to the Python **range()**, however returns an array instead of an iterator.\n\n#### Usage\n\n```Javascript\nconst { range } = require(\"qutyl\");\n\nrange(10);\n// [0,1,2,3,4,5,6,7,8,9]\n\nrange(-10);\n// []\n\nrange(-10, 0);\n// [ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1 ]\n\nrange(0, -10);\n// []\n\nrange(0, -10, -1);\n// [ 0, -1, -2, -3, -4, -5, -6, -7, -8, -9 ]\n\nrange(5, 10);\n// [5, 6, 7, 8, 9]\n\nrange(5, 20, 4);\n// [ 5, 9, 13, 17 ]\n\nrange(0, 10, 0);\n// []\n```\n\n## set\n\nThis contains all the relevant `Set` functions.\n\n#### at\n\nThis function returns the element from a `Set()` from the integer _index_, i.e., it supports both forward(positive) and backward(negative) indexing.\n\n###### Usage\n\n```Javascript\n\nconst { set: { at } } = require(\"qutyl\");\n\nconst foo = new Set([0,1,2,3,4]);\n\nat(foo, -1);\n// 4\n\nat(foo, -2);\n// 3\n\nat(foo, 2);\n// 2\n\nat(foo, 10);\n// undefined\n```\n\n#### difference\n\nAccepts either an `Array` or `Set` and returns a `Set` containing all the element that are unique to the _first_ argument. If the either argument is not of type `Array` or `Set`, it will return **undefined**.\n\n###### Usage\n\n```Javascript\n\nconst { set: { difference } } = require(\"qutyl\");\n\nconst foo = new Set([0,1,2,3,4]);\nconst bar = new Set([0,1,2,5,6,7,8,9]);\n\ndifference(foo, bar);\n// Set([3,4])\n\ndifference(bar, foo);\n// Set([5,6,7,8,9])\n```\n\n#### intersection\n\nAccepts either an `Array` or `Set` and returns a `Set` containing all the element that are common in both arguments. If the either argument is not of type `Array` or `Set`, it will return **undefined**.\n\n###### Usage\n\n```Javascript\n\nconst { set: { intersection } } = require(\"qutyl\");\n\nconst foo = new Set([0,1,2,3,4]);\nconst bar = new Set([0,1,2,5,6,7,8,9]);\n\nintersection(foo, bar);\n// Set([0,1,2])\n```\n\n#### isDisjointFrom\n\nAccepts either an `Array` or `Set` and returns a `boolean` where if _both_ arguments have no common elements then **true**, else **false**. If the either argument is not of type `Array` or `Set`, it will return **undefined**.\n\n###### Usage\n\n```Javascript\nconst { set: { isDisjointFrom } } = require(\"qutyl\");\n\nconst foo = new Set([0,1,2,3,4]);\nconst bar = new Set([0,1,2,5,6,7,8,9]);\nconst blah = new Set([5,6,7,8,9]);\n\nisDisjointFrom(foo, bar);\n// false\n\nisDisjointFrom(foo, blah);\n// true\n```\n\n#### isSubsetOf\n\nAccepts either an `Array` or `Set` and returns a `boolean` where if all the elements in _first_ argument are present in the _second_ argument then **true**, else **false**. If the either argument is not of type `Array` or `Set`, it will return **undefined**.\n\n###### Usage\n\n```Javascript\n\nconst { set: { isSubsetOf } } = require(\"qutyl\");\n\nconst foo = new Set([0,1,2,3,4]);\nconst bar = new Set([0,1,2,5,6,7,8,9]);\nconst blah = new Set([5,6,7,8,9]);\n\nisSubsetOf(foo, bar);\n// false\n\nisSubsetOf(bar, foo);\n// false\n\nisSubsetOf(foo, blah);\n// false\n\nisSubsetOf(blah, bar);\n// true\n\nisSubsetOf(bar, blah);\n// false\n```\n\n#### isSupersetOf\n\nAccepts either an `Array` or `Set` and returns a `boolean` where if _first_ argument contains all the elements from the _second_ argument, then **true**, else **false**. If the either argument is not of type `Array` or `Set`, it will return **undefined**.\n\n###### Usage\n\n```Javascript\n\nconst { set: { isSupersetOf } } = require(\"qutyl\");\n\nconst foo = new Set([0,1,2,3,4]);\nconst bar = new Set([0,1,2,5,6,7,8,9]);\nconst blah = new Set([5,6,7,8,9]);\n\nisSupersetOf(foo, bar);\n// false\n\nisSupersetOf(bar, foo);\n// false\n\nisSupersetOf(foo, blah);\n// false\n\nisSupersetOf(blah, bar);\n// false\n\nisSupersetOf(bar, blah);\n// true\n```\n\n#### symmetricDifference\n\nAccepts either an `Array` or `Set` and returns a `Set` containing all the element that are unique to _both_ arguments and not the common ones. If the either argument is not of type `Array` or `Set`, it will return **undefined**.\n\n###### Usage\n\n```Javascript\nconst { set: { symmetricDifference } } = require(\"qutyl\");\n\nconst foo = new Set([0,1,2,3,4]);\nconst bar = new Set([0,1,2,5,6,7,8,9]);\nconst blah = new Set([5,6,7,8,9]);\n\nsymmetricDifference(foo, bar);\n// Set([3,4,5,6,7,8,9])\n\nsymmetricDifference(foo, blah);\n// Set([0,1,2,3,4,5,6,7,8,9])\n\nsymmetricDifference(bar, blah);\n// Set([0,1,2])\n```\n\n#### union\n\nAccepts either an `Array` or `Set` and returns a `Set` containing all the element from _both_ arguments after removing the duplicates. If the either argument is not of type `Array` or `Set`, it will return **undefined**.\n\n###### Usage\n\n```Javascript\nconst { set: { union } } = require(\"qutyl\");\n\nconst foo = new Set([0,1,2,3,4]);\nconst bar = new Set([0,1,2,5,6,7,8,9]);\n\nunion(foo, bar);\n// Set([0,1,2,3,4,5,6,7,8,9])\n```\n\n## shuffle\n\nThis function accepts an array and returns a new array with all the elements shuffled. If data type is other than _array_, it will return _undefined_.\n\n#### Usage\n\n```Javascript\n\nconst foo = [1, 2, 3, 4, 5, 6, 7]\n\nshuffle(foo)\n// [ 2, 7, 4, 6, 3, 5, 1 ]\n\n\n```\n\n## zip\n\nThis function zips each element of the passed _...arrays_ and returns the resultant array with size of the smallest array in _arrays_.\n\n#### Usage\n\n```Javascript\n\nconst { zip } = require(\"qutyl\");\n\nconst foo = [0,1,2,3,4];\nconst bar = [0,1,2,5,6,7,8,9];\nconst blah = [5,6,7,8,9];\n\nzip(foo, bar, blah);\n/*\n[\n  [ 0, 0, 5 ],\n  [ 1, 1, 6 ],\n  [ 2, 2, 7 ],\n  [ 3, 5, 8 ],\n  [ 4, 6, 9 ]\n]\n*/\n```\n\n## zipAll\n\nThis function zips each element of the passed _...arrays_ and returns the resultant array with size of the largest array in _arrays_ and replaces the missing elements for smaller arrays with **undefined**.\n\n#### Usage\n\n```Javascript\nconst { zipAll } = require(\"qutyl\");\n\nconst foo = [0,1,2,3,4];\nconst bar = [0,1,2,5,6,7,8,9];\nconst blah = [5,6,7,8,9];\n\nzipAll(foo, bar, blah);\n/*\n[\n  [ 0, 0, 5 ],\n  [ 1, 1, 6 ],\n  [ 2, 2, 7 ],\n  [ 3, 5, 8 ],\n  [ 4, 6, 9 ],\n  [ undefined, 7, undefined],\n  [ undefined, 8, undefined ],\n  [ undefined, 9, undefined ]\n]\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrbing47%2Fqutyl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrbing47%2Fqutyl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrbing47%2Fqutyl/lists"}