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.
npm install @solid-primitives/utils
# or
pnpm add @solid-primitives/utils
# or
yarn add @solid-primitives/utils
Functional programming helpers for making non-mutating changes to data. Keeping it immutable. Useful for updating signals.
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:
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));
-
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
-
push
- non-mutatingArray.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
- standaloneArray.prototype.filter()
that filters out passed item -
filter
- standaloneArray.prototype.filter()
-
sort
- non-mutatingArray.prototype.sort()
as a standalone function -
sortBy
- Sort an array by object key, or multiple keys -
map
- standaloneArray.prototype.map()
function -
slice
- standaloneArray.prototype.slice()
function -
splice
- non-mutatingArray.prototype.splice()
as a standalone function -
fill
- non-mutatingArray.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
-
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.
-
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.
-
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
See CHANGELOG.md