@hamak/shared-utils 0.4.1 → 0.4.4

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.
@@ -81,4 +81,31 @@ export declare class Pathway {
81
81
  static asString(path: Path): string;
82
82
  static getName(path: string | string[] | Pathway): string;
83
83
  }
84
+ /**
85
+ * Converts a path (string or string array) to an array of path segments.
86
+ * If already an array, returns it as-is.
87
+ * If a string, splits by '/' and filters out empty segments.
88
+ *
89
+ * @param path - The path to convert to segments
90
+ * @returns Array of path segments
91
+ *
92
+ * @example
93
+ * pathSteps('/foo/bar/baz') // ['foo', 'bar', 'baz']
94
+ * pathSteps(['foo', 'bar']) // ['foo', 'bar']
95
+ * pathSteps('foo//bar/') // ['foo', 'bar']
96
+ */
97
+ export declare function pathSteps(path: string | string[]): string[];
98
+ /**
99
+ * Returns the parent path segments by removing the last segment.
100
+ * Uses pathSteps internally to normalize the input path.
101
+ *
102
+ * @param path - The path to get parent segments from
103
+ * @returns Array of parent path segments (all but last segment)
104
+ *
105
+ * @example
106
+ * parentPathSteps('/foo/bar/baz') // ['foo', 'bar']
107
+ * parentPathSteps(['foo', 'bar']) // ['foo']
108
+ * parentPathSteps(['foo']) // []
109
+ */
110
+ export declare function parentPathSteps(path: string | string[]): string[];
84
111
  //# sourceMappingURL=core-utils-pathway.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"core-utils-pathway.d.ts","sourceRoot":"","sources":["../src/core-utils-pathway.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAA;AAC9C;;GAEG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,cAAc,CAAU;IAEhC;;;;OAIG;gBACS,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS;IAUtD;;;;OAIG;WACW,EAAE,CAAC,IAAI,EAAE,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207
