Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
shape-collection
Advanced tools
Utility for manipulating data in arrays of objects.
Run npm install shape-collection --save
import { shape } from 'shape-collection';
const arr = [{
users: ['aa', 'bb']
}, {
users: ['kk', 'zz', 'xyz']
}];
const users = shape(arr).reduceTo('users').fetch();
// users contains:
// ["aa", "bb", "kk", "zz", "xyz"]
const arr = [{ id: 'abc' }, { id: 'xyz' }]
shape(arr).filterByProp('id', 'abc').fetchIndex(0);
Function
. Returns the shaped collection.
Function
. Returns item at a specific index from the shaped collection.
Function
. Filters the collection by unique value:
import { shape } from 'shape-collection';
const arr = [{
id: 1,
users: ['aa', 'bb']
}, {
id: 2,
users: ['kk', 'zz', 'xyz']
}];
const user = shape(arr).filterByUnique('id', 1).fetchIndex(0);
// user contains:
// {id: 1, users: ['aa', 'bb']}
Function
. Filter and extract duplicate items from collection:
const arr = [{
id: 1,
type: 'b',
users: ['aa', 'bb']
}, {
id: 1,
type: 'a',
users: ['kk', 'zz', 'xyz']
}, , {
id: 3,
type: 'a',
users: ['kk', 'zz', 'xyz']
}];
const duplicates = shape(arr).filterByDuplicate('id').fetch();
// duplicates contains:
// [{ id: 1, type: 'b' ... }, { id: 1, type: 'a' ... }]
Function
. Filter collection by property value:
const arr = [{
id: 1,
type: 'b',
users: ['aa', 'bb']
}, {
id: 1,
type: 'a',
users: ['kk', 'zz', 'xyz']
}, , {
id: 3,
type: 'a',
users: ['kk', 'zz', 'xyz']
}];
const item = shape(arr).filterByProp('id', 3).fetch();
// item contains:
// [{ id: 3, type: 'a' ... }]
Function
. Sort collection by key, type and direction:
const arr = [{
id: 1,
type: 'b',
users: ['aa', 'bb']
}, {
id: 1,
type: 'a',
users: ['kk', 'zz', 'xyz']
}, , {
id: 3,
type: 'a',
users: ['kk', 'zz', 'xyz']
}];
const sortedById = shape(arr).sortBy({
key: 'id', // string, **REQUIRED**
type: 'number', // string, default = 'string'
direction = 'desc' // string, defaul = 'asc'
}).fetch();
// sortedById contains:
// [{ id: 3 ... }, { id: 1 ... }, { id: 1 ... }]
Available options for sortBy
are:
type
number
string
date
- new Date() fieldscombo
- combination of two string fieldsdirection
asc
desc
Function
. Reduce collection to another collection:
const arr = [{
id: 1,
type: 'b',
users: ['aa', 'bb']
}, {
id: 2,
type: 'a',
users: ['kk', 'zz', 'xyz']
}, {
id: 3,
type: 'a',
users: ['ff', 'hhh', 'eeee', 'kk']
}];
const users = shape(arr).reduceTo('users').fetch();
// users contains:
// ["aa", "bb", "kk", "zz", "xyz", "ff", "hhh", "eeee", "kk"]
FAQs
Utility for manipulating data in arrays of objects
The npm package shape-collection receives a total of 0 weekly downloads. As such, shape-collection popularity was classified as not popular.
We found that shape-collection 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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.