@solid-primitives/utils
Advanced tools
Comparing version 6.0.0 to 6.1.0
{ | ||
"name": "@solid-primitives/utils", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "A bunch of reactive utility types and functions, for building primitives with Solid.js", | ||
@@ -24,14 +24,29 @@ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>", | ||
"type": "module", | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"main": "./dist/index/index.cjs", | ||
"module": "./dist/index/index.js", | ||
"types": "./dist/index/index.d.ts", | ||
"browser": {}, | ||
"exports": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
".": { | ||
"import": { | ||
"types": "./dist/index/index.d.ts", | ||
"default": "./dist/index/index.js" | ||
}, | ||
"require": "./dist/index/index.cjs" | ||
}, | ||
"require": "./dist/index.cjs" | ||
"./immutable": { | ||
"import": { | ||
"types": "./dist/immutable/index.d.ts", | ||
"default": "./dist/immutable/index.js" | ||
}, | ||
"require": "./dist/immutable/index.cjs" | ||
} | ||
}, | ||
"typesVersions": {}, | ||
"typesVersions": { | ||
"*": { | ||
"immutable": [ | ||
"./dist/immutable/index.d.ts" | ||
] | ||
} | ||
}, | ||
"keywords": [ | ||
@@ -38,0 +53,0 @@ "utilities", |
@@ -14,7 +14,89 @@ <p> | ||
# or | ||
pnpm add @solid-primitives/utils | ||
# or | ||
yarn add @solid-primitives/utils | ||
``` | ||
## Immutable helpers | ||
Functional programming helpers for making non-mutating changes to data. Keeping it immutable. Useful for updating signals. | ||
```ts | ||
import { pick } from "@solid-primitives/utils/immutable"; | ||
const original = { foo: 123, bar: "baz" }; | ||
const newObj = pick(original, "foo"); | ||
original; // { foo: 123, bar: "baz" } | ||
newObj; // { foo: 123 } | ||
``` | ||
Use it for changing signals: | ||
```ts | ||
import { push, update } from "@solid-primitives/utils/immutable"; | ||
const [list, setList] = createSignal([1, 2, 3]); | ||
setList(p => push(p, 4)); | ||
const [user, setUser] = createSignal({ | ||
name: "John", | ||
street: { name: "Kingston Cei", number: 24 }, | ||
}); | ||
setUser(p => update(p, "street", "number", 64)); | ||
``` | ||
## List of functions: | ||
### Copying | ||
- **`shallowArrayCopy`** - make shallow copy of an array | ||
- **`shallowObjectCopy`** - make shallow copy of an object | ||
- **`shallowCopy`** - make shallow copy of an array/object | ||
- **`withArrayCopy`** - apply mutations to the an array without changing the original | ||
- **`withObjectCopy`** - apply mutations to the an object without changing the original | ||
- **`withCopy`** - apply mutations to the an object/array without changing the original | ||
### Array | ||
- **`push`** - non-mutating `Array.prototype.push()` | ||
- **`drop`** - non-mutating function that drops n items from the array start | ||
- **`dropRight`** - non-mutating function that drops n items from the array end | ||
- **`filterOut`** - standalone `Array.prototype.filter()` that filters out passed item | ||
- **`filter`** - standalone `Array.prototype.filter()` | ||
- **`sort`** - non-mutating `Array.prototype.sort()` as a standalone function | ||
- **`sortBy`** - Sort an array by object key, or multiple keys | ||
- **`map`** - standalone `Array.prototype.map()` function | ||
- **`slice`** - standalone `Array.prototype.slice()` function | ||
- **`splice`** - non-mutating `Array.prototype.splice()` as a standalone function | ||
- **`fill`** - non-mutating `Array.prototype.fill()` as a standalone function | ||
- **`concat`** - Creates a new array concatenating array with any additional arrays and/or values. | ||
- **`remove`** - Remove item from array | ||
- **`removeItems`** - Remove multiple items from an array | ||
- **`flatten`** - Flattens a nested array into a one-level array | ||
- **`filterInstance`** - Flattens a nested array into a one-level array | ||
- **`filterOutInstance`** - Flattens a nested array into a one-level array | ||
### Object | ||
- **`omit`** - Create a new subset object without the provided keys | ||
- **`pick`** - Create a new subset object with only the provided keys | ||
- **`split`** - Split object into multiple subset objects. | ||
- **`merge`** - Merges multiple objects into a single one. | ||
### Object/Array | ||
- **`get`** - Get a single property value of an object by specifying a path to it. | ||
- **`update`** - Change single value in an object by key, or series of recursing keys. | ||
### Number | ||
- **`add`** - `a + b + c + ...` _(works for numbers or strings)_ | ||
- **`substract`** - `a - b - c - ...` | ||
- **`multiply`** - `a * b * c * ...` | ||
- **`divide`** - `a / b / c / ...` | ||
- **`power`** - `a ** b ** c ** ...` | ||
- **`clamp`** - clamp a number value between two other values | ||
## Changelog | ||
See [CHANGELOG.md](./CHANGELOG.md) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48554
11
1038
102
1