@visulima/object 1.0.7 → 1.0.8

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/dist/index.mjs CHANGED
@@ -1 +1,176 @@
1
- var L=Object.defineProperty;var o=(c,y)=>L(c,"name",{value:y,configurable:!0});import{default as w}from"./packem_shared/omit-BcaD2qRn.mjs";import{default as B}from"./packem_shared/pick-BxgLK1bH.mjs";import{deleteProperty as W,escapePath as z,getProperty as C,hasProperty as G,setProperty as H}from"./packem_shared/getProperty-D2xQpEOY.mjs";import{default as Q}from"./packem_shared/isPlainObject-CLTs8VdF.mjs";var s={},p={},D;function N(){if(D)return p;D=1;var c=Object.defineProperty,y=o((i,b)=>c(i,"name",{value:b,configurable:!0}),"t");Object.defineProperty(p,"__esModule",{value:!0}),p.isDocumentToRecurOn=p.flatten=p.unique=void 0;function u(i){return[...new Set(i)]}o(u,"unique"),y(u,"unique"),p.unique=u;function f(i){return[].concat(...i)}o(f,"flatten"),y(f,"flatten"),p.flatten=f;function m(i){return typeof i=="object"&&i!==null&&!Array.isArray(i)&&Object.keys(i).length}return o(m,"isDocumentToRecurOn"),y(m,"isDocumentToRecurOn"),p.isDocumentToRecurOn=m,p}o(N,"requireUtils");var K={},P;function R(){return P||(P=1,Object.defineProperty(K,"__esModule",{value:!0})),K}o(R,"requireTypes");var q;function k(){return q||(q=1,function(c){var y=Object.defineProperty,u=o((t,e)=>y(t,"name",{value:e,configurable:!0}),"i"),f=s&&s.__createBinding||(Object.create?function(t,e,r,a){a===void 0&&(a=r);var n=Object.getOwnPropertyDescriptor(e,r);(!n||("get"in n?!e.__esModule:n.writable||n.configurable))&&(n={enumerable:!0,get:u(function(){return e[r]},"get")}),Object.defineProperty(t,a,n)}:function(t,e,r,a){a===void 0&&(a=r),t[a]=e[r]}),m=s&&s.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=s&&s.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&f(e,t,r);return m(e,t),e},b=s&&s.__exportStar||function(t,e){for(var r in t)r!=="default"&&!Object.prototype.hasOwnProperty.call(e,r)&&f(e,t,r)};Object.defineProperty(c,"__esModule",{value:!0}),c.deepKeysFromList=c.deepKeys=void 0;const l=i(N());b(R(),c);function O(t,e){const r=A(e);return typeof t=="object"&&t!==null?v("",t,r):[]}o(O,"deepKeys"),u(O,"deepKeys"),c.deepKeys=O;function g(t,e){const r=A(e);return t.map(a=>typeof a=="object"&&a!==null?O(a,r):[])}o(g,"deepKeysFromList"),u(g,"deepKeysFromList"),c.deepKeysFromList=g;function v(t,e,r){const a=Object.keys(e).map(n=>{const d=j(t,_(n,r));return r.expandNestedObjects&&l.isDocumentToRecurOn(e[n])||r.arrayIndexesAsKeys&&Array.isArray(e[n])&&e[n].length?v(d,e[n],r):r.expandArrayObjects&&Array.isArray(e[n])?h(e[n],d,r):r.ignoreEmptyArrays&&Array.isArray(e[n])&&!e[n].length?[]:d});return l.flatten(a)}o(v,"generateDeepKeysList"),u(v,"generateDeepKeysList");function h(t,e,r){let a=g(t,r);return t.length?t.length&&l.flatten(a).length===0?[e]:(a=a.map(n=>Array.isArray(n)&&n.length===0?[e]:n.map(d=>j(e,_(d,r)))),l.unique(l.flatten(a))):r.ignoreEmptyArraysWhenExpanding?[]:[e]}o(h,"processArrayKeys"),u(h,"processArrayKeys");function _(t,e){return e.escapeNestedDots?t.replace(/\./g,"\\."):t}o(_,"escapeNestedDotsIfSpecified"),u(_,"escapeNestedDotsIfSpecified");function j(t,e){return t?t+"."+e:e}o(j,"buildKeyName"),u(j,"buildKeyName");function A(t){return{arrayIndexesAsKeys:!1,expandNestedObjects:!0,expandArrayObjects:!1,ignoreEmptyArraysWhenExpanding:!1,escapeNestedDots:!1,ignoreEmptyArrays:!1,...t??{}}}o(A,"mergeOptions"),u(A,"mergeOptions")}(s)),s}o(k,"requireDeeks");var x=k();const M=x.deepKeys,S=x.deepKeysFromList;export{M as deepKeys,S as deepKeysFromList,W as deleteProperty,z as escapePath,C as getProperty,G as hasProperty,Q as isPlainObject,w as omit,B as pick,H as setProperty};
1
+ export { default as omit } from './packem_shared/omit-Bz46-jv-.mjs';
2
+ export { default as pick } from './packem_shared/pick-C9-E3eDJ.mjs';
3
+ export { deleteProperty, escapePath, getProperty, hasProperty, setProperty } from './packem_shared/getProperty-CqSBQFGO.mjs';
4
+ export { default as isPlainObject } from './packem_shared/isPlainObject-BEp1xndO.mjs';
5
+
6
+ var deeks = {};
7
+
8
+ var utils = {};
9
+
10
+ var hasRequiredUtils;
11
+
12
+ function requireUtils () {
13
+ if (hasRequiredUtils) return utils;
14
+ hasRequiredUtils = 1;
15
+ var __defProp = Object.defineProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ Object.defineProperty(utils, "__esModule", { value: true });
18
+ utils.isDocumentToRecurOn = utils.flatten = utils.unique = undefined;
19
+ function unique(array) {
20
+ return [...new Set(array)];
21
+ }
22
+ __name(unique, "unique");
23
+ utils.unique = unique;
24
+ function flatten(array) {
25
+ return [].concat(...array);
26
+ }
27
+ __name(flatten, "flatten");
28
+ utils.flatten = flatten;
29
+ function isDocumentToRecurOn(val) {
30
+ return typeof val === "object" && val !== null && !Array.isArray(val) && Object.keys(val).length;
31
+ }
32
+ __name(isDocumentToRecurOn, "isDocumentToRecurOn");
33
+ utils.isDocumentToRecurOn = isDocumentToRecurOn;
34
+ return utils;
35
+ }
36
+
37
+ var types = {};
38
+
39
+ var hasRequiredTypes;
40
+
41
+ function requireTypes () {
42
+ if (hasRequiredTypes) return types;
43
+ hasRequiredTypes = 1;
44
+ Object.defineProperty(types, "__esModule", { value: true });
45
+ return types;
46
+ }
47
+
48
+ var hasRequiredDeeks;
49
+
50
+ function requireDeeks () {
51
+ if (hasRequiredDeeks) return deeks;
52
+ hasRequiredDeeks = 1;
53
+ (function (exports) {
54
+ var __defProp = Object.defineProperty;
55
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
56
+ var __createBinding = deeks.__createBinding || (Object.create ? function(o, m, k, k2) {
57
+ if (k2 === undefined) k2 = k;
58
+ var desc = Object.getOwnPropertyDescriptor(m, k);
59
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
60
+ desc = { enumerable: true, get: /* @__PURE__ */ __name(function() {
61
+ return m[k];
62
+ }, "get") };
63
+ }
64
+ Object.defineProperty(o, k2, desc);
65
+ } : function(o, m, k, k2) {
66
+ if (k2 === undefined) k2 = k;
67
+ o[k2] = m[k];
68
+ });
69
+ var __setModuleDefault = deeks.__setModuleDefault || (Object.create ? function(o, v) {
70
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
71
+ } : function(o, v) {
72
+ o["default"] = v;
73
+ });
74
+ var __importStar = deeks.__importStar || function(mod) {
75
+ if (mod && mod.__esModule) return mod;
76
+ var result = {};
77
+ if (mod != null) {
78
+ for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
79
+ }
80
+ __setModuleDefault(result, mod);
81
+ return result;
82
+ };
83
+ var __exportStar = deeks.__exportStar || function(m, exports2) {
84
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
85
+ };
86
+ Object.defineProperty(exports, "__esModule", { value: true });
87
+ exports.deepKeysFromList = exports.deepKeys = undefined;
88
+ const utils = __importStar(requireUtils());
89
+ __exportStar(requireTypes(), exports);
90
+ function deepKeys(object, options) {
91
+ const parsedOptions = mergeOptions(options);
92
+ if (typeof object === "object" && object !== null) {
93
+ return generateDeepKeysList("", object, parsedOptions);
94
+ }
95
+ return [];
96
+ }
97
+ __name(deepKeys, "deepKeys");
98
+ exports.deepKeys = deepKeys;
99
+ function deepKeysFromList(list, options) {
100
+ const parsedOptions = mergeOptions(options);
101
+ return list.map((document) => {
102
+ if (typeof document === "object" && document !== null) {
103
+ return deepKeys(document, parsedOptions);
104
+ }
105
+ return [];
106
+ });
107
+ }
108
+ __name(deepKeysFromList, "deepKeysFromList");
109
+ exports.deepKeysFromList = deepKeysFromList;
110
+ function generateDeepKeysList(heading, data, options) {
111
+ const keys = Object.keys(data).map((currentKey) => {
112
+ const keyName = buildKeyName(heading, escapeNestedDotsIfSpecified(currentKey, options));
113
+ if (options.expandNestedObjects && utils.isDocumentToRecurOn(data[currentKey]) || options.arrayIndexesAsKeys && Array.isArray(data[currentKey]) && data[currentKey].length) {
114
+ return generateDeepKeysList(keyName, data[currentKey], options);
115
+ } else if (options.expandArrayObjects && Array.isArray(data[currentKey])) {
116
+ return processArrayKeys(data[currentKey], keyName, options);
117
+ } else if (options.ignoreEmptyArrays && Array.isArray(data[currentKey]) && !data[currentKey].length) {
118
+ return [];
119
+ }
120
+ return keyName;
121
+ });
122
+ return utils.flatten(keys);
123
+ }
124
+ __name(generateDeepKeysList, "generateDeepKeysList");
125
+ function processArrayKeys(subArray, currentKeyPath, options) {
126
+ let subArrayKeys = deepKeysFromList(subArray, options);
127
+ if (!subArray.length) {
128
+ return options.ignoreEmptyArraysWhenExpanding ? [] : [currentKeyPath];
129
+ } else if (subArray.length && utils.flatten(subArrayKeys).length === 0) {
130
+ return [currentKeyPath];
131
+ } else {
132
+ subArrayKeys = subArrayKeys.map((schemaKeys) => {
133
+ if (Array.isArray(schemaKeys) && schemaKeys.length === 0) {
134
+ return [currentKeyPath];
135
+ }
136
+ return schemaKeys.map((subKey) => buildKeyName(currentKeyPath, escapeNestedDotsIfSpecified(subKey, options)));
137
+ });
138
+ return utils.unique(utils.flatten(subArrayKeys));
139
+ }
140
+ }
141
+ __name(processArrayKeys, "processArrayKeys");
142
+ function escapeNestedDotsIfSpecified(key, options) {
143
+ if (options.escapeNestedDots) {
144
+ return key.replace(/\./g, "\\.");
145
+ }
146
+ return key;
147
+ }
148
+ __name(escapeNestedDotsIfSpecified, "escapeNestedDotsIfSpecified");
149
+ function buildKeyName(upperKeyName, currentKeyName) {
150
+ if (upperKeyName) {
151
+ return upperKeyName + "." + currentKeyName;
152
+ }
153
+ return currentKeyName;
154
+ }
155
+ __name(buildKeyName, "buildKeyName");
156
+ function mergeOptions(options) {
157
+ return {
158
+ arrayIndexesAsKeys: false,
159
+ expandNestedObjects: true,
160
+ expandArrayObjects: false,
161
+ ignoreEmptyArraysWhenExpanding: false,
162
+ escapeNestedDots: false,
163
+ ignoreEmptyArrays: false,
164
+ ...options ?? {}
165
+ };
166
+ }
167
+ __name(mergeOptions, "mergeOptions");
168
+ } (deeks));
169
+ return deeks;
170
+ }
171
+
172
+ var deeksExports = requireDeeks();
173
+
174
+ const deepKeys = deeksExports.deepKeys;
175
+ const deepKeysFromList = deeksExports.deepKeysFromList;
176
+ export { deepKeys, deepKeysFromList };
@@ -0,0 +1,278 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ const isObject = /* @__PURE__ */ __name((value) => {
8
+ const type = typeof value;
9
+ return value !== null && (type === "object" || type === "function");
10
+ }, "isObject");
11
+ const isEmptyObject = /* @__PURE__ */ __name((value) => isObject(value) && Object.keys(value).length === 0, "isEmptyObject");
12
+ const disallowedKeys = /* @__PURE__ */ new Set([
13
+ "__proto__",
14
+ "prototype",
15
+ "constructor"
16
+ ]);
17
+ const digits = new Set("0123456789");
18
+ function getPathSegments(path) {
19
+ const parts = [];
20
+ let currentSegment = "";
21
+ let currentPart = "start";
22
+ let isIgnoring = false;
23
+ for (const character of path) {
24
+ switch (character) {
25
+ case "\\": {
26
+ if (currentPart === "index") {
27
+ throw new Error("Invalid character in an index");
28
+ }
29
+ if (currentPart === "indexEnd") {
30
+ throw new Error("Invalid character after an index");
31
+ }
32
+ if (isIgnoring) {
33
+ currentSegment += character;
34
+ }
35
+ currentPart = "property";
36
+ isIgnoring = !isIgnoring;
37
+ break;
38
+ }
39
+ case ".": {
40
+ if (currentPart === "index") {
41
+ throw new Error("Invalid character in an index");
42
+ }
43
+ if (currentPart === "indexEnd") {
44
+ currentPart = "property";
45
+ break;
46
+ }
47
+ if (isIgnoring) {
48
+ isIgnoring = false;
49
+ currentSegment += character;
50
+ break;
51
+ }
52
+ if (disallowedKeys.has(currentSegment)) {
53
+ return [];
54
+ }
55
+ parts.push(currentSegment);
56
+ currentSegment = "";
57
+ currentPart = "property";
58
+ break;
59
+ }
60
+ case "[": {
61
+ if (currentPart === "index") {
62
+ throw new Error("Invalid character in an index");
63
+ }
64
+ if (currentPart === "indexEnd") {
65
+ currentPart = "index";
66
+ break;
67
+ }
68
+ if (isIgnoring) {
69
+ isIgnoring = false;
70
+ currentSegment += character;
71
+ break;
72
+ }
73
+ if (currentPart === "property") {
74
+ if (disallowedKeys.has(currentSegment)) {
75
+ return [];
76
+ }
77
+ parts.push(currentSegment);
78
+ currentSegment = "";
79
+ }
80
+ currentPart = "index";
81
+ break;
82
+ }
83
+ case "]": {
84
+ if (currentPart === "index") {
85
+ parts.push(Number.parseInt(currentSegment, 10));
86
+ currentSegment = "";
87
+ currentPart = "indexEnd";
88
+ break;
89
+ }
90
+ if (currentPart === "indexEnd") {
91
+ throw new Error("Invalid character after an index");
92
+ }
93
+ }
94
+ default: {
95
+ if (currentPart === "index" && !digits.has(character)) {
96
+ throw new Error("Invalid character in an index");
97
+ }
98
+ if (currentPart === "indexEnd") {
99
+ throw new Error("Invalid character after an index");
100
+ }
101
+ if (currentPart === "start") {
102
+ currentPart = "property";
103
+ }
104
+ if (isIgnoring) {
105
+ isIgnoring = false;
106
+ currentSegment += "\\";
107
+ }
108
+ currentSegment += character;
109
+ }
110
+ }
111
+ }
112
+ if (isIgnoring) {
113
+ currentSegment += "\\";
114
+ }
115
+ switch (currentPart) {
116
+ case "property": {
117
+ if (disallowedKeys.has(currentSegment)) {
118
+ return [];
119
+ }
120
+ parts.push(currentSegment);
121
+ break;
122
+ }
123
+ case "index": {
124
+ throw new Error("Index was not closed");
125
+ }
126
+ case "start": {
127
+ parts.push("");
128
+ break;
129
+ }
130
+ }
131
+ return parts;
132
+ }
133
+ __name(getPathSegments, "getPathSegments");
134
+ function isStringIndex(object, key) {
135
+ if (typeof key !== "number" && Array.isArray(object)) {
136
+ const index = Number.parseInt(key, 10);
137
+ return Number.isInteger(index) && object[index] === object[key];
138
+ }
139
+ return false;
140
+ }
141
+ __name(isStringIndex, "isStringIndex");
142
+ function assertNotStringIndex(object, key) {
143
+ if (isStringIndex(object, key)) {
144
+ throw new Error("Cannot use string index");
145
+ }
146
+ }
147
+ __name(assertNotStringIndex, "assertNotStringIndex");
148
+ function getProperty(object, path, value) {
149
+ if (!isObject(object) || typeof path !== "string") {
150
+ return value === undefined ? object : value;
151
+ }
152
+ const pathArray = getPathSegments(path);
153
+ if (pathArray.length === 0) {
154
+ return value;
155
+ }
156
+ for (let index = 0; index < pathArray.length; index++) {
157
+ const key = pathArray[index];
158
+ if (isStringIndex(object, key)) {
159
+ object = index === pathArray.length - 1 ? undefined : null;
160
+ } else {
161
+ object = object[key];
162
+ }
163
+ if (object === undefined || object === null) {
164
+ if (index !== pathArray.length - 1) {
165
+ return value;
166
+ }
167
+ break;
168
+ }
169
+ }
170
+ return object === undefined ? value : object;
171
+ }
172
+ __name(getProperty, "getProperty");
173
+ function setProperty(object, path, value) {
174
+ if (!isObject(object) || typeof path !== "string") {
175
+ return object;
176
+ }
177
+ const root = object;
178
+ const pathArray = getPathSegments(path);
179
+ for (let index = 0; index < pathArray.length; index++) {
180
+ const key = pathArray[index];
181
+ assertNotStringIndex(object, key);
182
+ if (index === pathArray.length - 1) {
183
+ object[key] = value;
184
+ } else if (!isObject(object[key])) {
185
+ object[key] = typeof pathArray[index + 1] === "number" ? [] : {};
186
+ }
187
+ object = object[key];
188
+ }
189
+ return root;
190
+ }
191
+ __name(setProperty, "setProperty");
192
+ function deleteProperty(object, path) {
193
+ if (!isObject(object) || typeof path !== "string") {
194
+ return false;
195
+ }
196
+ const pathArray = getPathSegments(path);
197
+ for (let index = 0; index < pathArray.length; index++) {
198
+ const key = pathArray[index];
199
+ assertNotStringIndex(object, key);
200
+ if (index === pathArray.length - 1) {
201
+ delete object[key];
202
+ return true;
203
+ }
204
+ object = object[key];
205
+ if (!isObject(object)) {
206
+ return false;
207
+ }
208
+ }
209
+ }
210
+ __name(deleteProperty, "deleteProperty");
211
+ function hasProperty(object, path) {
212
+ if (!isObject(object) || typeof path !== "string") {
213
+ return false;
214
+ }
215
+ const pathArray = getPathSegments(path);
216
+ if (pathArray.length === 0) {
217
+ return false;
218
+ }
219
+ for (const key of pathArray) {
220
+ if (!isObject(object) || !(key in object) || isStringIndex(object, key)) {
221
+ return false;
222
+ }
223
+ object = object[key];
224
+ }
225
+ return true;
226
+ }
227
+ __name(hasProperty, "hasProperty");
228
+ function escapePath(path) {
229
+ if (typeof path !== "string") {
230
+ throw new TypeError("Expected a string");
231
+ }
232
+ return path.replaceAll(/[\\.[]/g, "\\$&");
233
+ }
234
+ __name(escapePath, "escapePath");
235
+ function entries(value) {
236
+ const result = Object.entries(value);
237
+ if (Array.isArray(value)) {
238
+ return result.map(([key, value2]) => [Number(key), value2]);
239
+ }
240
+ return result;
241
+ }
242
+ __name(entries, "entries");
243
+ function stringifyPath(pathSegments) {
244
+ let result = "";
245
+ for (let [index, segment] of entries(pathSegments)) {
246
+ if (typeof segment === "number") {
247
+ result += `[${segment}]`;
248
+ } else {
249
+ segment = escapePath(segment);
250
+ result += index === 0 ? segment : `.${segment}`;
251
+ }
252
+ }
253
+ return result;
254
+ }
255
+ __name(stringifyPath, "stringifyPath");
256
+ function* deepKeysIterator(object, currentPath = []) {
257
+ if (!isObject(object) || isEmptyObject(object)) {
258
+ if (currentPath.length > 0) {
259
+ yield stringifyPath(currentPath);
260
+ }
261
+ return;
262
+ }
263
+ for (const [key, value] of entries(object)) {
264
+ yield* deepKeysIterator(value, [...currentPath, key]);
265
+ }
266
+ }
267
+ __name(deepKeysIterator, "deepKeysIterator");
268
+ function deepKeys(object) {
269
+ return [...deepKeysIterator(object)];
270
+ }
271
+ __name(deepKeys, "deepKeys");
272
+
273
+ exports.deepKeys = deepKeys;
274
+ exports.deleteProperty = deleteProperty;
275
+ exports.escapePath = escapePath;
276
+ exports.getProperty = getProperty;
277
+ exports.hasProperty = hasProperty;
278
+ exports.setProperty = setProperty;