@solid-primitives/utils 3.0.1 → 3.1.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,19 +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
- See [CHANGELOG.md](./CHANGELOG.md)
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
@@ -1,65 +1,16 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var solidJs = require('solid-js');
6
+ var web = require('solid-js/web');
19
7
 
20
8
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- access: () => access,
24
- accessArray: () => accessArray,
25
- accessWith: () => accessWith,
26
- arrayEquals: () => arrayEquals,
27
- asAccessor: () => asAccessor,
28
- asArray: () => asArray,
29
- chain: () => chain,
30
- clamp: () => clamp,
31
- compare: () => compare,
32
- createCallbackStack: () => createCallbackStack,
33
- createMicrotask: () => createMicrotask,
34
- createProxy: () => createProxy,
35
- createStaticStore: () => createStaticStore,
36
- createTrigger: () => createTrigger,
37
- createTriggerCache: () => createTriggerCache,
38
- createWeakTriggerCache: () => createWeakTriggerCache,
39
- entries: () => entries,
40
- forEachEntry: () => forEachEntry,
41
- handleDiffArray: () => handleDiffArray,
42
- isClient: () => isClient,
43
- isDev: () => isDev,
44
- isObject: () => isObject,
45
- isProd: () => isProd,
46
- isServer: () => isServer,
47
- keys: () => keys,
48
- noop: () => noop,
49
- ofClass: () => ofClass,
50
- onRootCleanup: () => onRootCleanup,
51
- warn: () => warn,
52
- withAccess: () => withAccess
53
- });
54
- module.exports = __toCommonJS(src_exports);
55
- var import_solid_js = require("solid-js");
56
- var import_web = require("solid-js/web");
57
9
  var noop = () => void 0;
58
- var isServer = import_web.isServer;
10
+ var isServer = web.isServer;
59
11
  var isClient = !isServer;
60
- var isDev = import_solid_js.DEV && isClient;
12
+ var isDev = solidJs.DEV && isClient;
61
13
  var isProd = !isDev;
62
- var warn = (...a) => isDev && console.warn(...a);
63
14
  var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
64
15
  function isObject(value) {
65
16
  return value !== null && (typeof value === "object" || typeof value === "function");
@@ -86,12 +37,9 @@ var asAccessor = (v) => typeof v === "function" ? v : () => v;
86
37
  function accessWith(valueOrFn, ...args) {
87
38
  return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
88
39
  }
89
- function forEachEntry(object, iterator) {
90
- Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object));
91
- }
92
40
  var entries = Object.entries;
93
41
  var keys = Object.keys;
94
- var onRootCleanup = (fn) => (0, import_solid_js.getOwner)() ? (0, import_solid_js.onCleanup)(fn) : fn;
42
+ var onRootCleanup = (fn) => solidJs.getOwner() ? solidJs.onCleanup(fn) : fn;
95
43
  var createCallbackStack = () => {
96
44
  let stack = [];
97
45
  const clear = () => stack = [];
@@ -113,16 +61,19 @@ function createMicrotask(fn) {
113
61
  };
114
62
  }
