@telperion/js-utils 3.5.0 → 3.6.3

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/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
  Javascript utility functions for web development
3
3
 
4
4
  [![npm](https://img.shields.io/npm/v/@telperion/js-utils.svg)](https://www.npmjs.com/package/@telperion/js-utils)
5
- [![npm](https://img.shields.io/npm/dw/@telperion/js-utils.svg)](https://www.npmjs.com/package/@telperion/js-utils)
5
+ [![npm](https://img.shields.io/npm/dm/@telperion/js-utils.svg)](https://www.npmjs.com/package/@telperion/js-utils)
6
+ [![codecov](https://codecov.io/gh/telperiontech/telperion/graph/badge.svg?token=dz46LY3onk&flag=js-utils)](https://app.codecov.io/gh/telperiontech/telperion/tree/main?flags%5B0%5D=js-utils)
6
7
  [![TypeScript](https://badges.frapsoft.com/typescript/version/typescript-next.svg?v=101)](https://github.com/ellerbrock/typescript-badges/)
7
8
  [![npm](https://img.shields.io/npm/l/@telperion/js-utils.svg)](https://github.com/telperiontech/telperion/blob/main/LICENSE)
8
9
 
@@ -293,6 +294,17 @@ const a = {
293
294
  compact(a); // {z: 20}
294
295
  ```
295
296
 
297
+ #### [Map](https://open-source.telperion.tr/js-utils/modules/_object_map_.html)
298
+ Maps the values of an object using a callback function
299
+
300
+ ```typescript
301
+ import { map } from "@telperion/js-utils/object";
302
+
303
+ const obj = { a: 1, b: 2, c: 3 };
304
+
305
+ map(obj, value => value * 2); // { a: 2, b: 4, c: 6 }
306
+ ```
307
+
296
308
  #### [Deepest](https://open-source.telperion.tr/js-utils/modules/_object_deepest_.html)
297
309
  Get deepest value in an object chain
298
310
 
@@ -1,4 +1,4 @@
1
- import type { Tail } from '@thalesrc/extra-ts-types';
1
+ import type { Tail } from '@telperion/extra-ts-types';
2
2
  import { remove } from '@telperion/js-utils/array/remove';
3
3
  type FuncType<T> = typeof remove<T>;
4
4
  type FuncArgs<T> = Parameters<FuncType<T>>;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/remove.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAiC1D,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,UAAuB,GAAG,IAAkB;IACnE,OAAO,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;AAC/B,CAAC,CAAC","file":"remove.js","sourcesContent":["import type { Tail } from '@thalesrc/extra-ts-types';\n\nimport { remove } from '@telperion/js-utils/array/remove';\n\ntype FuncType<T> = typeof remove<T>;\ntype FuncArgs<T> = Parameters<FuncType<T>>;\ntype FuncReturn<T> = ReturnType<FuncType<T>>;\ntype ProtoArgs<T> = Tail<FuncArgs<T>>;\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Remove\n *\n * Removes an item from the array\n *\n * Removes all item references if multi is set to `true`\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/remove\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n *\n * array.remove(\"b\", true); // [\"a\", \"c\", \"a\", \"c\"]\n * ```\n * * * *\n * @param itemToRemove Item to remove\n * @return New array\n */\n remove(...args: ProtoArgs<T>): FuncReturn<T>;\n }\n}\n\nArray.prototype.remove = function<T>(this: T[], ...args: ProtoArgs<T>): FuncReturn<T> {\n return remove(this, ...args);\n};\n"]}
1
+ {"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/remove.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,kCAAkC,CAAC;AAiC1D,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,UAAuB,GAAG,IAAkB;IACnE,OAAO,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;AAC/B,CAAC,CAAC","file":"remove.js","sourcesContent":["import type { Tail } from '@telperion/extra-ts-types';\n\nimport { remove } from '@telperion/js-utils/array/remove';\n\ntype FuncType<T> = typeof remove<T>;\ntype FuncArgs<T> = Parameters<FuncType<T>>;\ntype FuncReturn<T> = ReturnType<FuncType<T>>;\ntype ProtoArgs<T> = Tail<FuncArgs<T>>;\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Remove\n *\n * Removes an item from the array\n *\n * Removes all item references if multi is set to `true`\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/remove\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n *\n * array.remove(\"b\", true); // [\"a\", \"c\", \"a\", \"c\"]\n * ```\n * * * *\n * @param itemToRemove Item to remove\n * @return New array\n */\n remove(...args: ProtoArgs<T>): FuncReturn<T>;\n }\n}\n\nArray.prototype.remove = function<T>(this: T[], ...args: ProtoArgs<T>): FuncReturn<T> {\n return remove(this, ...args);\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/replace.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAA4C,MAAM,mCAAmC,CAAC;AA4EtG,KAAK,CAAC,SAAS,CAAC,OAAO,GAA0B,UAAuB,GAAG,IAAyC;IAClH,OAAO,OAAO,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;AAChC,CAAC,CAAC","file":"replace.js","sourcesContent":["import type { Tail } from '@thalesrc/extra-ts-types';\n\nimport { replace, ReplaceItemsOptions, ReplaceByMapOptions } from '@telperion/js-utils/array/replace';\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Replace\n *\n * Replaces an item with passed one of an array\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/replace\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n *\n * array.replace(\"b\", \"x\"); // [\"a\", \"x\", \"c\", \"a\", \"b\", \"c\"]\n * ```\n * * * *\n * @param array Array to replace its item\n * @param itemToRemove Item to remove\n * @param itemToReplace Item to replace with\n * @return New replaced array\n */\n replace(itemToRemove: T, itemToReplace: T): T[];\n\n /**\n * #### Replace\n *\n * Deletes items and replaces new ones from passed starting index of an array\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/replace\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n *\n * array.replace({startingIndex: 3, deleteCount: 1, itemsToReplace: ['x', 'y']}); // [\"a\", \"b\", \"c\", \"x\", \"y\", \"b\", \"c\"];\n * ```\n * * * *\n * @param array Array to replace its item\n * @param replaceOptions Replace options\n * @template T Typeof array items\n * @return New replaced array\n */\n replace(replaceOptions: ReplaceItemsOptions<T>): T[];\n\n /**\n * #### Replace\n *\n * Deletes items and replaces new ones by passed matcher map\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/replace\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n * const map = new Map();\n * map.set(\"a\", \"x\")\n * map.set(\"b\", \"y\");\n *\n * array.replace({itemsToReplace: map}); // [\"x\", \"y\", \"c\", \"a\", \"b\", \"c\"];\n * array.replace({itemsToReplace: map, multi: true}); // [\"x\", \"y\", \"c\", \"x\", \"y\", \"c\"];\n * ```\n * * * *\n * @param array Array to replace its item\n * @param replaceOptions Replace options\n * @template T Typeof array items\n * @return New replaced array\n */\n replace(replaceOptions: ReplaceByMapOptions<T>): T[];\n }\n}\n\nArray.prototype.replace = <Array<any>['replace']>function<T>(this: T[], ...args: Tail<Parameters<typeof replace<T>>>): T[] {\n return replace(this, ...args);\n};\n"]}
1
+ {"version":3,"sources":["../../../../../libs/js-utils/src/array/proto/replace.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAA4C,MAAM,mCAAmC,CAAC;AA4EtG,KAAK,CAAC,SAAS,CAAC,OAAO,GAA0B,UAAuB,GAAG,IAAyC;IAClH,OAAO,OAAO,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;AAChC,CAAC,CAAC","file":"replace.js","sourcesContent":["import type { Tail } from '@telperion/extra-ts-types';\n\nimport { replace, ReplaceItemsOptions, ReplaceByMapOptions } from '@telperion/js-utils/array/replace';\n\ndeclare global {\n export interface Array<T> {\n /**\n * #### Replace\n *\n * Replaces an item with passed one of an array\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/replace\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n *\n * array.replace(\"b\", \"x\"); // [\"a\", \"x\", \"c\", \"a\", \"b\", \"c\"]\n * ```\n * * * *\n * @param array Array to replace its item\n * @param itemToRemove Item to remove\n * @param itemToReplace Item to replace with\n * @return New replaced array\n */\n replace(itemToRemove: T, itemToReplace: T): T[];\n\n /**\n * #### Replace\n *\n * Deletes items and replaces new ones from passed starting index of an array\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/replace\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n *\n * array.replace({startingIndex: 3, deleteCount: 1, itemsToReplace: ['x', 'y']}); // [\"a\", \"b\", \"c\", \"x\", \"y\", \"b\", \"c\"];\n * ```\n * * * *\n * @param array Array to replace its item\n * @param replaceOptions Replace options\n * @template T Typeof array items\n * @return New replaced array\n */\n replace(replaceOptions: ReplaceItemsOptions<T>): T[];\n\n /**\n * #### Replace\n *\n * Deletes items and replaces new ones by passed matcher map\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/array/proto/replace\";\n *\n * const array = [\"a\", \"b\", \"c\", \"a\", \"b\", \"c\"];\n * const map = new Map();\n * map.set(\"a\", \"x\")\n * map.set(\"b\", \"y\");\n *\n * array.replace({itemsToReplace: map}); // [\"x\", \"y\", \"c\", \"a\", \"b\", \"c\"];\n * array.replace({itemsToReplace: map, multi: true}); // [\"x\", \"y\", \"c\", \"x\", \"y\", \"c\"];\n * ```\n * * * *\n * @param array Array to replace its item\n * @param replaceOptions Replace options\n * @template T Typeof array items\n * @return New replaced array\n */\n replace(replaceOptions: ReplaceByMapOptions<T>): T[];\n }\n}\n\nArray.prototype.replace = <Array<any>['replace']>function<T>(this: T[], ...args: Tail<Parameters<typeof replace<T>>>): T[] {\n return replace(this, ...args);\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/js-utils/src/function/proto/debounce.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAgCxF,QAAQ,CAAC,SAAS,CAAC,QAAQ,GAAG,UAA4B,IAAI,GAAG,qBAAqB,EAAE,aAAkB,IAAI,EAAE,GAAG,IAAW;IAC5H,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC;AACnD,CAAC,CAAC","file":"debounce.js","sourcesContent":["import type { AnyFunction } from '@thalesrc/extra-ts-types';\n\nimport { debounce, DEFAULT_DEBOUNCE_TIME } from '@telperion/js-utils/function/debounce';\n\ndeclare global {\n export interface Function {\n /**\n * #### Debounces a function that delays invoking until after given time have elapsed since the last time the debounced function was invoked\n *\n * * * *\n * Example usage:\n * ```typescript\n * import \"@telperion/js-utils/function/proto/debounce\";\n *\n * function foo() {\n * console.log(\"hello\");\n * }\n *\n * for (let i = 0; i < 5; i++) {\n * foo.debounce();\n * }\n *\n * // logs \"hello\" only once\n * ```\n * * * *\n * @param [time = 180] Time for debouncing\n * @param [thisObject = null] This object to execute the callback function with\n * @param args Function arguments\n * @return A promise which resolves right after the debouncing sequence has been finished\n */\n debounce(time?: number, thisObject?: any, ...args: any[]): Promise<any>;\n }\n}\n\nFunction.prototype.debounce = function(this: AnyFunction, time = DEFAULT_DEBOUNCE_TIME, thisObject: any = null, ...args: any[]): Promise<any> {\n return debounce(this, time, thisObject, ...args);\n};\n"]}
1
+ {"version":3,"sources":["../../../../../libs/js-utils/src/function/proto/debounce.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAgCxF,QAAQ,CAAC,SAAS,CAAC,QAAQ,GAAG,UAA4B,IAAI,GAAG,qBAAqB,EAAE,aAAkB,IAAI,EAAE,GAAG,IAAW;IAC5H,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,CAAC;AACnD,CAAC,CAAC","file":"debounce.js","sourcesContent":["import type { AnyFunction } from '@telperion/extra-ts-types';\n\nimport { debounce, DEFAULT_DEBOUNCE_TIME } from '@telperion/js-utils/function/debounce';\n\ndeclare global {\n export interface Function {\n /**\n * #### Debounces a function that delays invoking until after given time have elapsed since the last time the debounced function was invoked\n *\n * * * *\n * Example usage:\n * ```typescript\n * import \"@telperion/js-utils/function/proto/debounce\";\n *\n * function foo() {\n * console.log(\"hello\");\n * }\n *\n * for (let i = 0; i < 5; i++) {\n * foo.debounce();\n * }\n *\n * // logs \"hello\" only once\n * ```\n * * * *\n * @param [time = 180] Time for debouncing\n * @param [thisObject = null] This object to execute the callback function with\n * @param args Function arguments\n * @return A promise which resolves right after the debouncing sequence has been finished\n */\n debounce(time?: number, thisObject?: any, ...args: any[]): Promise<any>;\n }\n}\n\nFunction.prototype.debounce = function(this: AnyFunction, time = DEFAULT_DEBOUNCE_TIME, thisObject: any = null, ...args: any[]): Promise<any> {\n return debounce(this, time, thisObject, ...args);\n};\n"]}
package/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deepFreeze = exports.deepest = exports.clone = exports.uniquifyByKey = exports.uniquify = exports.replace = exports.remove = exports.intersection = exports.findByKey = exports.difference = exports.asyncMap = exports.arrayize = void 0;
3
+ exports.map = exports.deepFreeze = exports.deepest = exports.clone = exports.uniquifyByKey = exports.uniquify = exports.replace = exports.remove = exports.intersection = exports.findByKey = exports.difference = exports.asyncMap = exports.arrayize = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  var array_1 = require("@telperion/js-utils/array");
6
6
  Object.defineProperty(exports, "arrayize", { enumerable: true, get: function () { return array_1.arrayize; } });
@@ -20,7 +20,9 @@ var object_1 = require("@telperion/js-utils/object");
20
20
  Object.defineProperty(exports, "clone", { enumerable: true, get: function () { return object_1.clone; } });
21
21
  Object.defineProperty(exports, "deepest", { enumerable: true, get: function () { return object_1.deepest; } });
22
22
  Object.defineProperty(exports, "deepFreeze", { enumerable: true, get: function () { return object_1.deepFreeze; } });
23
+ Object.defineProperty(exports, "map", { enumerable: true, get: function () { return object_1.map; } });
23
24
  tslib_1.__exportStar(require("@telperion/js-utils/promise"), exports);
25
+ tslib_1.__exportStar(require("@telperion/js-utils/time"), exports);
24
26
  // export { } from '@telperion/js-utils/string';
25
27
  tslib_1.__exportStar(require("@telperion/js-utils/compact"), exports);
26
28
  tslib_1.__exportStar(require("@telperion/js-utils/is-falsy"), exports);
package/index.d.ts CHANGED
@@ -3,8 +3,9 @@ export * from '@telperion/js-utils/class';
3
3
  export * from '@telperion/js-utils/function';
4
4
  export * from '@telperion/js-utils/map';
5
5
  export * from '@telperion/js-utils/math';
6
- export { clone, deepest, deepFreeze } from '@telperion/js-utils/object';
6
+ export { clone, deepest, deepFreeze, map } from '@telperion/js-utils/object';
7
7
  export * from '@telperion/js-utils/promise';
8
+ export * from '@telperion/js-utils/time';
8
9
  export * from '@telperion/js-utils/compact';
9
10
  export * from '@telperion/js-utils/is-falsy';
10
11
  export * from '@telperion/js-utils/is-truthy';
package/index.js CHANGED
@@ -3,8 +3,9 @@ export * from '@telperion/js-utils/class';
3
3
  export * from '@telperion/js-utils/function';
4
4
  export * from '@telperion/js-utils/map';
5
5
  export * from '@telperion/js-utils/math';
6
- export { clone, deepest, deepFreeze } from '@telperion/js-utils/object';
6
+ export { clone, deepest, deepFreeze, map } from '@telperion/js-utils/object';
7
7
  export * from '@telperion/js-utils/promise';
8
+ export * from '@telperion/js-utils/time';
8
9
  // export { } from '@telperion/js-utils/string';
9
10
  export * from '@telperion/js-utils/compact';
10
11
  export * from '@telperion/js-utils/is-falsy';
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/js-utils/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,SAAS,EACT,YAAY,EACZ,MAAM,EACN,OAAO,EACP,QAAQ,EACR,aAAa,EACd,MAAM,2BAA2B,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxE,cAAc,6BAA6B,CAAC;AAC5C,iDAAiD;AAEjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC","file":"index.js","sourcesContent":["export {\n ReplaceByMapOptions,\n ReplaceItemsOptions,\n Inclusion,\n Substraction,\n arrayize,\n asyncMap,\n difference,\n findByKey,\n intersection,\n remove,\n replace,\n uniquify,\n uniquifyByKey\n} from '@telperion/js-utils/array';\nexport * from '@telperion/js-utils/class';\nexport * from '@telperion/js-utils/function';\nexport * from '@telperion/js-utils/map';\nexport * from '@telperion/js-utils/math';\nexport { clone, deepest, deepFreeze } from '@telperion/js-utils/object';\nexport * from '@telperion/js-utils/promise';\n// export { } from '@telperion/js-utils/string';\n\nexport * from '@telperion/js-utils/compact';\nexport * from '@telperion/js-utils/is-falsy';\nexport * from '@telperion/js-utils/is-truthy';\nexport * from '@telperion/js-utils/open-promise';\nexport * from '@telperion/js-utils/smart-map';\nexport * from '@telperion/js-utils/unique-id';\nexport * from '@telperion/js-utils/limit';\n"]}
1
+ {"version":3,"sources":["../../../../../libs/js-utils/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,SAAS,EACT,YAAY,EACZ,MAAM,EACN,OAAO,EACP,QAAQ,EACR,aAAa,EACd,MAAM,2BAA2B,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,4BAA4B,CAAC;AAC7E,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,iDAAiD;AAEjD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC","file":"index.js","sourcesContent":["export {\n ReplaceByMapOptions,\n ReplaceItemsOptions,\n Inclusion,\n Substraction,\n arrayize,\n asyncMap,\n difference,\n findByKey,\n intersection,\n remove,\n replace,\n uniquify,\n uniquifyByKey\n} from '@telperion/js-utils/array';\nexport * from '@telperion/js-utils/class';\nexport * from '@telperion/js-utils/function';\nexport * from '@telperion/js-utils/map';\nexport * from '@telperion/js-utils/math';\nexport { clone, deepest, deepFreeze, map } from '@telperion/js-utils/object';\nexport * from '@telperion/js-utils/promise';\nexport * from '@telperion/js-utils/time';\n// export { } from '@telperion/js-utils/string';\n\nexport * from '@telperion/js-utils/compact';\nexport * from '@telperion/js-utils/is-falsy';\nexport * from '@telperion/js-utils/is-truthy';\nexport * from '@telperion/js-utils/open-promise';\nexport * from '@telperion/js-utils/smart-map';\nexport * from '@telperion/js-utils/unique-id';\nexport * from '@telperion/js-utils/limit';\n"]}
@@ -1,4 +1,4 @@
1
- import type { DeepestObject } from "@thalesrc/extra-ts-types";
1
+ import type { DeepestObject } from "@telperion/extra-ts-types";
2
2
  /**
3
3
  * #### Get deepest object in an object chain
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/js-utils/src/object/deepest.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,UAAU,OAAO,CAAuB,MAAS,EAAE,GAAM;IAC7D,IAAI,GAAG,GAAG,MAAM,CAAC;IAEjB,OAAO,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAChB,GAAG,GAAG,GAAG,CAAC,GAAG,CAAM,CAAC;IACtB,CAAC;IAED,OAAO,GAA0B,CAAC;AACpC,CAAC","file":"deepest.js","sourcesContent":["import type { DeepestObject } from \"@thalesrc/extra-ts-types\";\n\n/**\n * #### Get deepest object in an object chain\n *\n * * * * *\n * Example usage:\n * ```typescript\n * import { deepest } from \"@telperion/js-utils/object\";\n *\n * const a = {\n * x: null\n * };\n *\n * const b = {\n * x: a\n * };\n *\n * const c = {\n * x: b\n * };\n *\n * deepest(c, 'x'); // {x: null} (a)\n *\n * ```\n * Static usage example:\n * ```typescript\n * import \"@telperion/js-utils/object/static/deepest\";\n *\n * const a = {\n * x: null\n * };\n *\n * const b = {\n * x: a\n * };\n *\n * const c = {\n * x: b\n * };\n *\n * Object.deepest(c, 'x'); // a\n * ```\n * * * *\n * @param object Object to deep dive\n * @param key key of the object which contains same type instance\n */\nexport function deepest<T, K extends keyof T>(object: T, key: K): DeepestObject<T, K> {\n let obj = object;\n\n while (obj[key]) {\n obj = obj[key] as T;\n }\n\n return obj as DeepestObject<T, K>;\n}\n"]}
1
+ {"version":3,"sources":["../../../../../libs/js-utils/src/object/deepest.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,UAAU,OAAO,CAAuB,MAAS,EAAE,GAAM;IAC7D,IAAI,GAAG,GAAG,MAAM,CAAC;IAEjB,OAAO,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAChB,GAAG,GAAG,GAAG,CAAC,GAAG,CAAM,CAAC;IACtB,CAAC;IAED,OAAO,GAA0B,CAAC;AACpC,CAAC","file":"deepest.js","sourcesContent":["import type { DeepestObject } from \"@telperion/extra-ts-types\";\n\n/**\n * #### Get deepest object in an object chain\n *\n * * * * *\n * Example usage:\n * ```typescript\n * import { deepest } from \"@telperion/js-utils/object\";\n *\n * const a = {\n * x: null\n * };\n *\n * const b = {\n * x: a\n * };\n *\n * const c = {\n * x: b\n * };\n *\n * deepest(c, 'x'); // {x: null} (a)\n *\n * ```\n * Static usage example:\n * ```typescript\n * import \"@telperion/js-utils/object/static/deepest\";\n *\n * const a = {\n * x: null\n * };\n *\n * const b = {\n * x: a\n * };\n *\n * const c = {\n * x: b\n * };\n *\n * Object.deepest(c, 'x'); // a\n * ```\n * * * *\n * @param object Object to deep dive\n * @param key key of the object which contains same type instance\n */\nexport function deepest<T, K extends keyof T>(object: T, key: K): DeepestObject<T, K> {\n let obj = object;\n\n while (obj[key]) {\n obj = obj[key] as T;\n }\n\n return obj as DeepestObject<T, K>;\n}\n"]}
package/object/index.cjs CHANGED
@@ -5,3 +5,4 @@ tslib_1.__exportStar(require("@telperion/js-utils/object/clone"), exports);
5
5
  tslib_1.__exportStar(require("@telperion/js-utils/object/compact"), exports);
6
6
  tslib_1.__exportStar(require("@telperion/js-utils/object/deepest"), exports);
7
7
  tslib_1.__exportStar(require("@telperion/js-utils/object/deep-freeze"), exports);
8
+ tslib_1.__exportStar(require("@telperion/js-utils/object/map"), exports);
package/object/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from '@telperion/js-utils/object/clone';
2
2
  export * from '@telperion/js-utils/object/compact';
3
3
  export * from '@telperion/js-utils/object/deepest';
4
4
  export * from '@telperion/js-utils/object/deep-freeze';
5
+ export * from '@telperion/js-utils/object/map';
package/object/index.js CHANGED
@@ -2,5 +2,6 @@ export * from '@telperion/js-utils/object/clone';
2
2
  export * from '@telperion/js-utils/object/compact';
3
3
  export * from '@telperion/js-utils/object/deepest';
4
4
  export * from '@telperion/js-utils/object/deep-freeze';
5
+ export * from '@telperion/js-utils/object/map';
5
6
 
6
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/js-utils/src/object/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,wCAAwC,CAAC","file":"index.js","sourcesContent":["export * from '@telperion/js-utils/object/clone';\nexport * from '@telperion/js-utils/object/compact';\nexport * from '@telperion/js-utils/object/deepest';\nexport * from '@telperion/js-utils/object/deep-freeze';\n"]}
1
+ {"version":3,"sources":["../../../../../libs/js-utils/src/object/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC;AACjD,cAAc,oCAAoC,CAAC;AACnD,cAAc,oCAAoC,CAAC;AACnD,cAAc,wCAAwC,CAAC;AACvD,cAAc,gCAAgC,CAAC","file":"index.js","sourcesContent":["export * from '@telperion/js-utils/object/clone';\nexport * from '@telperion/js-utils/object/compact';\nexport * from '@telperion/js-utils/object/deepest';\nexport * from '@telperion/js-utils/object/deep-freeze';\nexport * from '@telperion/js-utils/object/map';\n"]}
package/object/map.cjs ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.map = map;
4
+ /**
5
+ * #### Maps the values of an object using a callback function
6
+ *
7
+ * Similar to `Array.prototype.map`, but for objects. Iterates over own enumerable properties
8
+ * and returns a new object with the same keys and transformed values.
9
+ *
10
+ * * * *
11
+ * Example usage:
12
+ * ```typescript
13
+ * import { map } from "@telperion/js-utils/object";
14
+ *
15
+ * const obj = { a: 1, b: 2, c: 3 };
16
+ *
17
+ * map(obj, value => value * 2); // { a: 2, b: 4, c: 6 }
18
+ * ```
19
+ *
20
+ * Example with key usage:
21
+ * ```typescript
22
+ * import { map } from "@telperion/js-utils/object";
23
+ *
24
+ * const obj = { x: 1, y: 2 };
25
+ *
26
+ * map(obj, (value, key) => `${key}_${value}`); // { x: "x_1", y: "y_2" }
27
+ * ```
28
+ * * * *
29
+ * @param object Object to map
30
+ * @param fn Callback function to transform each value, receives the value, key, and the entire object as arguments
31
+ * @returns A new object with the same keys and transformed values
32
+ */
33
+ function map(object, fn) {
34
+ const result = {};
35
+ for (const key in object) {
36
+ if (object.hasOwnProperty(key)) {
37
+ result[key] = fn(object[key], key, object);
38
+ }
39
+ }
40
+ return result;
41
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * #### Maps the values of an object using a callback function
3
+ *
4
+ * Similar to `Array.prototype.map`, but for objects. Iterates over own enumerable properties
5
+ * and returns a new object with the same keys and transformed values.
6
+ *
7
+ * * * *
8
+ * Example usage:
9
+ * ```typescript
10
+ * import { map } from "@telperion/js-utils/object";
11
+ *
12
+ * const obj = { a: 1, b: 2, c: 3 };
13
+ *
14
+ * map(obj, value => value * 2); // { a: 2, b: 4, c: 6 }
15
+ * ```
16
+ *
17
+ * Example with key usage:
18
+ * ```typescript
19
+ * import { map } from "@telperion/js-utils/object";
20
+ *
21
+ * const obj = { x: 1, y: 2 };
22
+ *
23
+ * map(obj, (value, key) => `${key}_${value}`); // { x: "x_1", y: "y_2" }
24
+ * ```
25
+ * * * *
26
+ * @param object Object to map
27
+ * @param fn Callback function to transform each value, receives the value, key, and the entire object as arguments
28
+ * @returns A new object with the same keys and transformed values
29
+ */
30
+ export declare function map<T extends Object, R>(object: T, fn: (value: T[keyof T], key: keyof T, object: T) => R): {
31
+ [K in keyof T]: R;
32
+ };
package/object/map.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * #### Maps the values of an object using a callback function
3
+ *
4
+ * Similar to `Array.prototype.map`, but for objects. Iterates over own enumerable properties
5
+ * and returns a new object with the same keys and transformed values.
6
+ *
7
+ * * * *
8
+ * Example usage:
9
+ * ```typescript
10
+ * import { map } from "@telperion/js-utils/object";
11
+ *
12
+ * const obj = { a: 1, b: 2, c: 3 };
13
+ *
14
+ * map(obj, value => value * 2); // { a: 2, b: 4, c: 6 }
15
+ * ```
16
+ *
17
+ * Example with key usage:
18
+ * ```typescript
19
+ * import { map } from "@telperion/js-utils/object";
20
+ *
21
+ * const obj = { x: 1, y: 2 };
22
+ *
23
+ * map(obj, (value, key) => `${key}_${value}`); // { x: "x_1", y: "y_2" }
24
+ * ```
25
+ * * * *
26
+ * @param object Object to map
27
+ * @param fn Callback function to transform each value, receives the value, key, and the entire object as arguments
28
+ * @returns A new object with the same keys and transformed values
29
+ */
30
+ export function map(object, fn) {
31
+ const result = {};
32
+ for (const key in object) {
33
+ if (object.hasOwnProperty(key)) {
34
+ result[key] = fn(object[key], key, object);
35
+ }
36
+ }
37
+ return result;
38
+ }
39
+
40
+ //# sourceMappingURL=map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/js-utils/src/object/map.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,GAAG,CACjB,MAAS,EACT,EAAqD;IAErD,MAAM,MAAM,GAAG,EAA2B,CAAC;IAE3C,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,IAAI,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/B,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","file":"map.js","sourcesContent":["/**\r\n * #### Maps the values of an object using a callback function\r\n *\r\n * Similar to `Array.prototype.map`, but for objects. Iterates over own enumerable properties\r\n * and returns a new object with the same keys and transformed values.\r\n *\r\n * * * *\r\n * Example usage:\r\n * ```typescript\r\n * import { map } from \"@telperion/js-utils/object\";\r\n *\r\n * const obj = { a: 1, b: 2, c: 3 };\r\n *\r\n * map(obj, value => value * 2); // { a: 2, b: 4, c: 6 }\r\n * ```\r\n *\r\n * Example with key usage:\r\n * ```typescript\r\n * import { map } from \"@telperion/js-utils/object\";\r\n *\r\n * const obj = { x: 1, y: 2 };\r\n *\r\n * map(obj, (value, key) => `${key}_${value}`); // { x: \"x_1\", y: \"y_2\" }\r\n * ```\r\n * * * *\r\n * @param object Object to map\r\n * @param fn Callback function to transform each value, receives the value, key, and the entire object as arguments\r\n * @returns A new object with the same keys and transformed values\r\n */\r\nexport function map<T extends Object, R>(\r\n object: T,\r\n fn: (value: T[keyof T], key: keyof T, object: T) => R\r\n): { [K in keyof T]: R } {\r\n const result = {} as { [K in keyof T]: R };\r\n\r\n for (const key in object) {\r\n if (object.hasOwnProperty(key)) {\r\n result[key] = fn(object[key], key, object);\r\n }\r\n }\r\n\r\n return result;\r\n}\r\n"]}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const map_1 = require("@telperion/js-utils/object/map");
4
+ Object.map = map_1.map;
@@ -0,0 +1,26 @@
1
+ import { map } from '@telperion/js-utils/object/map';
2
+ declare global {
3
+ export interface ObjectConstructor {
4
+ /**
5
+ * #### Maps the values of an object using a callback function
6
+ *
7
+ * Similar to `Array.prototype.map`, but for objects. Iterates over own enumerable properties
8
+ * and returns a new object with the same keys and transformed values.
9
+ *
10
+ * * * *
11
+ * Example usage:
12
+ * ```typescript
13
+ * import "@telperion/js-utils/object/static/map";
14
+ *
15
+ * const obj = { a: 1, b: 2, c: 3 };
16
+ *
17
+ * Object.map(obj, value => value * 2); // { a: 2, b: 4, c: 6 }
18
+ * ```
19
+ * * * *
20
+ * @param object Object to map
21
+ * @param fn Callback function to transform each value, receives the value, key, and the entire object as arguments
22
+ * @returns A new object with the same keys and transformed values
23
+ */
24
+ map: typeof map;
25
+ }
26
+ }
@@ -0,0 +1,4 @@
1
+ import { map } from '@telperion/js-utils/object/map';
2
+ Object.map = map;
3
+
4
+ //# sourceMappingURL=map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/js-utils/src/object/static/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AA4BrD,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC","file":"map.js","sourcesContent":["import { map } from '@telperion/js-utils/object/map';\r\n\r\ndeclare global {\r\n export interface ObjectConstructor {\r\n /**\r\n * #### Maps the values of an object using a callback function\r\n *\r\n * Similar to `Array.prototype.map`, but for objects. Iterates over own enumerable properties\r\n * and returns a new object with the same keys and transformed values.\r\n *\r\n * * * *\r\n * Example usage:\r\n * ```typescript\r\n * import \"@telperion/js-utils/object/static/map\";\r\n *\r\n * const obj = { a: 1, b: 2, c: 3 };\r\n *\r\n * Object.map(obj, value => value * 2); // { a: 2, b: 4, c: 6 }\r\n * ```\r\n * * * *\r\n * @param object Object to map\r\n * @param fn Callback function to transform each value, receives the value, key, and the entire object as arguments\r\n * @returns A new object with the same keys and transformed values\r\n */\r\n map: typeof map;\r\n }\r\n}\r\n\r\nObject.map = map;\r\n"]}
package/open-promise.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ConstructorType } from '@thalesrc/extra-ts-types';
1
+ import type { ConstructorType } from '@telperion/extra-ts-types';
2
2
  type Executor<T> = ConstructorParameters<ConstructorType<typeof Promise<T>>>[0];
3
3
  type ExecutorParams<T> = Parameters<Executor<T>>;
4
4
  type Resolver<T> = ExecutorParams<T>[0];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/js-utils/src/open-promise.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,mCAAmC,CAAC;AAOzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,8DAA8D;AAC9D,MAAM,OAAO,WAAqB,SAAQ,OAAU;IAClD,MAAM,CAAC,eAAe,GAAkB,IAAI,CAAC;IAC7C,MAAM,CAAC,eAAe,GAAa,IAAI,CAAC;IAExC,SAAS,GAAG,KAAK,CAAC;IAClB,SAAS,GAAG,KAAK,CAAC;IAElB,SAAS,GAAgB,IAAI,CAAC;IAC9B,SAAS,GAAa,IAAI,CAAC;IAG3B;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,YAAY,WAAwB,IAAI;QACtC,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxB,WAAW,CAAC,eAAe,GAAG,OAAO,CAAC;YACtC,WAAW,CAAC,eAAe,GAAG,MAAM,CAAC;YAErC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,eAAe,CAAC;QAC7C,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,eAAe,CAAC;QAE7C,WAAW,CAAC,eAAe,GAAG,IAAI,CAAC;QACnC,WAAW,CAAC,eAAe,GAAG,IAAI,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,GAAG,IAA6B;QACtC,IAAI,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAElE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,GAAG,IAA0B;QAClC,IAAI,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAElE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAAmB;QACxB,OAAO;aACJ,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aAC/B,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC","file":"open-promise.js","sourcesContent":["import type { ConstructorType } from '@thalesrc/extra-ts-types';\nimport { noop } from '@telperion/js-utils/function/noop';\n\ntype Executor<T> = ConstructorParameters<ConstructorType<typeof Promise<T>>>[0];\ntype ExecutorParams<T> = Parameters<Executor<T>>;\ntype Resolver<T> = ExecutorParams<T>[0];\ntype Rejector = ExecutorParams<unknown>[1];\n\n/**\n * #### Open Promise\n * A promise constructor to resolve or reject from outside\n *\n * @deprecated Use the native `Promise.withResolvers()` instead, which provides the same functionality.\n *\n * * * *\n * Example with native alternative:\n * ```typescript\n * // Instead of:\n * // import { OpenPromise } from \"@telperion/js-utils\";\n * // const aPromiseWillBeResolvedLater = new OpenPromise();\n *\n * // Use:\n * const { promise, resolve, reject } = Promise.withResolvers();\n *\n * promise.then(val => console.log(val));\n * ...\n * ...\n *\n * resolve({x: 1});\n * ```\n *\n * Legacy Example:\n * ```typescript\n * import { OpenPromise } from \"@telperion/js-utils\";\n *\n * const aPromiseWillBeResolvedLater = new OpenPromise();\n *\n * aPromiseWillBeResolvedLater.then(val => console.log(val));\n * // aPromiseWillBeResolvedLater.finished // false\n * ...\n * ...\n *\n * aPromiseWillBeResolvedLater.resolve({x: 1});\n * // aPromiseWillBeResolvedLater.finished // true\n * ```\n * * * *\n * @template T typeof the value which is going to be resolved\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class OpenPromise<T = any> extends Promise<T> {\n static #resolverHolder: Resolver<any> = noop;\n static #rejectorHolder: Rejector = noop;\n\n #resolved = false;\n #rejected = false;\n\n #resolver: Resolver<T> = noop;\n #rejector: Rejector = noop;\n\n\n /**\n * Returns whether is the promise resolved\n */\n get resolved() {\n return this.#resolved;\n }\n\n /**\n * Returns whether is the promise rejected\n */\n get rejected() {\n return this.#rejected;\n }\n\n /**\n * Returns whether is the promise finished\n */\n get finished() {\n return this.#resolved || this.#rejected;\n }\n\n /**\n * Open Promise Constructor\n */\n constructor(executor: Executor<T> = noop) {\n super((resolve, reject) => {\n OpenPromise.#resolverHolder = resolve;\n OpenPromise.#rejectorHolder = reject;\n\n executor(resolve, reject);\n });\n\n this.#resolver = OpenPromise.#resolverHolder;\n this.#rejector = OpenPromise.#rejectorHolder;\n\n OpenPromise.#resolverHolder = noop;\n OpenPromise.#rejectorHolder = noop;\n }\n\n /**\n * Resolves promise\n * @param value Value to resolve the promise\n */\n resolve(...args: Parameters<Resolver<T>>): void {\n if (this.finished) throw new Error('Promise is already finished');\n\n this.#resolved = true;\n this.#resolver(...args);\n }\n\n /**\n * Rejects promise\n * @param reason Error to reject promise\n */\n reject(...args: Parameters<Rejector>): void {\n if (this.finished) throw new Error('Promise is already finished');\n\n this.#rejected = true;\n this.#rejector(...args);\n }\n\n /**\n * Binds a promise to the inner promise to resolve or reject with it\n * @param promise A promise to bind inner promise\n */\n bindTo(promise: Promise<T>): void {\n promise\n .then(e => { this.resolve(e); })\n .catch(e => this.reject(e));\n }\n}\n"]}
1
+ {"version":3,"sources":["../../../../../libs/js-utils/src/open-promise.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,mCAAmC,CAAC;AAOzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,8DAA8D;AAC9D,MAAM,OAAO,WAAqB,SAAQ,OAAU;IAClD,MAAM,CAAC,eAAe,GAAkB,IAAI,CAAC;IAC7C,MAAM,CAAC,eAAe,GAAa,IAAI,CAAC;IAExC,SAAS,GAAG,KAAK,CAAC;IAClB,SAAS,GAAG,KAAK,CAAC;IAElB,SAAS,GAAgB,IAAI,CAAC;IAC9B,SAAS,GAAa,IAAI,CAAC;IAG3B;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,YAAY,WAAwB,IAAI;QACtC,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxB,WAAW,CAAC,eAAe,GAAG,OAAO,CAAC;YACtC,WAAW,CAAC,eAAe,GAAG,MAAM,CAAC;YAErC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,eAAe,CAAC;QAC7C,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,eAAe,CAAC;QAE7C,WAAW,CAAC,eAAe,GAAG,IAAI,CAAC;QACnC,WAAW,CAAC,eAAe,GAAG,IAAI,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,GAAG,IAA6B;QACtC,IAAI,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAElE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,GAAG,IAA0B;QAClC,IAAI,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAElE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAAmB;QACxB,OAAO;aACJ,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aAC/B,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC","file":"open-promise.js","sourcesContent":["import type { ConstructorType } from '@telperion/extra-ts-types';\nimport { noop } from '@telperion/js-utils/function/noop';\n\ntype Executor<T> = ConstructorParameters<ConstructorType<typeof Promise<T>>>[0];\ntype ExecutorParams<T> = Parameters<Executor<T>>;\ntype Resolver<T> = ExecutorParams<T>[0];\ntype Rejector = ExecutorParams<unknown>[1];\n\n/**\n * #### Open Promise\n * A promise constructor to resolve or reject from outside\n *\n * @deprecated Use the native `Promise.withResolvers()` instead, which provides the same functionality.\n *\n * * * *\n * Example with native alternative:\n * ```typescript\n * // Instead of:\n * // import { OpenPromise } from \"@telperion/js-utils\";\n * // const aPromiseWillBeResolvedLater = new OpenPromise();\n *\n * // Use:\n * const { promise, resolve, reject } = Promise.withResolvers();\n *\n * promise.then(val => console.log(val));\n * ...\n * ...\n *\n * resolve({x: 1});\n * ```\n *\n * Legacy Example:\n * ```typescript\n * import { OpenPromise } from \"@telperion/js-utils\";\n *\n * const aPromiseWillBeResolvedLater = new OpenPromise();\n *\n * aPromiseWillBeResolvedLater.then(val => console.log(val));\n * // aPromiseWillBeResolvedLater.finished // false\n * ...\n * ...\n *\n * aPromiseWillBeResolvedLater.resolve({x: 1});\n * // aPromiseWillBeResolvedLater.finished // true\n * ```\n * * * *\n * @template T typeof the value which is going to be resolved\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class OpenPromise<T = any> extends Promise<T> {\n static #resolverHolder: Resolver<any> = noop;\n static #rejectorHolder: Rejector = noop;\n\n #resolved = false;\n #rejected = false;\n\n #resolver: Resolver<T> = noop;\n #rejector: Rejector = noop;\n\n\n /**\n * Returns whether is the promise resolved\n */\n get resolved() {\n return this.#resolved;\n }\n\n /**\n * Returns whether is the promise rejected\n */\n get rejected() {\n return this.#rejected;\n }\n\n /**\n * Returns whether is the promise finished\n */\n get finished() {\n return this.#resolved || this.#rejected;\n }\n\n /**\n * Open Promise Constructor\n */\n constructor(executor: Executor<T> = noop) {\n super((resolve, reject) => {\n OpenPromise.#resolverHolder = resolve;\n OpenPromise.#rejectorHolder = reject;\n\n executor(resolve, reject);\n });\n\n this.#resolver = OpenPromise.#resolverHolder;\n this.#rejector = OpenPromise.#rejectorHolder;\n\n OpenPromise.#resolverHolder = noop;\n OpenPromise.#rejectorHolder = noop;\n }\n\n /**\n * Resolves promise\n * @param value Value to resolve the promise\n */\n resolve(...args: Parameters<Resolver<T>>): void {\n if (this.finished) throw new Error('Promise is already finished');\n\n this.#resolved = true;\n this.#resolver(...args);\n }\n\n /**\n * Rejects promise\n * @param reason Error to reject promise\n */\n reject(...args: Parameters<Rejector>): void {\n if (this.finished) throw new Error('Promise is already finished');\n\n this.#rejected = true;\n this.#rejector(...args);\n }\n\n /**\n * Binds a promise to the inner promise to resolve or reject with it\n * @param promise A promise to bind inner promise\n */\n bindTo(promise: Promise<T>): void {\n promise\n .then(e => { this.resolve(e); })\n .catch(e => this.reject(e));\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telperion/js-utils",
3
- "version": "3.5.0",
3
+ "version": "3.6.3",
4
4
  "description": "Javascript utility functions for web development",
5
5
  "keywords": [
6
6
  "object",
@@ -35,7 +35,7 @@
35
35
  "directory": "libs/js-utils"
36
36
  },
37
37
  "dependencies": {
38
- "@thalesrc/extra-ts-types": "^1.1.0",
38
+ "@telperion/extra-ts-types": "^1.5.0",
39
39
  "tslib": "^2.3.0"
40
40
  },
41
41
  "type": "module",
@@ -446,6 +446,13 @@
446
446
  "require": "./object/static/deep-freeze.cjs",
447
447
  "types": "./object/static/deep-freeze.d.ts"
448
448
  },
449
+ "./object/static/map": {
450
+ "default": "./object/static/map.cjs",
451
+ "import": "./object/static/map.js",
452
+ "node": "./object/static/map.cjs",
453
+ "require": "./object/static/map.cjs",
454
+ "types": "./object/static/map.d.ts"
455
+ },
449
456
  "./object/clone": {
450
457
  "default": "./object/clone.cjs",
451
458
  "import": "./object/clone.js",
@@ -474,6 +481,13 @@
474
481
  "require": "./object/deep-freeze.cjs",
475
482
  "types": "./object/deep-freeze.d.ts"
476
483
  },
484
+ "./object/map": {
485
+ "default": "./object/map.cjs",
486
+ "import": "./object/map.js",
487
+ "node": "./object/map.cjs",
488
+ "require": "./object/map.cjs",
489
+ "types": "./object/map.d.ts"
490
+ },
477
491
  "./promise": {
478
492
  "default": "./promise/index.cjs",
479
493
  "import": "./promise/index.js",
@@ -1,4 +1,4 @@
1
- import type { Tail } from '@thalesrc/extra-ts-types';
1
+ import type { Tail } from '@telperion/extra-ts-types';
2
2
  import { limit } from '@telperion/js-utils/string/limit';
3
3
  type FuncType = typeof limit;
4
4
  type FuncArgs = Parameters<FuncType>;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../libs/js-utils/src/string/proto/limit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AA+BzD,MAAM,CAAC,SAAS,CAAC,KAAK,GAAG,UAAwB,GAAG,IAAe;IACjE,OAAO,KAAK,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;AAC9B,CAAC,CAAC","file":"limit.js","sourcesContent":["import type { Tail } from '@thalesrc/extra-ts-types';\n\nimport { limit } from '@telperion/js-utils/string/limit';\n\ntype FuncType = typeof limit;\ntype FuncArgs = Parameters<FuncType>;\ntype FuncReturn = ReturnType<FuncType>;\ntype ProtoArgs = Tail<FuncArgs>;\n\ndeclare global {\n export interface String {\n /**\n * #### Limit\n *\n * Limits the string to `n` character\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/string/proto/limit\";\n *\n * const str = 'foobarbaz';\n *\n * str.limit(3); // 'foo'\n * ```\n * * * *\n * @param count Count to limit string character size\n * @return Limited string\n */\n limit(...args: ProtoArgs): FuncReturn;\n }\n}\n\nString.prototype.limit = function (this: string, ...args: ProtoArgs): FuncReturn {\n return limit(this, ...args);\n};\n"]}
1
+ {"version":3,"sources":["../../../../../libs/js-utils/src/string/proto/limit.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AA+BzD,MAAM,CAAC,SAAS,CAAC,KAAK,GAAG,UAAwB,GAAG,IAAe;IACjE,OAAO,KAAK,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;AAC9B,CAAC,CAAC","file":"limit.js","sourcesContent":["import type { Tail } from '@telperion/extra-ts-types';\n\nimport { limit } from '@telperion/js-utils/string/limit';\n\ntype FuncType = typeof limit;\ntype FuncArgs = Parameters<FuncType>;\ntype FuncReturn = ReturnType<FuncType>;\ntype ProtoArgs = Tail<FuncArgs>;\n\ndeclare global {\n export interface String {\n /**\n * #### Limit\n *\n * Limits the string to `n` character\n *\n * * * *\n * Example:\n * ```typescript\n * import \"@telperion/js-utils/string/proto/limit\";\n *\n * const str = 'foobarbaz';\n *\n * str.limit(3); // 'foo'\n * ```\n * * * *\n * @param count Count to limit string character size\n * @return Limited string\n */\n limit(...args: ProtoArgs): FuncReturn;\n }\n}\n\nString.prototype.limit = function (this: string, ...args: ProtoArgs): FuncReturn {\n return limit(this, ...args);\n};\n"]}