@tolki/path 0.0.0 → 1.0.1

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/pluck.js CHANGED
@@ -1,62 +1,48 @@
1
- import { isNull as p, isArray as s, isMap as a, keyedEntries as x, isObject as f, isPlainObject as b, isFunction as l, isUndefined as h, phpArrayKey as O, isNumber as k, readMapKey as j, isPhpFalsy as A } from "@tolki/utils";
2
- const u = /* @__PURE__ */ Symbol("absent");
3
- function E(n) {
4
- return s(n) ? n : a(n) ? x(n).map(([, r]) => r) : Object.values(n);
5
- }
6
- function d(n, r) {
7
- if (r.length === 0)
8
- return n;
9
- const [i, ...e] = r;
10
- if (i === "*") {
11
- const c = y(n) ? n.all() : n;
12
- return !s(c) && !f(c) ? null : E(c).map(
13
- (P) => d(P, e)
14
- );
15
- }
16
- const o = t(n, i);
17
- return o === u || h(o) ? null : d(o, e);
18
- }
19
- function w(n, r) {
20
- if (r.length === 0)
21
- return !1;
22
- let i = n;
23
- for (const e of r)
24
- if (i = t(i, e), i === u)
25
- return !1;
26
- return !0;
27
- }
28
- function F(n, r) {
29
- const i = t(n, r);
30
- return i === u ? [!1, void 0] : [!0, i];
31
- }
32
- function G(n) {
33
- return p(n) ? [] : s(n) ? [...n] : String(n).split(".");
34
- }
35
- function t(n, r) {
36
- if (s(n)) {
37
- const i = O(r);
38
- return k(i) && Object.hasOwn(n, i) ? n[i] : u;
39
- }
40
- if (!f(n))
41
- return u;
42
- if (a(n)) {
43
- const i = j(n, r);
44
- return i.found ? i.value : u;
45
- }
46
- return K(n) ? (y(n) ? t(n.all(), r) !== u : !A(n.offsetExists(r))) ? n.offsetGet(r) : u : Object.hasOwn(n, r) ? n[r] : u;
47
- }
48
- function K(n) {
49
- return f(n) && !b(n) && l(n.offsetExists) && l(n.offsetGet);
50
- }
51
- function y(n) {
52
- return f(n) && !b(n) && l(n.all);
53
- }
54
- export {
55
- G as explodePluckPath,
56
- E as getPluckWildcardValues,
57
- w as hasPluckPath,
58
- K as isArrayAccess,
59
- y as isEnumerable,
60
- F as readPluckKey,
61
- d as resolvePluckPath
62
- };
1
+ import { isArray as e, isFunction as t, isMap as n, isNull as r, isNumber as i, isObject as a, isPhpFalsy as o, isPlainObject as s, isUndefined as c, keyedEntries as l, phpArrayKey as u, readMapKey as d } from "@tolki/utils";
2
+ // src/pluck.ts
3
+ var f = Symbol("absent");
4
+ function p(t) {
5
+ return e(t) ? t : n(t) ? l(t).map(([, e]) => e) : Object.values(t);
6
+ }
7
+ function m(t, n) {
8
+ if (n.length === 0) return t;
9
+ let [r, ...i] = n;
10
+ if (r === "*") {
11
+ let n = b(t) ? t.all() : t;
12
+ return !e(n) && !a(n) ? null : p(n).map((e) => m(e, i));
13
+ }
14
+ let o = v(t, r);
15
+ return o === f || c(o) ? null : m(o, i);
16
+ }
17
+ function h(e, t) {
18
+ if (t.length === 0) return !1;
19
+ let n = e;
20
+ for (let e of t) if (n = v(n, e), n === f) return !1;
21
+ return !0;
22
+ }
23
+ function g(e, t) {
24
+ let n = v(e, t);
25
+ return n === f ? [!1, void 0] : [!0, n];
26
+ }
27
+ function _(t) {
28
+ return r(t) ? [] : e(t) ? [...t] : String(t).split(".");
29
+ }
30
+ function v(t, r) {
31
+ if (e(t)) {
32
+ let e = u(r);
33
+ return i(e) && Object.hasOwn(t, e) ? t[e] : f;
34
+ }
35
+ if (!a(t)) return f;
36
+ if (n(t)) {
37
+ let e = d(t, r);
38
+ return e.found ? e.value : f;
39
+ }
40
+ return y(t) ? (b(t) ? v(t.all(), r) !== f : !o(t.offsetExists(r))) ? t.offsetGet(r) : f : Object.hasOwn(t, r) ? t[r] : f;
41
+ }
42
+ function y(e) {
43
+ return a(e) && !s(e) && t(e.offsetExists) && t(e.offsetGet);
44
+ }
45
+ function b(e) {
46
+ return a(e) && !s(e) && t(e.all);
47
+ }
48
+ export { _ as explodePluckPath, p as getPluckWildcardValues, h as hasPluckPath, y as isArrayAccess, b as isEnumerable, g as readPluckKey, m as resolvePluckPath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/path",
3
- "version": "0.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Utilities for working with path-based operations across arrays/objects.",
5
5
  "author": "Abraham Arango <https://github.com/abetwothree>",
6
6
  "license": "MIT",
@@ -14,10 +14,16 @@
14
14
  },
15
15
  "type": "module",
16
16
  "main": "dist/index.js",
17
- "keywords": [],
17
+ "keywords": [
18
+ "path",
19
+ "array",
20
+ "object",
21
+ "utilities",
22
+ "dot-notation"
23
+ ],
18
24
  "dependencies": {
19
- "@tolki/utils": "^1.5.0",
20
- "@tolki/types": "^1.8.0"
25
+ "@tolki/utils": "^1.6.3",
26
+ "@tolki/types": "^1.11.0"
21
27
  },
22
28
  "sideEffects": false,
23
29
  "files": [
@@ -34,12 +40,14 @@
34
40
  "types": "./dist/index.d.ts"
35
41
  },
36
42
  "./path": {
43
+ "types": "./dist/path.d.ts",
37
44
  "import": "./dist/path.js",
38
- "types": "./dist/path.d.ts"
45
+ "default": "./dist/path.js"
39
46
  },
40
47
  "./pluck": {
48
+ "types": "./dist/pluck.d.ts",
41
49
  "import": "./dist/pluck.js",
42
- "types": "./dist/pluck.d.ts"
50
+ "default": "./dist/pluck.js"
43
51
  }
44
52
  }
45
53
  }