@visulima/object 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## @visulima/object 1.0.0 (2024-07-16)
2
+
3
+ ### Features
4
+
5
+ * **object:** a new package to work with objects and arrays ([#460](https://github.com/visulima/visulima/issues/460)) ([a674e24](https://github.com/visulima/visulima/commit/a674e24122290e5e8447ee65611ece5f95ac2c1a))
package/LICENSE.md ADDED
@@ -0,0 +1,124 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 visulima
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ <!-- DEPENDENCIES -->
24
+
25
+ # Licenses of bundled dependencies
26
+ The published @visulima/object artifact additionally contains code with the following licenses:
27
+ MIT
28
+
29
+ # Bundled dependencies:
30
+ ## deeks
31
+ License: MIT
32
+ By: mrodrig
33
+ Repository: git+https://github.com/mrodrig/deeks.git
34
+
35
+ ---------------------------------------
36
+
37
+ ## dot-prop
38
+ License: MIT
39
+ By: Sindre Sorhus
40
+ Repository: sindresorhus/dot-prop
41
+
42
+ > MIT License
43
+ >
44
+ > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
45
+ >
46
+ > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
47
+ >
48
+ > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
49
+ >
50
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51
+
52
+ ---------------------------------------
53
+
54
+ ## is-plain-obj
55
+ License: MIT
56
+ By: Sindre Sorhus
57
+ Repository: sindresorhus/is-plain-obj
58
+
59
+ > MIT License
60
+ >
61
+ > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
62
+ >
63
+ > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
64
+ >
65
+ > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
66
+ >
67
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
68
+
69
+ <!-- DEPENDENCIES -->
70
+
71
+ <!-- TYPE_DEPENDENCIES -->
72
+
73
+ # Licenses of bundled types
74
+ The published @visulima/object artifact additionally contains code with the following licenses:
75
+ MIT, (MIT OR CC0-1.0)
76
+
77
+ # Bundled types:
78
+ ## deeks
79
+ License: MIT
80
+ By: mrodrig
81
+ Repository: git+https://github.com/mrodrig/deeks.git
82
+
83
+ ---------------------------------------
84
+
85
+ ## dot-prop
86
+ License: MIT
87
+ By: Sindre Sorhus
88
+ Repository: sindresorhus/dot-prop
89
+
90
+ > MIT License
91
+ >
92
+ > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
93
+ >
94
+ > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
95
+ >
96
+ > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
97
+ >
98
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
99
+
100
+ ---------------------------------------
101
+
102
+ ## is-plain-obj
103
+ License: MIT
104
+ By: Sindre Sorhus
105
+ Repository: sindresorhus/is-plain-obj
106
+
107
+ > MIT License
108
+ >
109
+ > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
110
+ >
111
+ > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
112
+ >
113
+ > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
114
+ >
115
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
116
+
117
+ ---------------------------------------
118
+
119
+ ## type-fest
120
+ License: (MIT OR CC0-1.0)
121
+ By: Sindre Sorhus
122
+ Repository: sindresorhus/type-fest
123
+
124
+ <!-- TYPE_DEPENDENCIES -->
package/README.md ADDED
@@ -0,0 +1,140 @@
1
+ <div align="center">
2
+ <h3>visulima object</h3>
3
+ <p>
4
+ Helper functions for working with objects, build on top of
5
+
6
+ [is-plain-obj][is-plain-obj],
7
+ [dot-prop][dot-prop],
8
+ [deeks][deeks] and
9
+ [type-fest][type-fest]
10
+
11
+ </p>
12
+ </div>
13
+
14
+ <br />
15
+
16
+ <div align="center">
17
+
18
+ [![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]
19
+
20
+ </div>
21
+
22
+ ---
23
+
24
+ <div align="center">
25
+ <p>
26
+ <sup>
27
+ Daniel Bannert's open source work is supported by the community on <a href="https://github.com/sponsors/prisis">GitHub Sponsors</a>
28
+ </sup>
29
+ </p>
30
+ </div>
31
+
32
+ ---
33
+
34
+ ## Install
35
+
36
+ ```sh
37
+ npm install @visulima/object
38
+ ```
39
+
40
+ ```sh
41
+ yarn add @visulima/object
42
+ ```
43
+
44
+ ```sh
45
+ pnpm add @visulima/object
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ ### deleteProperty
51
+
52
+ ### escapePath
53
+
54
+ ### getProperty
55
+
56
+ ### hasProperty
57
+
58
+ ### setProperty
59
+
60
+ ### deepKeys
61
+
62
+ ### deepKeysFromList
63
+
64
+ ### isPlainObject
65
+
66
+ ### pick
67
+
68
+ With `pick` you pass an object and an array of keys of an object - **the props which may stay**.
69
+
70
+ ```js
71
+ import { pick } from "@visulima/object";
72
+
73
+ const squirtle = { id: "007", name: "Squirtle", type: "water" };
74
+
75
+ const newObject = pick(squirtle, ["name", "type"]);
76
+ // returns { name: 'Squirtle', type: 'water' }
77
+
78
+ const doc = { items: { keep: "πŸ“Œ", discard: "βœ‚οΈ" } };
79
+
80
+ pick(doc, ["items.keep"]);
81
+ // returns {items: {keep: 'πŸ“Œ'}}
82
+ ```
83
+
84
+ ### omit
85
+
86
+ With `omit` you pass an object and an array of keys of an object - the props which should be removed.
87
+
88
+ ```js
89
+ import { omit } from "@visulima/object";
90
+
91
+ const squirtle = { id: "007", name: "Squirtle", type: "water" };
92
+
93
+ const withoutId = omit(squirtle, ["id"]);
94
+ // returns { name: 'Squirtle', type: 'water' }
95
+
96
+ const doc = { items: { keep: "πŸ“Œ", discard: "βœ‚οΈ" } };
97
+
98
+ omit(doc, ["items.discard"]);
99
+ // returns {items: {keep: 'πŸ“Œ'}}
100
+ ```
101
+
102
+ ## Related
103
+
104
+ - [is-plain-object](https://github.com/jonschlinkert/is-plain-object) - Returns true if the given value is an object created by the Object constructor.
105
+ - [is-plain-obj][is-plain-obj] - Check if a value is a plain object.
106
+ - [dot-prop][dot-prop] - Get, set, or delete a property from a nested object using a dot path.
107
+ - [ts-dot-prop](https://github.com/justinlettau/ts-dot-prop) - TypeScript utility to transform nested objects using a dot notation path.
108
+ - [dset](https://www.npmjs.com/package/dset) - A tiny (194B) utility for safely writing deep Object values~!
109
+ - [filter-anything](https://github.com/mesqueeb/filter-anything) - A simple (TypeScript) integration of "pick" and "omit" to filter props of an object.
110
+
111
+ ## Supported Node.js Versions
112
+
113
+ Libraries in this ecosystem make the best effort to track [Node.js’ release schedule](https://github.com/nodejs/release#release-schedule).
114
+ Here’s [a post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).
115
+
116
+ ## Contributing
117
+
118
+ If you would like to help take a look at the [list of issues](https://github.com/visulima/visulima/issues) and check our [Contributing](.github/CONTRIBUTING.md) guidelines.
119
+
120
+ > **Note:** please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
121
+
122
+ ## Credits
123
+
124
+ - [Daniel Bannert](https://github.com/prisis)
125
+ - [All Contributors](https://github.com/visulima/visulima/graphs/contributors)
126
+
127
+ ## License
128
+
129
+ The visulima object is open-sourced software licensed under the [MIT][license-url]
130
+
131
+ [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
132
+ [typescript-url]: "typescript"
133
+ [license-image]: https://img.shields.io/npm/l/@visulima/object?color=blueviolet&style=for-the-badge
134
+ [license-url]: LICENSE.md "license"
135
+ [npm-image]: https://img.shields.io/npm/v/@visulima/object/latest.svg?style=for-the-badge&logo=npm
136
+ [npm-url]: https://www.npmjs.com/package/@visulima/object/v/latest "npm"
137
+ [is-plain-obj]: https://github.com/sindresorhus/is-plain-obj
138
+ [dot-prop]: https://github.com/sindresorhus/dot-prop
139
+ [deeks]: https://github.com/mrodrig/deeks
140
+ [type-fest]: https://github.com/sindresorhus/type-fest
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var M=Object.defineProperty;var u=(e,r)=>M(e,"name",{value:r,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function w(e){if(typeof e!="object"||e===null)return!1;const r=Object.getPrototypeOf(e);return(r===null||r===Object.prototype||Object.getPrototypeOf(r)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}u(w,"isPlainObject");var F=Object.defineProperty,L=u((e,r)=>F(e,"name",{value:r,configurable:!0}),"n$1");const S=L((e,r)=>{const t=r.split(".");return e.split(".").reduce((n,a,o)=>{const l=t[o]==="*"?"*":a;return n.push(l),n},[]).join(".")===r},"pathsAreEqual");var q=Object.defineProperty,R=u((e,r)=>q(e,"name",{value:r,configurable:!0}),"m$2");const k=R((e,r,t="")=>w(e)?Object.entries(e).reduce((n,[a,o])=>{let l=t;return l&&(l+="."),l+=a,r.some(g=>S(l,g))?n:w(o)?(n[a]=k(e[a],r,l),n):(n[a]=o,n)},{}):e,"recursiveOmit");var B=Object.defineProperty,D=u((e,r)=>B(e,"name",{value:r,configurable:!0}),"r");const K=D(e=>Array.isArray(e)&&e.length>0,"isFullArray"),W=D((e,r)=>K(r)?k(e,r):e,"omit"),C=W;var G=Object.defineProperty,z=u((e,r)=>G(e,"name",{value:r,configurable:!0}),"h");const T=z((e,r,t="")=>w(e)?Object.entries(e).reduce((n,[a,o])=>{let l=t;if(l&&(l+="."),l+=a,r.length>0){let g=!1;if(r.forEach(O=>{const _=l.split(".").length,x=O.split(".").length,m=O.split(".").slice(0,_).join("."),A=l.split(".").slice(0,x).join(".");S(A,m)&&(g=!0)}),!g)return n}return w(o)?(n[a]=T(e[a],r,l),n):(n[a]=o,n)},{}):e,"recursivePick");var H=Object.defineProperty,$=u((e,r)=>H(e,"name",{value:r,configurable:!0}),"t");const J=$(e=>Array.isArray(e)&&e.length>0,"isFullArray"),Q=$((e,r)=>J(r)?T(e,r):{},"pick"),U=Q;var p=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},E={},y={};Object.defineProperty(y,"__esModule",{value:!0});y.isDocumentToRecurOn=y.flatten=y.unique=void 0;function V(e){return[...new Set(e)]}u(V,"unique");y.unique=V;function X(e){return[].concat(...e)}u(X,"flatten");y.flatten=X;function Y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length}u(Y,"isDocumentToRecurOn");y.isDocumentToRecurOn=Y;var N={};Object.defineProperty(N,"__esModule",{value:!0});(function(e){var r=p&&p.__createBinding||(Object.create?function(s,i,f,d){d===void 0&&(d=f);var c=Object.getOwnPropertyDescriptor(i,f);(!c||("get"in c?!i.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:u(function(){return i[f]},"get")}),Object.defineProperty(s,d,c)}:function(s,i,f,d){d===void 0&&(d=f),s[d]=i[f]}),t=p&&p.__setModuleDefault||(Object.create?function(s,i){Object.defineProperty(s,"default",{enumerable:!0,value:i})}:function(s,i){s.default=i}),n=p&&p.__importStar||function(s){if(s&&s.__esModule)return s;var i={};if(s!=null)for(var f in s)f!=="default"&&Object.prototype.hasOwnProperty.call(s,f)&&r(i,s,f);return t(i,s),i},a=p&&p.__exportStar||function(s,i){for(var f in s)f!=="default"&&!Object.prototype.hasOwnProperty.call(i,f)&&r(i,s,f)};Object.defineProperty(e,"__esModule",{value:!0}),e.deepKeysFromList=e.deepKeys=void 0;const o=n(y);a(N,e);function l(s,i){const f=A(i);return typeof s=="object"&&s!==null?O("",s,f):[]}u(l,"deepKeys"),e.deepKeys=l;function g(s,i){const f=A(i);return s.map(d=>typeof d=="object"&&d!==null?l(d,f):[])}u(g,"deepKeysFromList"),e.deepKeysFromList=g;function O(s,i,f){const d=Object.keys(i).map(c=>{const b=m(s,x(c,f));return f.expandNestedObjects&&o.isDocumentToRecurOn(i[c])||f.arrayIndexesAsKeys&&Array.isArray(i[c])&&i[c].length?O(b,i[c],f):f.expandArrayObjects&&Array.isArray(i[c])?_(i[c],b,f):f.ignoreEmptyArrays&&Array.isArray(i[c])&&!i[c].length?[]:b});return o.flatten(d)}u(O,"generateDeepKeysList");function _(s,i,f){let d=g(s,f);return s.length?s.length&&o.flatten(d).length===0?[i]:(d=d.map(c=>Array.isArray(c)&&c.length===0?[i]:c.map(b=>m(i,x(b,f)))),o.unique(o.flatten(d))):f.ignoreEmptyArraysWhenExpanding?[]:[i]}u(_,"processArrayKeys");function x(s,i){return i.escapeNestedDots?s.replace(/\./g,"\\."):s}u(x,"escapeNestedDotsIfSpecified");function m(s,i){return s?s+"."+i:i}u(m,"buildKeyName");function A(s){return{arrayIndexesAsKeys:!1,expandNestedObjects:!0,expandArrayObjects:!1,ignoreEmptyArraysWhenExpanding:!1,escapeNestedDots:!1,ignoreEmptyArrays:!1,...s??{}}}u(A,"mergeOptions")})(E);const h=u(e=>{const r=typeof e;return e!==null&&(r==="object"||r==="function")},"isObject"),P=new Set(["__proto__","prototype","constructor"]),Z=new Set("0123456789");function v(e){const r=[];let t="",n="start",a=!1;for(const o of e)switch(o){case"\\":{if(n==="index")throw new Error("Invalid character in an index");if(n==="indexEnd")throw new Error("Invalid character after an index");a&&(t+=o),n="property",a=!a;break}case".":{if(n==="index")throw new Error("Invalid character in an index");if(n==="indexEnd"){n="property";break}if(a){a=!1,t+=o;break}if(P.has(t))return[];r.push(t),t="",n="property";break}case"[":{if(n==="index")throw new Error("Invalid character in an index");if(n==="indexEnd"){n="index";break}if(a){a=!1,t+=o;break}if(n==="property"){if(P.has(t))return[];r.push(t),t=""}n="index";break}case"]":{if(n==="index"){r.push(Number.parseInt(t,10)),t="",n="indexEnd";break}if(n==="indexEnd")throw new Error("Invalid character after an index")}default:{if(n==="index"&&!Z.has(o))throw new Error("Invalid character in an index");if(n==="indexEnd")throw new Error("Invalid character after an index");n==="start"&&(n="property"),a&&(a=!1,t+="\\"),t+=o}}switch(a&&(t+="\\"),n){case"property":{if(P.has(t))return[];r.push(t);break}case"index":throw new Error("Index was not closed");case"start":{r.push("");break}}return r}u(v,"getPathSegments");function I(e,r){if(typeof r!="number"&&Array.isArray(e)){const t=Number.parseInt(r,10);return Number.isInteger(t)&&e[t]===e[r]}return!1}u(I,"isStringIndex");function j(e,r){if(I(e,r))throw new Error("Cannot use string index")}u(j,"assertNotStringIndex");function ee(e,r,t){if(!h(e)||typeof r!="string")return t===void 0?e:t;const n=v(r);if(n.length===0)return t;for(let a=0;a<n.length;a++){const o=n[a];if(I(e,o)?e=a===n.length-1?void 0:null:e=e[o],e==null){if(a!==n.length-1)return t;break}}return e===void 0?t:e}u(ee,"getProperty");function re(e,r,t){if(!h(e)||typeof r!="string")return e;const n=e,a=v(r);for(let o=0;o<a.length;o++){const l=a[o];j(e,l),o===a.length-1?e[l]=t:h(e[l])||(e[l]=typeof a[o+1]=="number"?[]:{}),e=e[l]}return n}u(re,"setProperty");function ne(e,r){if(!h(e)||typeof r!="string")return!1;const t=v(r);for(let n=0;n<t.length;n++){const a=t[n];if(j(e,a),n===t.length-1)return delete e[a],!0;if(e=e[a],!h(e))return!1}}u(ne,"deleteProperty");function te(e,r){if(!h(e)||typeof r!="string")return!1;const t=v(r);if(t.length===0)return!1;for(const n of t){if(!h(e)||!(n in e)||I(e,n))return!1;e=e[n]}return!0}u(te,"hasProperty");function ie(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replaceAll(/[\\.[]/g,"\\$&")}u(ie,"escapePath");exports.deepKeys=E.deepKeys;exports.deepKeysFromList=E.deepKeysFromList;exports.deleteProperty=ne;exports.escapePath=ie;exports.getProperty=ee;exports.hasProperty=te;exports.isPlainObject=w;exports.omit=C;exports.pick=U;exports.setProperty=re;