You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@solid-primitives/destructure

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solid-primitives/destructure - npm Package Compare versions

Comparing version
0.1.9-beta.0
to
0.1.9
+0
-0
LICENSE

@@ -0,0 +0,0 @@ MIT License

+2
-2
{
"name": "@solid-primitives/destructure",
"version": "0.1.9-beta.0",
"version": "0.1.9",
"description": "Primitives for destructuring reactive objects – like props or stores – or signals of them into a separate accessors updated individually.",

@@ -47,3 +47,3 @@ "author": "Damian Tarnawski @thetarnav <gthetarnav@gmail.com>",

"dependencies": {
"@solid-primitives/utils": "^5.4.0-beta.0"
"@solid-primitives/utils": "^5.4.0"
},

@@ -50,0 +50,0 @@ "peerDependencies": {

@@ -0,0 +0,0 @@ <p>

'use strict';
var solidJs = require('solid-js');
var utils = require('@solid-primitives/utils');
// src/index.ts
var isReactiveObject = (value) => typeof value === "object" && value !== null;
function createProxyCache(obj, get) {
return new Proxy(
{},
{
get: (target, key) => {
if (key === Symbol.iterator || key === "length")
return Reflect.get(obj, key);
const saved = Reflect.get(target, key);
if (saved)
return saved;
const value = get(key);
Reflect.set(target, key, value);
return value;
},
set: () => false
}
);
}
function destructure(source, options) {
const config = options ?? {};
const memo = config.memo ?? typeof source === "function";
const getter = typeof source === "function" ? (key) => () => source()[key] : (key) => () => source[key];
const obj = utils.access(source);
if (config.lazy) {
const owner = solidJs.getOwner();
return createProxyCache(obj, (key) => {
const calc = getter(key);
if (config.deep && isReactiveObject(obj[key]))
return solidJs.runWithOwner(owner, () => destructure(calc, { ...config, memo }));
return memo ? solidJs.runWithOwner(owner, () => solidJs.createMemo(calc, void 0, options)) : calc;
});
}
const result = Array.isArray(obj) ? [] : {};
for (const [key, value] of Object.entries(obj)) {
const calc = getter(key);
if (config.deep && isReactiveObject(value))
result[key] = destructure(calc, { ...config, memo });
else
result[key] = memo ? solidJs.createMemo(calc, void 0, options) : calc;
}
return result;
}
exports.destructure = destructure;