@solid-primitives/utils 2.2.1 → 3.0.0

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Solid Primitives Working Group
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Solid Primitives Working Group
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,46 +1,19 @@
1
- <p>
2
- <img width="100%" src="https://assets.solidjs.com/banner?type=Primitives&background=tiles&project=Utils" alt="Solid Primitives Utils">
3
- </p>
4
-
5
- # @solid-primitives/utils
6
-
7
- Solid Primitives Utilities is a support and helper package for a number of primitives in our library. Please free to augment or centralize useful utilities and methods in this package for sharing.
8
-
9
- ## Installation
10
-
11
- ```bash
12
- npm install @solid-primitives/utils
13
- # or
14
- yarn add @solid-primitives/utils
15
- ```
16
-
17
- ## Changelog
18
-
19
- <details>
20
- <summary><b>Expand Changelog</b></summary>
21
-
22
- 0.0.100
23
-
24
- First commit of the timer primitive.
25
-
26
- 0.0.250
27
-
28
- Republished version with better ESM support and build tooling.
29
-
30
- 0.0.260
31
-
32
- Added comments for util methods.
33
-
34
- 0.1.0
35
-
36
- Add `/fp` and `/setter` export entries. Add `destore` and `raceTimeout` util. More jsdoc.
37
-
38
- 0.1.2
39
-
40
- Updated to Solid 1.3
41
-
42
- 0.1.3
43
-
44
- Minor upgrades.
45
-
46
- </details>
1
+ <p>
2
+ <img width="100%" src="https://assets.solidjs.com/banner?type=Primitives&background=tiles&project=Utils" alt="Solid Primitives Utils">
3
+ </p>
4
+
5
+ # @solid-primitives/utils
6
+
7
+ Solid Primitives Utilities is a support and helper package for a number of primitives in our library. Please free to augment or centralize useful utilities and methods in this package for sharing.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @solid-primitives/utils
13
+ # or
14
+ yarn add @solid-primitives/utils
15
+ ```
16
+
17
+ ## Changelog
18
+
19
+ See [CHANGELOG.md](./CHANGELOG.md)
package/dist/index.cjs CHANGED
@@ -48,8 +48,6 @@ __export(src_exports, {
48
48
  noop: () => noop,
49
49
  ofClass: () => ofClass,
50
50
  onRootCleanup: () => onRootCleanup,
51
- promiseTimeout: () => promiseTimeout,
52
- raceTimeout: () => raceTimeout,
53
51
  warn: () => warn,
54
52
  withAccess: () => withAccess
55
53
  });
@@ -89,19 +87,12 @@ function accessWith(valueOrFn, ...args) {
89
87
  return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
90
88
  }
91
89
  function forEachEntry(object, iterator) {
92
- Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object));
90
+ Object.entries(object).forEach(
91
+ ([key, item], index, pairs) => iterator(key, item, index, pairs, object)
92
+ );
93
93
  }
94
94
  var entries = Object.entries;
95
95
  var keys = Object.keys;
96
- var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
97
- function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
98
- const promises = asArray(input);
99
- const race = Promise.race([...promises, promiseTimeout(ms, throwOnTimeout, reason)]);
100
- race.finally(() => {
101
- promises.forEach((p) => p && typeof p === "object" && typeof p.dispose === "function" && p.dispose());
102
- });
103
- return race;
104
- }
105
96
  var onRootCleanup = (fn) => (0, import_solid_js.getOwner)() ? (0, import_solid_js.onCleanup)(fn) : fn;
106
97
  var createCallbackStack = () => {
107
98
  let stack = [];
@@ -124,14 +115,17 @@ function createMicrotask(fn) {
124
115
  };
125
116
  }
126
117
  function createProxy(traps) {
127
- return new Proxy({}, {
128
- get: (_, k) => traps.get(k),
129
- set: (_, k, v) => {
130
- var _a;
131
- (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
132
- return false;
118
+ return new Proxy(
119
+ {},
120
+ {
121
+ get: (_, k) => traps.get(k),
122
+ set: (_, k, v) => {
123
+ var _a;
124
+ (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
125
+ return false;
126
+ }
133
127
  }
134
- });
128
+ );
135
129
  }
136
130
  var createTrigger = isDev ? () => (0, import_solid_js.createSignal)(void 0, { equals: false, name: "trigger" }) : () => (0, import_solid_js.createSignal)(void 0, { equals: false });
137
131
  function dirtyTriggerCache(key) {
@@ -270,8 +264,6 @@ function handleDiffArray(current, prev, handleAdded, handleRemoved) {
270
264
  noop,
271
265
  ofClass,
272
266
  onRootCleanup,
273
- promiseTimeout,
274
- raceTimeout,
275
267
  warn,
276
268
  withAccess
277
269
  });
package/dist/index.d.ts CHANGED
@@ -152,42 +152,6 @@ declare const entries: <T extends object>(obj: T) => [keyof T, T[keyof T]][];
152
152
  * Get keys of an object
153
153
  */
154
154
  declare const keys: <T extends object>(object: T) => (keyof T)[];
155
- /**
156
- * Creates a promise that resolves *(or rejects)* after given time.
157
- *
158
- * @param ms timeout duration in ms
159
- * @param throwOnTimeout promise will be rejected on timeout if set to `true`
160
- * @param reason rejection reason
161
- * @returns Promise<void>
162
- *
163
- * @example
164
- * ```ts
165
- * await promiseTimeout(1500) // will resolve void after timeout
166
- * await promiseTimeout(1500, true, 'rejection reason') // will reject 'rejection reason' after timout
167
- * ```
168
- */
169
- declare const promiseTimeout: (ms: number, throwOnTimeout?: boolean, reason?: string) => Promise<void>;
170
- /**
171
- * Combination of `Promise.race()` and `promiseTimeout`.
172
- *
173
- * @param promises single promise, or array of promises
174
- * @param ms timeout duration in ms
175
- * @param throwOnTimeout promise will be rejected on timeout if set to `true`
176
- * @param reason rejection reason
177
- * @returns a promise resulting in value of the first source promises to be resolved
178
- *
179
- * @example
180
- * ```ts
181
- * // single promise
182
- * await raceTimeout(new Promise(() => {...}), 3000)
183
- * // list of promises racing
184
- * await raceTimeout([new Promise(),new Promise()...], 3000)
185
- * // reject on timeout
186
- * await raceTimeout(new Promise(), 3000, true, 'rejection reason')
187
- * ```
188
- */
189
- declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout: true, reason?: string): T extends any[] ? Promise<Awaited<T[number]>> : Promise<Awaited<T>>;
190
- declare function raceTimeout<T>(promises: T, ms: number, throwOnTimeout?: boolean, reason?: string): T extends any[] ? Promise<Awaited<T[number]> | undefined> : Promise<Awaited<T> | undefined>;
191
155
  /**
192
156
  * Solid's `onCleanup` that is registered only if there is a root.
193
157
  */
@@ -291,4 +255,4 @@ declare function createStaticStore<T extends Readonly<AnyStatic>>(init: T): [acc
291
255
  */
292
256
  declare function handleDiffArray<T>(current: T[], prev: T[], handleAdded: (item: T) => void, handleRemoved: (item: T) => void): void;
293
257
 
294
- export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Definite, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Mutable, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, RequiredKeys, SetterValue, Simplify, StaticStoreSetter, Tail, Trigger, TriggerCache, Truthy, UnboxLazy, UnionToIntersection, Values, WeakTriggerCache, access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createMicrotask, createProxy, createStaticStore, createTrigger, createTriggerCache, createWeakTriggerCache, entries, forEachEntry, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, onRootCleanup, promiseTimeout, raceTimeout, warn, withAccess };
258
+ export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Definite, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, Mutable, NonIterable, Noop, OnAccessEffectFunction, Position, PrimitiveValue, RequiredKeys, SetterValue, Simplify, StaticStoreSetter, Tail, Trigger, TriggerCache, Truthy, UnboxLazy, UnionToIntersection, Values, WeakTriggerCache, access, accessArray, accessWith, arrayEquals, asAccessor, asArray, chain, clamp, compare, createCallbackStack, createMicrotask, createProxy, createStaticStore, createTrigger, createTriggerCache, createWeakTriggerCache, entries, forEachEntry, handleDiffArray, isClient, isDev, isObject, isProd, isServer, keys, noop, ofClass, onRootCleanup, warn, withAccess };
package/dist/index.js CHANGED
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  // src/index.ts
4
2
  import {
5
3
  getOwner,
@@ -44,19 +42,12 @@ function accessWith(valueOrFn, ...args) {
44
42
  return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
45
43
  }
46
44
  function forEachEntry(object, iterator) {
47
- Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object));
45
+ Object.entries(object).forEach(
46
+ ([key, item], index, pairs) => iterator(key, item, index, pairs, object)
47
+ );
48
48
  }
49
49
  var entries = Object.entries;
50
50
  var keys = Object.keys;
51
- var promiseTimeout = (ms, throwOnTimeout = false, reason = "Timeout") => new Promise((resolve, reject) => throwOnTimeout ? setTimeout(() => reject(reason), ms) : setTimeout(resolve, ms));
52
- function raceTimeout(input, ms, throwOnTimeout = false, reason = "Timeout") {
53
- const promises = asArray(input);
54
- const race = Promise.race([...promises, promiseTimeout(ms, throwOnTimeout, reason)]);
55
- race.finally(() => {
56
- promises.forEach((p) => p && typeof p === "object" && typeof p.dispose === "function" && p.dispose());
57
- });
58
- return race;
59
- }
60
51
  var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
61
52
  var createCallbackStack = () => {
62
53
  let stack = [];
@@ -79,14 +70,17 @@ function createMicrotask(fn) {
79
70
  };
80
71
  }
81
72
  function createProxy(traps) {
82
- return new Proxy({}, {
83
- get: (_, k) => traps.get(k),
84
- set: (_, k, v) => {
85
- var _a;
86
- (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
87
- return false;
73
+ return new Proxy(
74
+ {},
75
+ {
76
+ get: (_, k) => traps.get(k),
77
+ set: (_, k, v) => {
78
+ var _a;
79
+ (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
80
+ return false;
81
+ }
88
82
  }
89
- });
83
+ );
90
84
  }
91
85
  var createTrigger = isDev ? () => createSignal(void 0, { equals: false, name: "trigger" }) : () => createSignal(void 0, { equals: false });
92
86
  function dirtyTriggerCache(key) {
@@ -224,8 +218,6 @@ export {
224
218
  noop,
225
219
  ofClass,
226
220
  onRootCleanup,
227
- promiseTimeout,
228
- raceTimeout,
229
221
  warn,
230
222
  withAccess
231
223
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solid-primitives/utils",
3
- "version": "2.2.1",
3
+ "version": "3.0.0",
4
4
  "description": "A bunch of reactive utility types and functions, for building primitives with Solid.js",
5
5
  "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",
6
6
  "license": "MIT",
@@ -21,11 +21,6 @@
21
21
  "files": [
22
22
  "dist"
23
23
  ],
24
- "scripts": {
25
- "build": "tsup",
26
- "test": "uvu -r solid-register",
27
- "test:watch": "watchlist src test -- npm test"
28
- },
29
24
  "keywords": [
30
25
  "utilities",
31
26
  "reactivity",
@@ -37,11 +32,16 @@
37
32
  "prettier": "^2.7.1",
38
33
  "solid-register": "^0.2.5",
39
34
  "tslib": "^2.4.0",
40
- "tsup": "^6.1.2",
41
- "uvu": "^0.5.4",
35
+ "tsup": "^6.1.3",
36
+ "uvu": "^0.5.6",
42
37
  "watchlist": "^0.3.1"
43
38
  },
44
39
  "peerDependencies": {
45
40
  "solid-js": "^1.4.1"
41
+ },
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "test": "uvu -r solid-register",
45
+ "test:watch": "watchlist src test -- npm test"
46
46
  }
47
- }
47
+ }