@stryke/helpers 0.7.2 → 0.8.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/README.md CHANGED
@@ -49,20 +49,22 @@ other Stryke projects.
49
49
  <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
50
50
  ## Table of Contents
51
51
 
52
- - [Quick Features](#quick-features)
53
- - [Installing](#installing)
54
- - [Reduced Package Size](#reduced-package-size)
55
- - [Development](#development)
56
- - [Building](#building)
57
- - [Running unit tests](#running-unit-tests)
58
- - [Linting](#linting)
59
- - [Storm Workspaces](#storm-workspaces)
60
- - [Roadmap](#roadmap)
61
- - [Support](#support)
62
- - [License](#license)
63
- - [Changelog](#changelog)
64
- - [Contributing](#contributing)
65
- - [Contributors](#contributors)
52
+ - [Stryke - Helper Functions](#stryke---helper-functions)
53
+ - [Table of Contents](#table-of-contents)
54
+ - [Quick Features](#quick-features)
55
+ - [Installing](#installing)
56
+ - [Reduced Package Size](#reduced-package-size)
57
+ - [Development](#development)
58
+ - [Building](#building)
59
+ - [Running unit tests](#running-unit-tests)
60
+ - [Linting](#linting)
61
+ - [Storm Workspaces](#storm-workspaces)
62
+ - [Roadmap](#roadmap)
63
+ - [Support](#support)
64
+ - [License](#license)
65
+ - [Changelog](#changelog)
66
+ - [Contributing](#contributing)
67
+ - [Contributors](#contributors)
66
68
 
67
69
  <!-- END doctoc -->
68
70
 
@@ -89,6 +91,8 @@ The following modules are available in this package:
89
91
  - **match-sorter**: Provides a function to sort an array based on a search
90
92
  query.
91
93
  - **noop**: Provides a no-operation function.
94
+ - **once**: Provides a function that executes another function only once.
95
+ - **memoize**: Provides a function that memoizes the result of another function.
92
96
  - **remove-accents**: Provides a function to remove accents from a string.
93
97
  - **remove-empty-items**: Provides a function to remove empty items from an
94
98
  array.
package/dist/debounce.mjs CHANGED
@@ -1 +1 @@
1
- export function debounce(o,u,{signal:t}={}){let e=null;const n=(...r)=>{e!==null&&clearTimeout(e),!t?.aborted&&(e=setTimeout(()=>{o(...r),e=null},u))},l=()=>{n.cancel()};return n.cancel=()=>{e!==null&&(clearTimeout(e),e=null)},t?.addEventListener("abort",l,{once:!0}),n}
1
+ export function debounce(o,u,{signal:t}={}){let e=null;const n=((...r)=>{e!==null&&clearTimeout(e),!t?.aborted&&(e=setTimeout(()=>{o(...r),e=null},u))}),l=()=>{n.cancel()};return n.cancel=()=>{e!==null&&(clearTimeout(e),e=null)},t?.addEventListener("abort",l,{once:!0}),n}
package/dist/index.cjs CHANGED
@@ -146,6 +146,17 @@ Object.keys(_matchSorter).forEach(function (key) {
146
146
  }
147
147
  });
148
148
  });
149
+ var _memoize = require("./memoize.cjs");
150
+ Object.keys(_memoize).forEach(function (key) {
151
+ if (key === "default" || key === "__esModule") return;
152
+ if (key in exports && exports[key] === _memoize[key]) return;
153
+ Object.defineProperty(exports, key, {
154
+ enumerable: true,
155
+ get: function () {
156
+ return _memoize[key];
157
+ }
158
+ });
159
+ });
149
160
  var _mutex = require("./mutex.cjs");
150
161
  Object.keys(_mutex).forEach(function (key) {
151
162
  if (key === "default" || key === "__esModule") return;
@@ -179,6 +190,17 @@ Object.keys(_omit).forEach(function (key) {
179
190
  }
180
191
  });
181
192
  });
193
+ var _once = require("./once.cjs");
194
+ Object.keys(_once).forEach(function (key) {
195
+ if (key === "default" || key === "__esModule") return;
196
+ if (key in exports && exports[key] === _once[key]) return;
197
+ Object.defineProperty(exports, key, {
198
+ enumerable: true,
199
+ get: function () {
200
+ return _once[key];
201
+ }
202
+ });
203
+ });
182
204
  var _pick = require("./pick.cjs");
183
205
  Object.keys(_pick).forEach(function (key) {
184
206
  if (key === "default" || key === "__esModule") return;
package/dist/index.d.ts CHANGED
@@ -11,9 +11,11 @@ export * from "./get-unique";
11
11
  export * from "./identity";
12
12
  export * from "./is-equal";
13
13
  export * from "./match-sorter";
14
+ export * from "./memoize";
14
15
  export * from "./mutex";
15
16
  export * from "./noop";
16
17
  export * from "./omit";
18
+ export * from "./once";
17
19
  export * from "./pick";
18
20
  export * from "./remove-accents";
19
21
  export * from "./remove-empty-items";
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export*from"./arg-identity";export*from"./debounce";export*from"./deep-clone";export*from"./deep-merge";export*from"./delay";export*from"./filter-empty";export*from"./flatten-object";export*from"./get-field";export*from"./get-ordered-by";export*from"./get-unique";export*from"./identity";export*from"./is-equal";export*from"./match-sorter";export*from"./mutex";export*from"./noop";export*from"./omit";export*from"./pick";export*from"./remove-accents";export*from"./remove-empty-items";export*from"./semaphore";export*from"./set-field";export*from"./throttle";export*from"./timeout";export*from"./to-deep-key";export*from"./to-path";export*from"./unflatten-object";export*from"./union";export*from"./with-timeout";
1
+ export*from"./arg-identity";export*from"./debounce";export*from"./deep-clone";export*from"./deep-merge";export*from"./delay";export*from"./filter-empty";export*from"./flatten-object";export*from"./get-field";export*from"./get-ordered-by";export*from"./get-unique";export*from"./identity";export*from"./is-equal";export*from"./match-sorter";export*from"./memoize";export*from"./mutex";export*from"./noop";export*from"./omit";export*from"./once";export*from"./pick";export*from"./remove-accents";export*from"./remove-empty-items";export*from"./semaphore";export*from"./set-field";export*from"./throttle";export*from"./timeout";export*from"./to-deep-key";export*from"./to-path";export*from"./unflatten-object";export*from"./union";export*from"./with-timeout";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.memoizeOnId = void 0;
7
+ const memoizeOnId = e => {
8
+ const n = Object.prototype.hasOwnProperty,
9
+ t = {};
10
+ return r => n.call(t, r) ? t[r] : t[r] = e(r);
11
+ };
12
+ exports.memoizeOnId = memoizeOnId;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Memoizes a function based on its string identifier.
3
+ *
4
+ * @param fn - The function to memoize.
5
+ * @returns A memoized version of the input function.
6
+ */
7
+ export declare const memoizeOnId: <T>(fn: (id: string) => T) => (id: string) => T;
@@ -0,0 +1 @@
1
+ export const memoizeOnId=e=>{const n=Object.prototype.hasOwnProperty,t={};return r=>n.call(t,r)?t[r]:t[r]=e(r)};
package/dist/once.cjs ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.once = once;
7
+ exports.safeFunctionCast = safeFunctionCast;
8
+ function safeFunctionCast(n) {
9
+ return n;
10
+ }
11
+ function once(n) {
12
+ let e,
13
+ t = !1;
14
+ return function (...u) {
15
+ return t || (e = n.apply(this, u), t = !0), e;
16
+ };
17
+ }
package/dist/once.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /** silence "error TS2322" but practically this is safer and more convenient than resorting to `any` in a random place */
2
+ export declare function safeFunctionCast<TFunc extends (...args: any[]) => any>(fn: (...args: Parameters<TFunc>) => ReturnType<TFunc>): TFunc;
3
+ /**
4
+ * Executes a function only once.
5
+ *
6
+ * @param fn - The function to be executed only once.
7
+ * @returns A function that, when called, will execute the original function only once.
8
+ */
9
+ export declare function once<TFunc extends (...args: any[]) => any>(fn: TFunc): TFunc;
package/dist/once.mjs ADDED
@@ -0,0 +1 @@
1
+ export function safeFunctionCast(n){return n}export function once(n){let e,t=!1;return function(...u){return t||(e=n.apply(this,u),t=!0),e}}
package/dist/throttle.mjs CHANGED
@@ -1 +1 @@
1
- export function throttle(e,o){let t;return(...l)=>{const n=Date.now();(t==null||n-t>=o)&&(t=n,e(...l))}}
1
+ export function throttle(e,o){let t;return((...l)=>{const n=Date.now();(t==null||n-t>=o)&&(t=n,e(...l))})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/helpers",
3
- "version": "0.7.2",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "description": "A package containing miscellaneous helper functions that are used across many different Storm Software projects.",
6
6
  "repository": {
@@ -11,9 +11,9 @@
11
11
  "private": false,
12
12
  "publishConfig": { "access": "public" },
13
13
  "dependencies": {
14
- "@stryke/convert": "^0.3.1",
15
- "@stryke/type-checks": "^0.3.8",
16
- "@stryke/types": "^0.8.8"
14
+ "@stryke/convert": "^0.6.0",
15
+ "@stryke/type-checks": "^0.3.9",
16
+ "@stryke/types": "^0.9.0"
17
17
  },
18
18
  "devDependencies": {},
19
19
  "sideEffects": false,
@@ -212,6 +212,11 @@
212
212
  "require": { "types": "./dist/pick.d.ts", "default": "./dist/pick.cjs" },
213
213
  "default": { "types": "./dist/pick.d.ts", "default": "./dist/pick.mjs" }
214
214
  },
215
+ "./once": {
216
+ "import": { "types": "./dist/once.d.ts", "default": "./dist/once.mjs" },
217
+ "require": { "types": "./dist/once.d.ts", "default": "./dist/once.cjs" },
218
+ "default": { "types": "./dist/once.d.ts", "default": "./dist/once.mjs" }
219
+ },
215
220
  "./omit": {
216
221
  "import": { "types": "./dist/omit.d.ts", "default": "./dist/omit.mjs" },
217
222
  "require": { "types": "./dist/omit.d.ts", "default": "./dist/omit.cjs" },
@@ -230,6 +235,20 @@
230
235
  },
231
236
  "default": { "types": "./dist/mutex.d.ts", "default": "./dist/mutex.mjs" }
232
237
  },
238
+ "./memoize": {
239
+ "import": {
240
+ "types": "./dist/memoize.d.ts",
241
+ "default": "./dist/memoize.mjs"
242
+ },
243
+ "require": {
244
+ "types": "./dist/memoize.d.ts",
245
+ "default": "./dist/memoize.cjs"
246
+ },
247
+ "default": {
248
+ "types": "./dist/memoize.d.ts",
249
+ "default": "./dist/memoize.mjs"
250
+ }
251
+ },
233
252
  "./match-sorter": {
234
253
  "import": {
235
254
  "types": "./dist/match-sorter.d.ts",
@@ -441,5 +460,5 @@
441
460
  "main": "./dist/index.cjs",
442
461
  "module": "./dist/index.mjs",
443
462
  "types": "./dist/index.d.ts",
444
- "gitHead": "7aac00edc2ff843fb756d37cdcaf482e2da4472b"
463
+ "gitHead": "7def42c7a092ae198b8a753e78496b3f49c64b76"
445
464
  }