+ /**
208
+ * Converts a path (string or string array) to an array of path segments.
209
+ * If already an array, returns it as-is.
210
+ * If a string, splits by '/' and filters out empty segments.
211
+ *
212
+ * @param path - The path to convert to segments
213
+ * @returns Array of path segments
214
+ *
215
+ * @example
216
+ * pathSteps('/foo/bar/baz') // ['foo', 'bar', 'baz']
217
+ * pathSteps(['foo', 'bar']) // ['foo', 'bar']
218
+ * pathSteps('foo//bar/') // ['foo', 'bar']
219
+ */
220
+ export function pathSteps(path) {
221
+ if (Array.isArray(path)) {
222
+ return path;
223
+ }
224
+ return path.split('/').filter(s => s.trim().length > 0);
225
+ }
226
+ /**
227
+ * Returns the parent path segments by removing the last segment.
228
+ * Uses pathSteps internally to normalize the input path.
229
+ *
230
+ * @param path - The path to get parent segments from
231
+ * @returns Array of parent path segments (all but last segment)
232
+ *
233
+ * @example
234
+ * parentPathSteps('/foo/bar/baz') // ['foo', 'bar']
235
+ * parentPathSteps(['foo', 'bar']) // ['foo']
236
+ * parentPathSteps(['foo']) // []
237
+ */
238
+ export function parentPathSteps(path) {
239
+ const steps = pathSteps(path);
240
+ return steps.length > 0 ? steps.slice(0, steps.length - 1) : steps;
241
+ }
@@ -1,4 +1,7 @@
1
- export class Chronometre {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chronometre = exports.Chronometre = void 0;
4
+ class Chronometre {
2
5
  constructor() {
3
6
  this.start = Date.now();
4
7
  }
@@ -11,6 +14,8 @@ export class Chronometre {
11
14
  return d;
12
15
  }
13
16
  }
14
- export function chronometre() {
17
+ exports.Chronometre = Chronometre;
18
+ function chronometre() {
15
19
  return new Chronometre();
16
20
  }
21
+ exports.chronometre = chronometre;
@@ -1,7 +1,11 @@
1
- export function reverseOrder(compareFn) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compareDesc = exports.compare = exports.reverseOrder = void 0;
4
+ function reverseOrder(compareFn) {
2
5
  return (a, b, fns) => -compareFn(a, b, fns);
3
6
  }
4
- export function compare(a, b, ...fns) {
7
+ exports.reverseOrder = reverseOrder;
8
+ function compare(a, b, ...fns) {
5
9
  if (fns.length === 0) {
6
10
  if (typeof a === "number" && typeof b === "number") {
7
11
  fns = [(x) => x];
@@ -19,4 +23,5 @@ export function compare(a, b, ...fns) {
19
23
  }
20
24
  return 0;
21
25
  }
22
- export const compareDesc = reverseOrder(compare);
26
+ exports.compare = compare;
27
+ exports.compareDesc = reverseOrder(compare);
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,8 @@
1
- import { Pathway } from './core-utils-pathway';
2
- export function fileSystemNodeInitialState(contentPresent = true) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fsutils = exports.DirectoryNodePathwayResolver = exports.fileSystemNodeInitialState = void 0;
4
+ const core_utils_pathway_1 = require("./core-utils-pathway");
5
+ function fileSystemNodeInitialState(contentPresent = true) {
3
6
  return {
4
7
  contentLoaded: contentPresent,
5
8
  contentLoading: false,
@@ -8,6 +11,7 @@ export function fileSystemNodeInitialState(contentPresent = true) {
8
11
  extensionStates: {}
9
12
  };
10
13
  }
14
+ exports.fileSystemNodeInitialState = fileSystemNodeInitialState;
11
15
  function isRoot(node) {
12
16
  switch (node.type) {
13
17
  case "directory": {
@@ -18,26 +22,27 @@ function isRoot(node) {
18
22
  }
19
23
  }
20
24
  }
21
- export class DirectoryNodePathwayResolver {
25
+ class DirectoryNodePathwayResolver {
22
26
  constructor(root) {
23
27
  this.root = root;
24
28
  }
25
29
  resolve(path) {
26
- return fsutils.resolveFileNode(this.root, path);
30
+ return exports.fsutils.resolveFileNode(this.root, path);
27
31
  }
28
32
  changeDIr(path) {
29
33
  const fileNode = this.resolve(path);
30
34
  if (fileNode === undefined) {
31
- throw new Error(`No such directory: ${Pathway.asString(path)}`);
35
+ throw new Error(`No such directory: ${core_utils_pathway_1.Pathway.asString(path)}`);
32
36
  }
33
37
  else {
34
38
  switch (fileNode.type) {
35
39
  case "directory": return new DirectoryNodePathwayResolver(fileNode);
36
- case "file": throw new Error(`Path is not directory: ${Pathway.asString(path)}`);
40
+ case "file": throw new Error(`Path is not directory: ${core_utils_pathway_1.Pathway.asString(path)}`);
37
41
  }
38
42
  }
39
43
  }
40
44
  }
45
+ exports.DirectoryNodePathwayResolver = DirectoryNodePathwayResolver;
41
46
  class FilesystemUtil {
42
47
  createRootDir(children, state = fileSystemNodeInitialState()) {
43
48
  return this.createDir("", children, state);
@@ -49,7 +54,7 @@ class FilesystemUtil {
49
54
  };
50
55
  }
51
56
  createDirs(path, children, state = fileSystemNodeInitialState()) {
52
- const pathway = Pathway.of(path);
57
+ const pathway = core_utils_pathway_1.Pathway.of(path);
53
58
  const dir = pathway.getSegments().reverse().reduce((acc, segment) => {
54
59
  return this.createDir(segment, acc === undefined ? children : [acc]);
55
60
  }, undefined);
@@ -65,7 +70,7 @@ class FilesystemUtil {
65
70
  if (fromDir === undefined) {
66
71
  return undefined;
67
72
  }
68
- const pathway = Pathway.of(path);
73
+ const pathway = core_utils_pathway_1.Pathway.of(path);
69
74
  if (pathway.isAbsolute() && !isRoot(fromDir)) {
70
75
  return undefined;
71
76
  }
@@ -101,7 +106,7 @@ class FilesystemUtil {
101
106
  return (fsn === null || fsn === void 0 ? void 0 : fsn.type) === "directory" ? fsn : undefined;
102
107
  }
103
108
  resolveDescendent(fromDir, path) {
104
- const pathway = Pathway.of(path);
109
+ const pathway = core_utils_pathway_1.Pathway.of(path);
105
110
  return pathway.isCurrentDir() ? undefined : this.resolveFileNode(fromDir, pathway);
106
111
  }
107
112
  /**
@@ -115,7 +120,7 @@ class FilesystemUtil {
115
120
  createDescendent(fromDir, path, content, schema = "xs:any", state = fileSystemNodeInitialState(), override = false) {
116
121
  if (!fromDir)
117
122
  return undefined;
118
- const pathway = Pathway.of(path);
123
+ const pathway = core_utils_pathway_1.Pathway.of(path);
119
124
  if (pathway.isCurrentDir())
120
125
  return undefined;
121
126
  const segments = pathway.getSegments();
@@ -154,4 +159,4 @@ class FilesystemUtil {
154
159
  return fileNode;
155
160
  }
156
161
  }
157
- export const fsutils = new FilesystemUtil();
162
+ exports.fsutils = new FilesystemUtil();
@@ -1,7 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LexicalQualifiedName = void 0;
1
4
  /**
2
5
  * Unresolved qualified name by either namespace of prefix
3
6
  */
4
- export class LexicalQualifiedName {
7
+ class LexicalQualifiedName {
5
8
  constructor(namespace, prefix, name) {
6
9
  this.namespace = namespace;
7
10
  this.prefix = prefix;
@@ -17,3 +20,4 @@ export class LexicalQualifiedName {
17
20
  }
18
21
  }
19
22
  }
23
+ exports.LexicalQualifiedName = LexicalQualifiedName;
@@ -1,26 +1,31 @@
1
- import { Pathway } from "./core-utils-pathway";
2
- export class RecordPathwayResolver {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RelativePathwayResolver = exports.EmptyPathwayResolver = exports.RecordPathwayResolver = void 0;
4
+ const core_utils_pathway_1 = require("./core-utils-pathway");
5
+ class RecordPathwayResolver {
3
6
  constructor(record) {
4
7
  this.record = record;
5
8
  }
6
9
  resolve(path) {
7
- const key = Pathway.asString(path);
10
+ const key = core_utils_pathway_1.Pathway.asString(path);
8
11
  return this.record[key];
9
12
  }
10
13
  }
11
- export class EmptyPathwayResolver {
14
+ exports.RecordPathwayResolver = RecordPathwayResolver;
15
+ class EmptyPathwayResolver {
12
16
  resolve(path) {
13
17
  return undefined;
14
18
  }
15
19
  }
16
- export class RelativePathwayResolver {
20
+ exports.EmptyPathwayResolver = EmptyPathwayResolver;
21
+ class RelativePathwayResolver {
17
22
  constructor(parentResolver, path) {
18
23
  this.parentResolver = parentResolver;
19
24
  this.path = path;
20
- this.relativePathway = Pathway.of(path);
25
+ this.relativePathway = core_utils_pathway_1.Pathway.of(path);
21
26
  }
22
27
  resolve(path) {
23
- const pathway = Pathway.of(path);
28
+ const pathway = core_utils_pathway_1.Pathway.of(path);
24
29
  if (pathway.isAbsolute()) {
25
30
  return this.parentResolver.resolve(path);
26
31
  }
@@ -29,3 +34,4 @@ export class RelativePathwayResolver {
29
34
  }
30
35
  }
31
36
  }
37
+ exports.RelativePathwayResolver = RelativePathwayResolver;
@@ -1,7 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parentPathSteps = exports.pathSteps = exports.Pathway = void 0;
1
4
  /**
2
5
  * Class representing a normalized pathway.
3
6
  */
4
- export class Pathway {
7
+ class Pathway {
5
8
  /**
6
9
  * Creates a Pathway instance.
7
10
  * @param path - The pathway to normalize, either as a string or an array of strings.
@@ -204,3 +207,41 @@ export class Pathway {
204
207
  return name;
205
208
  }
206
209
  }
210
+ exports.Pathway = Pathway;
211
+ /**
212
+ * Converts a path (string or string array) to an array of path segments.
213
+ * If already an array, returns it as-is.
214
+ * If a string, splits by '/' and filters out empty segments.
215
+ *
216
+ * @param path - The path to convert to segments
217
+ * @returns Array of path segments
218
+ *
219
+ * @example
220
+ * pathSteps('/foo/bar/baz') // ['foo', 'bar', 'baz']
221
+ * pathSteps(['foo', 'bar']) // ['foo', 'bar']
222
+ * pathSteps('foo//bar/') // ['foo', 'bar']
223
+ */
224
+ function pathSteps(path) {
225
+ if (Array.isArray(path)) {
226
+ return path;
227
+ }
228
+ return path.split('/').filter(s => s.trim().length > 0);
229
+ }
230
+ exports.pathSteps = pathSteps;
231
+ /**
232
+ * Returns the parent path segments by removing the last segment.
233
+ * Uses pathSteps internally to normalize the input path.
234
+ *
235
+ * @param path - The path to get parent segments from
236
+ * @returns Array of parent path segments (all but last segment)
237
+ *
238
+ * @example
239
+ * parentPathSteps('/foo/bar/baz') // ['foo', 'bar']
240
+ * parentPathSteps(['foo', 'bar']) // ['foo']
241
+ * parentPathSteps(['foo']) // []
242
+ */
243
+ function parentPathSteps(path) {
244
+ const steps = pathSteps(path);
245
+ return steps.length > 0 ? steps.slice(0, steps.length - 1) : steps;
246
+ }
247
+ exports.parentPathSteps = parentPathSteps;
@@ -1,4 +1,7 @@
1
- export class SimpleRegistry {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SimpleRegistry = void 0;
4
+ class SimpleRegistry {
2
5
  constructor() {
3
6
  this.records = new Map();
4
7
  }
@@ -20,3 +23,4 @@ export class SimpleRegistry {
20
23
  namespaceRecord[variableName] = t;
21
24
  }
22
25
  }
26
+ exports.SimpleRegistry = SimpleRegistry;
@@ -1,4 +1,7 @@
1
- export class RecordResolver {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChainedResolver = exports.SimpleResolver = exports.QualifiedNameResolverImpl = exports.RecordResolver = void 0;
4
+ class RecordResolver {
2
5
  constructor(variables, parent) {
3
6
  this.variables = variables;
4
7
  this.parent = parent;
@@ -8,7 +11,8 @@ export class RecordResolver {
8
11
  return (_a = this.variables[variableName]) !== null && _a !== void 0 ? _a : (_b = this.parent) === null || _b === void 0 ? void 0 : _b.resolve(undefined, undefined, variableName);
9
12
  }
10
13
  }
11
- export class QualifiedNameResolverImpl {
14
+ exports.RecordResolver = RecordResolver;
15
+ class QualifiedNameResolverImpl {
12
16
  constructor(ignoreNs = false) {
13
17
  this.ignoreNs = ignoreNs;
14
18
  this.entries = new Map();
@@ -37,7 +41,8 @@ export class QualifiedNameResolverImpl {
37
41
  return prefixEntry;
38
42
  }
39
43
  }
40
- export class SimpleResolver {
44
+ exports.QualifiedNameResolverImpl = QualifiedNameResolverImpl;
45
+ class SimpleResolver {
41
46
  constructor(parent, namespace, variableName, variableValue) {
42
47
  this.parent = parent;
43
48
  this.namespace = namespace;
@@ -52,7 +57,8 @@ export class SimpleResolver {
52
57
  return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.resolve(namespace, prefix, variableName);
53
58
  }
54
59
  }
55
- export class ChainedResolver {
60
+ exports.SimpleResolver = SimpleResolver;
61
+ class ChainedResolver {
56
62
  constructor(resolvers) {
57
63
  this.resolvers = resolvers;
58
64
  }
@@ -66,3 +72,4 @@ export class ChainedResolver {
66
72
  return undefined;
67
73
  }
68
74
  }
75
+ exports.ChainedResolver = ChainedResolver;
@@ -1,10 +1,15 @@
1
- export function head(value) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reduce = exports.fromArray = exports.concat = exports.push = exports.head = void 0;
4
+ function head(value) {
2
5
  return { value };
3
6
  }
4
- export function push(head, value) {
7
+ exports.head = head;
8
+ function push(head, value) {
5
9
  return { value, parent: head };
6
10
  }
7
- export function concat(tail, stack) {
11
+ exports.push = push;
12
+ function concat(tail, stack) {
8
13
  if (tail === undefined)
9
14
  return stack;
10
15
  if (stack === undefined)
@@ -12,10 +17,12 @@ export function concat(tail, stack) {
12
17
  const { parent, value } = stack;
13
18
  return { value, parent: concat(tail, parent) };
14
19
  }
15
- export function fromArray(t) {
20
+ exports.concat = concat;
21
+ function fromArray(t) {
16
22
  return t === null || t === void 0 ? void 0 : t.reduce((acc, t) => push(acc, t), undefined);
17
23
  }
18
- export function reduce(head, reducer, initial) {
24
+ exports.fromArray = fromArray;
25
+ function reduce(head, reducer, initial) {
19
26
  if (head === undefined) {
20
27
  return initial;
21
28
  }
@@ -23,6 +30,7 @@ export function reduce(head, reducer, initial) {
23
30
  const acc = reduce(parent, reducer, initial);
24
31
  return reducer(acc, value);
25
32
  }
33
+ exports.reduce = reduce;
26
34
  function equal(a, b) {
27
35
  // Not equal if both are nullish
28
36
  if (a === undefined || a === null || b === undefined || b === null) {
@@ -44,4 +52,4 @@ function equal(a, b) {
44
52
  }
45
53
  }
46
54
  const stack = { push, head, concat, reduce, fromArray, equal };
47
- export default stack;
55
+ exports.default = stack;
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,14 +1,19 @@
1
- export function holder(value) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExplorationContext = exports.hyperReflect = exports.hyper = exports.holder = void 0;
4
+ function holder(value) {
2
5
  return { value };
3
6
  }
4
- export function hyper(data, children) {
7
+ exports.holder = holder;
8
+ function hyper(data, children) {
5
9
  return { data, children };
6
10
  }
11
+ exports.hyper = hyper;
7
12
  /**
8
13
  * Utility function that create Overlay which mirror original object
9
14
  * @param o
10
15
  */
11
- export function hyperReflect(o) {
16
+ function hyperReflect(o) {
12
17
  if (o === null || o === undefined) {
13
18
  return hyper(o);
14
19
  }
@@ -22,10 +27,11 @@ export function hyperReflect(o) {
22
27
  return hyper(o);
23
28
  }
24
29
  }
30
+ exports.hyperReflect = hyperReflect;
25
31
  /**
26
32
  * Mainly used to prevent re-entrant navitation
27
33
  */
28
- export class ExplorationContext {
34
+ class ExplorationContext {
29
35
  constructor(parent, values) {
30
36
  this.parent = parent;
31
37
  this.values = values;
@@ -37,3 +43,4 @@ export class ExplorationContext {
37
43
  return new ExplorationContext(this, values);
38
44
  }
39
45
  }
46
+ exports.ExplorationContext = ExplorationContext;
@@ -1,3 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.notes = void 0;
1
4
  class NoteUtils {
2
5
  add(nv, ...notes) {
3
6
  return Object.assign(Object.assign({}, (nv !== null && nv !== void 0 ? nv : { type: "core:node-validation" })), { notes });
@@ -15,4 +18,4 @@ class NoteUtils {
15
18
  return { severity: "error", key, message, params };
16
19
  }
17
20
  }
18
- export const notes = new NoteUtils();
21
+ exports.notes = new NoteUtils();
@@ -1,13 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.utils = exports.removeDuplicates = exports.areSameDefined = exports.DEFAULT_EQUAL_FN = exports.equalSet = exports.isEmptyObject = exports.isNullish = exports.isNonNullObject = void 0;
1
4
  function includes(arr, t) {
2
5
  return arr === undefined ? false : arr.includes(t);
3
6
  }
4
- export function isNonNullObject(data) {
7
+ function isNonNullObject(data) {
5
8
  if (data === null || data === undefined) {
6
9
  return false;
7
10
  }
8
11
  const dataType = typeof data;
9
12
  return dataType === 'object' && !Array.isArray(data);
10
13
  }
14
+ exports.isNonNullObject = isNonNullObject;
11
15
  function isBlank(s) {
12
16
  return s === null || s === undefined || s.trim() === "";
13
17
  }
@@ -17,20 +21,24 @@ function isDefined(data) {
17
21
  function isNotDefined(data) {
18
22
  return !isDefined(data);
19
23
  }
20
- export function isNullish(o) {
24
+ function isNullish(o) {
21
25
  return o === null || o === undefined;
22
26
  }
23
- export function isEmptyObject(object) {
27
+ exports.isNullish = isNullish;
28
+ function isEmptyObject(object) {
24
29
  for (const property in object) {
25
30
  return false;
26
31
  }
27
32
  return true;
28
33
  }
29
- export function equalSet(a, b) {
34
+ exports.isEmptyObject = isEmptyObject;
35
+ function equalSet(a, b) {
30
36
  return a.size === b.size && [...a].every((x) => b.has(x));
31
37
  }
32
- export const DEFAULT_EQUAL_FN = (a, b) => a === b;
33
- export function areSameDefined(a, b, equalFn) {
38
+ exports.equalSet = equalSet;
39
+ const DEFAULT_EQUAL_FN = (a, b) => a === b;
40
+ exports.DEFAULT_EQUAL_FN = DEFAULT_EQUAL_FN;
41
+ function areSameDefined(a, b, equalFn) {
34
42
  if (a === undefined || b === undefined) {
35
43
  return false;
36
44
  }
@@ -39,14 +47,16 @@ export function areSameDefined(a, b, equalFn) {
39
47
  }
40
48
  return a === b || (equalFn ? equalFn(a, b) : false);
41
49
  }
50
+ exports.areSameDefined = areSameDefined;
42
51
  /**
43
52
  * Warning: non performant O(n2)
44
53
  * @param arr
45
54
  * @param equals
46
55
  */
47
- export function removeDuplicates(arr, equals = DEFAULT_EQUAL_FN) {
56
+ function removeDuplicates(arr, equals = exports.DEFAULT_EQUAL_FN) {
48
57
  return arr.filter((item, index) => arr.findIndex((e, i) => i < index && equals(item, e)) === -1);
49
58
  }
59
+ exports.removeDuplicates = removeDuplicates;
50
60
  // export function removeDuplicatesAndUndefined<T>(arr : (T|undefined)[], equals : EqualFn<T> = DEFAULT_EQUAL_FN) : T[] {
51
61
  // return arr.filter((item, index) : item is T => item !== undefined && arr.findIndex((e,i) => i < index && equals(item, e)) === -1)
52
62
  // }
@@ -110,4 +120,4 @@ function cascadeFilter(arr, fns) {
110
120
  return arr;
111
121
  }
112
122
  }
113
- export const utils = { includes, isNonNullObject, isEmptyObject, equalSet, isDefined, isBlank, isNotDefined, removeDuplicates, areSameDefined, intersection, deepEqual, escapeForXPath, cascadeFilter };
123
+ exports.utils = { includes, isNonNullObject, isEmptyObject, equalSet, isDefined, isBlank, isNotDefined, removeDuplicates, areSameDefined, intersection, deepEqual, escapeForXPath, cascadeFilter };
@@ -1,24 +1,49 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.areSameDefined = exports.removeDuplicates = exports.DEFAULT_EQUAL_FN = exports.utils = exports.default = void 0;
1
21
  // Type utilities
2
- export * from './core-utils-types-hkt';
3
- export * from './core-utils-types';
4
- export { default } from './core-utils-stack';
22
+ __exportStar(require("./core-utils-types-hkt"), exports);
23
+ __exportStar(require("./core-utils-types"), exports);
24
+ var core_utils_stack_1 = require("./core-utils-stack");
25
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(core_utils_stack_1).default; } });
5
26
  // Core utilities
6
- export { utils, DEFAULT_EQUAL_FN, removeDuplicates, areSameDefined } from './core-utils';
27
+ var core_utils_1 = require("./core-utils");
28
+ Object.defineProperty(exports, "utils", { enumerable: true, get: function () { return core_utils_1.utils; } });
29
+ Object.defineProperty(exports, "DEFAULT_EQUAL_FN", { enumerable: true, get: function () { return core_utils_1.DEFAULT_EQUAL_FN; } });
30
+ Object.defineProperty(exports, "removeDuplicates", { enumerable: true, get: function () { return core_utils_1.removeDuplicates; } });
31
+ Object.defineProperty(exports, "areSameDefined", { enumerable: true, get: function () { return core_utils_1.areSameDefined; } });
7
32
  // Resolvers
8
- export * from './core-utils-resolver';
33
+ __exportStar(require("./core-utils-resolver"), exports);
9
34
  // Path and navigation utilities
10
- export * from './core-utils-pathway';
11
- export * from './core-utils-pathway-resolver';
35
+ __exportStar(require("./core-utils-pathway"), exports);
36
+ __exportStar(require("./core-utils-pathway-resolver"), exports);
12
37
  // Itinerary utilities
13
- export * from './itinerary/itinerary';
14
- export * from './itinerary/stack';
38
+ __exportStar(require("./itinerary/itinerary"), exports);
39
+ __exportStar(require("./itinerary/stack"), exports);
15
40
  // Note: HyperLayerNode is exported from core-utils-types (more complete version with HKT)
16
41
  // Filesystem utilities
17
- export * from './core-utils-filesystem';
42
+ __exportStar(require("./core-utils-filesystem"), exports);
18
43
  // Other utilities
19
- export * from './core-utils-file';
20
- export * from './core-utils-registry';
21
- export * from './core-utils-chrono';
22
- export * from './core-utils-comparator';
23
- export * from './core-utils-fqn';
24
- export * from './core-utils-validations';
44
+ __exportStar(require("./core-utils-file"), exports);
45
+ __exportStar(require("./core-utils-registry"), exports);
46
+ __exportStar(require("./core-utils-chrono"), exports);
47
+ __exportStar(require("./core-utils-comparator"), exports);
48
+ __exportStar(require("./core-utils-fqn"), exports);
49
+ __exportStar(require("./core-utils-validations"), exports);
@@ -1,11 +1,15 @@
1
- export function hyper(data, children) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hyperReflect = exports.hyper = void 0;
4
+ function hyper(data, children) {
2
5
  return { data, children };
3
6
  }
7
+ exports.hyper = hyper;
4
8
  /**
5
9
  * Utility function that create Overlay which mirror original object
6
10
  * @param o
7
11
  */
8
- export function hyperReflect(o) {
12
+ function hyperReflect(o) {
9
13
  if (o === null || o === undefined) {
10
14
  return hyper(o);
11
15
  }
@@ -19,3 +23,4 @@ export function hyperReflect(o) {
19
23
  return hyper(o);
20
24
  }
21
25
  }
26
+ exports.hyperReflect = hyperReflect;
@@ -1,5 +1,11 @@
1
- import stack from "./stack";
2
- export function constructiveItinerary(steps) {
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ROOT = exports.pointer = exports.ensurePath = exports.overlayNavigator = exports.navigationDepth = exports.navigateStep = exports.navigate = exports.xpathFromStack = exports.lookupStep = exports.positionStep = exports.propertyStep = exports.itineraryToStepArray = exports.itineraryOverlay = exports.itineraryOf = exports.areSameItineraryStep = exports.constructiveItinerary = void 0;
7
+ const stack_1 = __importDefault(require("./stack"));
8
+ function constructiveItinerary(steps) {
3
9
  const segments = [];
4
10
  const prototypes = [];
5
11
  for (let i = 0; i < steps.length; i += 2) {
@@ -30,10 +36,11 @@ export function constructiveItinerary(steps) {
30
36
  }
31
37
  return {
32
38
  itinerary: itineraryOf(...segments),
33
- prototypes: stack.fromArray(prototypes)
39
+ prototypes: stack_1.default.fromArray(prototypes)
34
40
  };
35
41
  }
36
- export function areSameItineraryStep(step1, step2) {
42
+ exports.constructiveItinerary = constructiveItinerary;
43
+ function areSameItineraryStep(step1, step2) {
37
44
  var _a, _b, _c;
38
45
  if (step1 == undefined || step2 == undefined) {
39
46
  return false;
@@ -53,21 +60,24 @@ export function areSameItineraryStep(step1, step2) {
53
60
  }
54
61
  }
55
62
  }
63
+ exports.areSameItineraryStep = areSameItineraryStep;
56
64
  function areSamePropertyValuePair(p1, p2) {
57
65
  return p1.propertyName === p2.propertyName
58
66
  && p1.propertyValue === p2.propertyValue;
59
67
  }
60
- export function itineraryOf(...args) {
68
+ function itineraryOf(...args) {
61
69
  return args.reduce((parent, e) => {
62
70
  const value = typeof e === 'string' ? propertyStep(e) : positionStep(e);
63
71
  return { parent, value };
64
72
  }, undefined);
65
73
  }
74
+ exports.itineraryOf = itineraryOf;
66
75
  const dataStep = propertyStep("data");
67
76
  const childrenStep = propertyStep("children");
68
- export function itineraryOverlay(it) {
77
+ function itineraryOverlay(it) {
69
78
  return { value: dataStep, parent: itineraryOverlayInner(it) };
70
79
  }
80
+ exports.itineraryOverlay = itineraryOverlay;
71
81
  function itineraryOverlayInner(it) {
72
82
  if (it === undefined) {
73
83
  return undefined;
@@ -77,7 +87,7 @@ function itineraryOverlayInner(it) {
77
87
  return { value, parent: { value: childrenStep, parent: itineraryOverlayInner(parent) } };
78
88
  }
79
89
  }
80
- export function itineraryToStepArray(itinerary) {
90
+ function itineraryToStepArray(itinerary) {
81
91
  let itn = itinerary;
82
92
  const result = [];
83
93
  while (itn !== undefined) {
@@ -86,16 +96,20 @@ export function itineraryToStepArray(itinerary) {
86
96
  }
87
97
  return result.reverse();
88
98
  }
89
- export function propertyStep(propertyName) {
99
+ exports.itineraryToStepArray = itineraryToStepArray;
100
+ function propertyStep(propertyName) {
90
101
  return { type: "property", propertyName };
91
102
  }
92
- export function positionStep(position) {
103
+ exports.propertyStep = propertyStep;
104
+ function positionStep(position) {
93
105
  return { type: "position", position };
94
106
  }
95
- export function lookupStep(criteria) {
107
+ exports.positionStep = positionStep;
108
+ function lookupStep(criteria) {
96
109
  return { type: "lookup", keys: Object.entries(criteria).map(([k, v]) => ({ propertyName: k, propertyValue: v })) };
97
110
  }
98
- export function xpathFromStack(path) {
111
+ exports.lookupStep = lookupStep;
112
+ function xpathFromStack(path) {
99
113
  if (path === undefined) {
100
114
  return ''; // TODO may need to return '.' here, to be checked
101
115
  }
@@ -116,7 +130,8 @@ export function xpathFromStack(path) {
116
130
  }
117
131
  }
118
132
  }
119
- export function navigate(from, itinerary, prototype) {
133
+ exports.xpathFromStack = xpathFromStack;
134
+ function navigate(from, itinerary, prototype) {
120
135
  if (from === undefined) {
121
136
  return undefined;
122
137
  }
@@ -127,7 +142,8 @@ export function navigate(from, itinerary, prototype) {
127
142
  const current = navigate(from, parent, prototype === null || prototype === void 0 ? void 0 : prototype.parent);
128
143
  return navigateStep(current, step, prototype === null || prototype === void 0 ? void 0 : prototype.value);
129
144
  }
130
- export function navigateStep(from, step, prototype) {
145
+ exports.navigate = navigate;
146
+ function navigateStep(from, step, prototype) {
131
147
  if (from === undefined) {
132
148
  return undefined;
133
149
  }
@@ -171,7 +187,8 @@ export function navigateStep(from, step, prototype) {
171
187
  }
172
188
  return undefined;
173
189
  }
174
- export function navigationDepth(from, itinerary, originalPath = xpathFromStack(itinerary)) {
190
+ exports.navigateStep = navigateStep;
191
+ function navigationDepth(from, itinerary, originalPath = xpathFromStack(itinerary)) {
175
192
  if (from === undefined || from === null) {
176
193
  return { value: undefined, path: '', originalPath };
177
194
  }
@@ -191,6 +208,7 @@ export function navigationDepth(from, itinerary, originalPath = xpathFromStack(i
191
208
  return { value: next, path: xpathFromStack(itinerary), originalPath };
192
209
  }
193
210
  }
211
+ exports.navigationDepth = navigationDepth;
194
212
  class OverlayNavigator {
195
213
  navigate(from, itinerary) {
196
214
  if (from === undefined) {
@@ -230,16 +248,17 @@ class OverlayNavigator {
230
248
  return undefined;
231
249
  }
232
250
  }
233
- export const overlayNavigator = new OverlayNavigator();
251
+ exports.overlayNavigator = new OverlayNavigator();
234
252
  /**
235
253
  * Same as {navigate} but try to path missing data node using prototype parameter
236
254
  * @param from
237
255
  * @param itinerary
238
256
  * @param prototype
239
257
  */
240
- export function ensurePath(from, itinerary, prototype) {
258
+ function ensurePath(from, itinerary, prototype) {
241
259
  return navigate(from, itinerary, prototype);
242
260
  }
261
+ exports.ensurePath = ensurePath;
243
262
  class AbstractPointerBuilder {
244
263
  constructor() {
245
264
  this.itinerary = [];
@@ -267,10 +286,11 @@ class AbsolutePointerBuilder extends AbstractPointerBuilder {
267
286
  this.type = "absolute";
268
287
  }
269
288
  }
270
- export function pointer(fromId) {
289
+ function pointer(fromId) {
271
290
  if (fromId === undefined) {
272
291
  return new AbsolutePointerBuilder();
273
292
  }
274
293
  return new RelativePointerBuilder(fromId);
275
294
  }
276
- export const ROOT = Object.freeze({ type: "absolute", itinerary: [] });
295
+ exports.pointer = pointer;
296
+ exports.ROOT = Object.freeze({ type: "absolute", itinerary: [] });
@@ -1,10 +1,15 @@
1
- export function head(value) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reduce = exports.fromArray = exports.concat = exports.push = exports.head = void 0;
4
+ function head(value) {
2
5
  return { value };
3
6
  }
4
- export function push(head, value) {
7
+ exports.head = head;
8
+ function push(head, value) {
5
9
  return { value, parent: head };
6
10
  }
7
- export function concat(tail, stack) {
11
+ exports.push = push;
12
+ function concat(tail, stack) {
8
13
  if (tail === undefined)
9
14
  return stack;
10
15
  if (stack === undefined)
@@ -12,10 +17,12 @@ export function concat(tail, stack) {
12
17
  const { parent, value } = stack;
13
18
  return { value, parent: concat(tail, parent) };
14
19
  }
15
- export function fromArray(t) {
20
+ exports.concat = concat;
21
+ function fromArray(t) {
16
22
  return t === null || t === void 0 ? void 0 : t.reduce((acc, t) => push(acc, t), undefined);
17
23
  }
18
- export function reduce(head, reducer, initial) {
24
+ exports.fromArray = fromArray;
25
+ function reduce(head, reducer, initial) {
19
26
  if (head === undefined) {
20
27
  return initial;
21
28
  }
@@ -23,6 +30,7 @@ export function reduce(head, reducer, initial) {
23
30
  const acc = reduce(parent, reducer, initial);
24
31
  return reducer(acc, value);
25
32
  }
33
+ exports.reduce = reduce;
26
34
  function equal(a, b) {
27
35
  // Not equal if both are nullish
28
36
  if (a === undefined || a === null || b === undefined || b === null) {
@@ -44,4 +52,4 @@ function equal(a, b) {
44
52
  }
45
53
  }
46
54
  const stack = { push, head, concat, reduce, fromArray, equal };
47
- export default stack;
55
+ exports.default = stack;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hamak/shared-utils",
3
- "version": "0.4.1",
3
+ "version": "0.4.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Shared utilities for path navigation, filesystem operations, and common helpers",
@@ -25,11 +25,11 @@
25
25
  ".": {
26
26
  "types": "./dist/index.d.ts",
27
27
  "import": "./dist/index.js",
28
- "default": "./dist/index.js",
29
- "legacy": "./dist/es2015/index.js"
28
+ "require": "./dist/es2015/index.js",
29
+ "default": "./dist/index.js"
30
30
  },
31
31
  "./es2015": {
32
- "import": "./dist/es2015/index.js",
32
+ "require": "./dist/es2015/index.js",
33
33
  "default": "./dist/es2015/index.js"
34
34
  }
35
35
  },
@@ -230,3 +230,41 @@ export class Pathway {
230
230
  }
231
231
 
232
232
  }
233
+
234
+ /**
235
+ * Converts a path (string or string array) to an array of path segments.
236
+ * If already an array, returns it as-is.
237
+ * If a string, splits by '/' and filters out empty segments.
238
+ *
239
+ * @param path - The path to convert to segments
240
+ * @returns Array of path segments
241
+ *
242
+ * @example
243
+ * pathSteps('/foo/bar/baz') // ['foo', 'bar', 'baz']
244
+ * pathSteps(['foo', 'bar']) // ['foo', 'bar']
245
+ * pathSteps('foo//bar/') // ['foo', 'bar']
246
+ */
247
+ export function pathSteps(path: string | string[]): string[] {
248
+ if (Array.isArray(path)) {
249
+ return path;
250
+ }
251
+
252
+ return path.split('/').filter(s => s.trim().length > 0);
253
+ }
254
+
255
+ /**
256
+ * Returns the parent path segments by removing the last segment.
257
+ * Uses pathSteps internally to normalize the input path.
258
+ *
259
+ * @param path - The path to get parent segments from
260
+ * @returns Array of parent path segments (all but last segment)
261
+ *
262
+ * @example
263
+ * parentPathSteps('/foo/bar/baz') // ['foo', 'bar']
264
+ * parentPathSteps(['foo', 'bar']) // ['foo']
265
+ * parentPathSteps(['foo']) // []
266
+ */
267
+ export function parentPathSteps(path: string | string[]): string[] {
268
+ const steps = pathSteps(path);
269
+ return steps.length > 0 ? steps.slice(0, steps.length - 1) : steps;
270
+ }
@@ -1,24 +1,21 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
2
  "compilerOptions": {
4
3
  "target": "ES2015",
5
- "lib": [
6
- "ES2015"
7
- ],
4
+ "module": "CommonJS",
5
+ "lib": ["ES2015"],
6
+ "skipLibCheck": true,
7
+ "moduleResolution": "node",
8
+ "resolveJsonModule": true,
9
+ "strict": true,
8
10
  "outDir": "./dist/es2015",
11
+ "rootDir": "./src",
9
12
  "declaration": false,
10
13
  "declarationMap": false,
11
14
  "sourceMap": false,
12
15
  "downlevelIteration": true,
13
- "composite": false
16
+ "esModuleInterop": true,
17
+ "allowSyntheticDefaultImports": true
14
18
  },
15
- "include": [
16
- "src/**/*"
17
- ],
18
- "exclude": [
19
- "node_modules",
20
- "dist",
21
- "**/*.spec.ts",
22
- "**/*.test.ts"
23
- ]
19
+ "include": ["src/**/*"],
20
+ "exclude": ["node_modules", "dist", "**/*.spec.ts", "**/*.test.ts"]
24
21
  }