
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
📦 NODE.JS - Create a multi-key object with the same/multiple values by passing just a string or array.
📦 NODE.JS - Create a multi-key object with the same/multiple values by passing just a string or array.
npm install expand-obj --save
or
yarn add expand-obj
commonjs
const expand = require('expand-obj');
or ES6 (export default)
import expand from 'expand-obj';
or ES6 (named export)
import { expand } from 'expand-obj';
Basically you just need to enter an object that contains one or more keys separated by some character or an array as a key.
const expand = require('expand-obj');
const foo = expand({
['a, b, c']: 123,
});
console.log(foo); // result: { a: 123, b: 123, c: 123 }
With options
const foo = expand(
{
['a, b, c']: [1, 2, 3],
},
{ splitValues: true }
);
console.log(foo); // result: { a: 1, b: 2, c: 3 }
Resolve functions
const foo = await expand({
['a, b, c']: async (val: string) => `test=${val}`,
});
console.log(foo); // result: { a: `test=a`, b: `test=b`, c: `test=c` }
const expand = require('expand-obj');
const styled = await expand({
'h1, h2, p, span': { fontSize: '2rem', fontWeight: 'bold' },
'roundedBorder, cardBorder, buttonBorder': { borderRadius: '7px' },
'span': { fontStyle: 'italic' },
});
<span style={styled.span}>Font Size 2rem and Italic</span>
<SomeReactComponent style={{...styled.h1, ...styled.roundedBorder}} />
By default these are the configuration options
export type ExpandOptions = {
separator?: string, // default: ','
splitValues?: boolean, // default: false
deleteRawKey?: boolean, // default: true
trimSpaces?: boolean, // default: true
tryJoinRepeatedKeys?: boolean, // default: true
resolveFuncs?: boolean, // default: true
useSubkeyAsParams?: boolean, // default: true
};
define the subkey separator
const options = {
separator: '|',
};
const obj = await expand(
{
'a, b, c': 123,
},
options
);
console.log(obj); // result: { a: 123, b: 123, c: 123 }
when true, spreads the values if the property value is of type array
const options = {
splitValues: true,
};
const obj = await expand(
{
'a, b, c': 123,
'h, i, j': [4, 5, 6],
'x, y, z': [7, 8],
},
options
);
console.log(obj); // result: { a: 123, b: 123, c: 123, h: 4, i: 5, j: 6, x: 7, y: 8, z: 8 }
// obs: note that the spread made uses the index of the
// current subkey in the property's key list
// and "z" repeats the last value in the array of values
when false, prevents the raw key from being removed from object entries
const options = {
deleteRawKey: false,
};
const obj = await expand(
{
'a, b, c': 123,
},
options
);
console.log(obj); // result: { 'a, b, c': 123, a: 123, b: 123, c: 123 }
when false, keep leading and trailing spaces
const options = {
trimSpaces: false,
};
const obj = await expand(
{
'a, b, c': 123,
},
options
);
console.log(obj); // result: { a: 123, ' b': 123, ' c': 123 }
when true, if the input object has a key that is equal to a subkey and both values are an array or an object the two values will be merged
const options = {
tryJoinRepeatedKeys: false,
};
const obj = await expand(
{
'a, b, c': 123,
'foo, bar': [4, 5, 6],
foo: [789],
},
options
);
console.log(obj); // result: { a: 123, b: 123, c: 123, foo: [4, 5, 6, 789], bar: [4, 5, 6] }
FAQs
📦 NODE.JS - Create a multi-key object with the same/multiple values by passing just a string or array.
The npm package expand-obj receives a total of 0 weekly downloads. As such, expand-obj popularity was classified as not popular.
We found that expand-obj demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.