115
63
  function createProxy(traps) {
116
- return new Proxy({}, {
117
- get: (_, k) => traps.get(k),
118
- set: (_, k, v) => {
119
- var _a;
120
- (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
121
- return false;
64
+ return new Proxy(
65
+ {},
66
+ {
67
+ get: (_, k) => traps.get(k),
68
+ set: (_, k, v) => {
69
+ var _a;
70
+ (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
71
+ return false;
72
+ }
122
73
  }
123
- });
74
+ );
124
75
  }
125
- var createTrigger = isDev ? () => (0, import_solid_js.createSignal)(void 0, { equals: false, name: "trigger" }) : () => (0, import_solid_js.createSignal)(void 0, { equals: false });
76
+ var createTrigger = isDev ? () => solidJs.createSignal(void 0, { equals: false, name: "trigger" }) : () => solidJs.createSignal(void 0, { equals: false });
126
77
  function dirtyTriggerCache(key) {
127
78
  const trigger = this.get(key);
128
79
  if (trigger)
@@ -132,7 +83,7 @@ function dirtyAllTriggerCache() {
132
83
  this.forEach((s) => s[1]());
133
84
  }
134
85
  function trackTriggerCache(key) {
135
- if (!(0, import_solid_js.getListener)())
86
+ if (!solidJs.getListener())
136
87
  return;
137
88
  let trigger = this.get(key);
138
89
  if (!trigger) {
@@ -164,7 +115,7 @@ function createStaticStore(init) {
164
115
  const saved = cache.get(key);
165
116
  if (saved)
166
117
  return saved[0]();
167
- const signal = (0, import_solid_js.createSignal)(copy[key], {
118
+ const signal = solidJs.createSignal(copy[key], {
168
119
  name: typeof key === "string" ? key : void 0
169
120
  });
170
121
  cache.set(key, signal);
@@ -186,8 +137,8 @@ function createStaticStore(init) {
186
137
  }
187
138
  const setter = (a, b) => {
188
139
  if (isObject(a))
189
- (0, import_solid_js.untrack)(() => {
190
- (0, import_solid_js.batch)(() => {
140
+ solidJs.untrack(() => {
141
+ solidJs.batch(() => {
191
142
  for (const [key, value] of entries(accessWith(a, store)))
192
143
  setValue(key, () => value);
193
144
  });
@@ -229,36 +180,34 @@ function handleDiffArray(current, prev, handleAdded, handleRemoved) {
229
180
  handleAdded(currEl);
230
181
  }
231
182
  }
232
- // Annotate the CommonJS export names for ESM import in node:
233
- 0 && (module.exports = {
234
- access,
235
- accessArray,
236
- accessWith,
237
- arrayEquals,
238
- asAccessor,
239
- asArray,
240
- chain,
241
- clamp,
242
- compare,
243
- createCallbackStack,
244
- createMicrotask,
245
- createProxy,
246
- createStaticStore,
247
- createTrigger,
248
- createTriggerCache,
249
- createWeakTriggerCache,
250
- entries,
251
- forEachEntry,
252
- handleDiffArray,
253
- isClient,
254
- isDev,
255
- isObject,
256
- isProd,
257
- isServer,
258
- keys,
259
- noop,
260
- ofClass,
261
- onRootCleanup,
262
- warn,
263
- withAccess
264
- });
183
+ var forEachEntry = (obj, fn) => Object.entries(obj).forEach(([key, value]) => fn(key, value));
184
+
185
+ exports.access = access;
186
+ exports.accessArray = accessArray;
187
+ exports.accessWith = accessWith;
188
+ exports.arrayEquals = arrayEquals;
189
+ exports.asAccessor = asAccessor;
190
+ exports.asArray = asArray;
191
+ exports.chain = chain;
192
+ exports.clamp = clamp;
193
+ exports.compare = compare;
194
+ exports.createCallbackStack = createCallbackStack;
195
+ exports.createMicrotask = createMicrotask;
196
+ exports.createProxy = createProxy;
197
+ exports.createStaticStore = createStaticStore;
198
+ exports.createTrigger = createTrigger;
199
+ exports.createTriggerCache = createTriggerCache;
200
+ exports.createWeakTriggerCache = createWeakTriggerCache;
201
+ exports.entries = entries;
202
+ exports.forEachEntry = forEachEntry;
203
+ exports.handleDiffArray = handleDiffArray;
204
+ exports.isClient = isClient;
205
+ exports.isDev = isDev;
206
+ exports.isObject = isObject;
207
+ exports.isProd = isProd;
208
+ exports.isServer = isServer;
209
+ exports.keys = keys;
210
+ exports.noop = noop;
211
+ exports.ofClass = ofClass;
212
+ exports.onRootCleanup = onRootCleanup;
213
+ exports.withAccess = withAccess;
package/dist/index.d.ts CHANGED
@@ -48,14 +48,6 @@ declare type DeepPartialAny<T> = {
48
48
  declare type NonIterable<T> = T & {
49
49
  [Symbol.iterator]: never;
50
50
  };
51
- /** An opposite of `Partial`. Makes all the keys required. */
52
- declare type Definite<T> = {
53
- [K in keyof T]-?: T[K];
54
- };
55
- /** An opposite of `Readonly`. Makes all the params mutable. */
56
- declare type Mutable<T> = {
57
- -readonly [K in keyof T]: T[K];
58
- };
59
51
  /** Unwraps the type definition of an object, making it more readable */
60
52
  declare type Simplify<T> = T extends object ? {
61
53
  [K in keyof T]: T[K];
@@ -94,8 +86,6 @@ declare const isClient = true;
94
86
  declare const isDev = true;
95
87
  /** production environment */
96
88
  declare const isProd = false;
97
- /** `console.warn` only during development */
98
- declare const warn: typeof console.warn;
99
89
  /**
100
90
  * Check if the value is an instance of ___
101
91
  */
@@ -140,10 +130,6 @@ declare const withAccess: <T, A extends MaybeAccessor<T>, V = MaybeAccessorValue
140
130
  declare const asAccessor: <A extends unknown>(v: A) => Accessor<MaybeAccessorValue<A>>;
141
131
  /** If value is a function – call it with a given arguments – otherwise get the value as is */
142
132
  declare function accessWith<T>(valueOrFn: T, ...args: T extends AnyFunction ? Parameters<T> : never): T extends AnyFunction ? ReturnType<T> : T;
143
- /**
144
- * Iterate through object entries.
145
- */
146
- declare function forEachEntry<O extends AnyObject>(object: O, iterator: (key: keyof O, item: Values<O>, index: number, pairs: [keyof O, Values<O>][], object: O) => void): void;
147
133
  /**
148
134
  * Get entries of an object
149
135
  */
@@ -254,5 +240,6 @@ declare function createStaticStore<T extends Readonly<AnyStatic>>(init: T): [acc
254
240
  * @param handleRemoved called once for every removed from array
255
241
  */
256
242
  declare function handleDiffArray<T>(current: readonly T[], prev: readonly T[], handleAdded: (item: T) => void, handleRemoved: (item: T) => void): void;
243
+ declare const forEachEntry: <T>(obj: Record<string, T>, fn: (key: string, value: T) => void) => void;
257
244
 
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 };
245
+ export { AccessReturnTypes, AnyClass, AnyFunction, AnyObject, AnyStatic, DeepPartialAny, Directive, ExtractIfPossible, Falsy, FalsyValue, ItemsOf, ItemsOfMany, Many, MaybeAccessor, MaybeAccessorValue, Modify, ModifyDeep, 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, withAccess };
package/dist/index.js CHANGED
@@ -1,22 +1,12 @@
1
- "use strict";
1
+ import { DEV, getOwner, onCleanup, createSignal, getListener, untrack, batch } from 'solid-js';
2
+ import { isServer as isServer$1 } from 'solid-js/web';
2
3
 
3
4
  // src/index.ts
4
- import {
5
- getOwner,
6
- onCleanup,
7
- createSignal,
8
- DEV,
9
- untrack,
10
- batch,
11
- getListener
12
- } from "solid-js";
13
- import { isServer as _isServer } from "solid-js/web";
14
5
  var noop = () => void 0;
15
- var isServer = _isServer;
6
+ var isServer = isServer$1;
16
7
  var isClient = !isServer;
17
8
  var isDev = DEV && isClient;
18
9
  var isProd = !isDev;
19
- var warn = (...a) => isDev && console.warn(...a);
20
10
  var ofClass = (v, c) => v instanceof c || v && v.constructor === c;
21
11
  function isObject(value) {
22
12
  return value !== null && (typeof value === "object" || typeof value === "function");
@@ -43,9 +33,6 @@ var asAccessor = (v) => typeof v === "function" ? v : () => v;
43
33
  function accessWith(valueOrFn, ...args) {
44
34
  return typeof valueOrFn === "function" ? valueOrFn(...args) : valueOrFn;
45
35
  }
46
- function forEachEntry(object, iterator) {
47
- Object.entries(object).forEach(([key, item], index, pairs) => iterator(key, item, index, pairs, object));
48
- }
49
36
  var entries = Object.entries;
50
37
  var keys = Object.keys;
51
38
  var onRootCleanup = (fn) => getOwner() ? onCleanup(fn) : fn;
@@ -70,14 +57,17 @@ function createMicrotask(fn) {
70
57
  };
71
58
  }
72
59
  function createProxy(traps) {
73
- return new Proxy({}, {
74
- get: (_, k) => traps.get(k),
75
- set: (_, k, v) => {
76
- var _a;
77
- (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
78
- return false;
60
+ return new Proxy(
61
+ {},
62
+ {
63
+ get: (_, k) => traps.get(k),
64
+ set: (_, k, v) => {
65
+ var _a;
66
+ (_a = traps.set) == null ? void 0 : _a.call(traps, k, v);
67
+ return false;
68
+ }
79
69
  }
80
- });
70
+ );
81
71
  }
82
72
  var createTrigger = isDev ? () => createSignal(void 0, { equals: false, name: "trigger" }) : () => createSignal(void 0, { equals: false });
83
73
  function dirtyTriggerCache(key) {
@@ -186,35 +176,6 @@ function handleDiffArray(current, prev, handleAdded, handleRemoved) {
186
176
  handleAdded(currEl);
187
177
  }
188
178
  }
189
- export {
190
- access,
191
- accessArray,
192
- accessWith,
193
- arrayEquals,
194
- asAccessor,
195
- asArray,
196
- chain,
197
- clamp,
198
- compare,
199
- createCallbackStack,
200
- createMicrotask,
201
- createProxy,
202
- createStaticStore,
203
- createTrigger,
204
- createTriggerCache,
205
- createWeakTriggerCache,
206
- entries,
207
- forEachEntry,
208
- handleDiffArray,
209
- isClient,
210
- isDev,
211
- isObject,
212
- isProd,
213
- isServer,
214
- keys,
215
- noop,
216
- ofClass,
217
- onRootCleanup,
218
- warn,
219
- withAccess
220
- };
179
+ var forEachEntry = (obj, fn) => Object.entries(obj).forEach(([key, value]) => fn(key, value));
180
+
181
+ export { 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, withAccess };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solid-primitives/utils",
3
- "version": "3.0.1",
3
+ "version": "3.1.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",
@@ -14,17 +14,20 @@
14
14
  },
15
15
  "private": false,
16
16
  "sideEffects": false,
17
- "type": "module",
18
- "main": "dist/index.cjs",
19
- "module": "dist/index.js",
20
- "types": "dist/index.d.ts",
21
17
  "files": [
22
18
  "dist"
23
19
  ],
24
- "scripts": {
25
- "build": "tsup",
26
- "test": "uvu -r solid-register",
27
- "test:watch": "watchlist src test -- npm test"
20
+ "type": "module",
21
+ "main": "./dist/index.cjs",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ "browser": {
26
+ "import": "./dist/index.js",
27
+ "require": "./dist/index.cjs"
28
+ },
29
+ "import": "./dist/index.js",
30
+ "require": "./dist/index.cjs"
28
31
  },
29
32
  "keywords": [
30
33
  "utilities",
@@ -35,13 +38,18 @@
35
38
  "devDependencies": {
36
39
  "jsdom": "^20.0.0",
37
40
  "prettier": "^2.7.1",
38
- "solid-register": "^0.2.5",
41
+ "solid-js": "^1.5.0",
39
42
  "tslib": "^2.4.0",
40
- "tsup": "^6.2.1",
41
- "uvu": "^0.5.6",
42
- "watchlist": "^0.3.1"
43
+ "tsup": "^6.2.3",
44
+ "vitest": "^0.24.1"
43
45
  },
46
+ "browser": {},
44
47
  "peerDependencies": {
45
- "solid-js": "^1.4.1"
48
+ "solid-js": "^1.5.0"
49
+ },
50
+ "scripts": {
51
+ "build": "jiti ../../scripts/build.ts",
52
+ "test": "vitest -c ../../configs/vitest.config.ts",
53
+ "test:ssr": "pnpm run test --mode ssr"
46
54
  }
47
- }
55
+ }