Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@roots/container

Package Overview
Dependencies
Maintainers
5
Versions
907
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@roots/container - npm Package Compare versions

Comparing version 2.2.0 to 3.0.0-alpha.0

84

lib/cjs/Container/index.js

@@ -19,19 +19,5 @@ "use strict";

/**
* ## container.getStore
*
* Get the store contents
*
* ### Usage
*
* ```js
* container.getStore()
* ```
*/
getStore() {
return this.repository;
}
/**
* ## container.all
*
* Does the same thing as container.getStore
* Does the same thing as container.all
*

@@ -45,3 +31,3 @@ * ### Usage

all() {
return this.getStore();
return this.repository;
}

@@ -77,3 +63,3 @@ /**

mergeStore(values) {
this.setStore(Object.assign(Object.assign({}, this.getStore()), values));
this.setStore(Object.assign(Object.assign({}, this.all()), values));
return this;

@@ -95,3 +81,3 @@ }

transformStore(transformFn) {
return transformFn(this.getStore());
return transformFn(this.all());
}

@@ -169,3 +155,3 @@ /**

getEntries(key) {
return Object.entries(key ? this.get(key) : this.getStore());
return Object.entries(key ? this.get(key) : this.all());
}

@@ -228,2 +214,9 @@ /**

}
findKey(...searchItem) {
return lodash_1.default.findKey(this.repository, ...searchItem);
}
findKeyOf(key, ...searchItem) {
const parseInner = v => (!lodash_1.default.isArray(v) ? Object.entries(v) : v).reduce((a, [k, v]) => (Object.assign(Object.assign({}, a), { [k]: v })), {});
return lodash_1.default.findKey(parseInner(this.get(key)), ...searchItem);
}
/**

@@ -266,3 +259,3 @@ * ## container.mutateEntries

getValues(key) {
return Object.values(key ? this.get(key) : this.getStore());
return Object.values(key ? this.get(key) : this.all());
}

@@ -289,3 +282,3 @@ /**

getKeys(key) {
return Object.keys(key ? this.get(key) : this.getStore());
return Object.keys(key ? this.get(key) : this.all());
}

@@ -337,2 +330,26 @@ /**

/**
* ## container.push
*
* Push an item or entry onto the container
*
* ```js
* container.unique('containerKey') // unique values of containerKey
* ```
*
* ```js
* container.unique() // unique values of container
* ```
*/
push(value, key) {
if (key) {
this.mutate(key, k => k.push(value));
return this;
}
if (!lodash_1.default.isArray(this.all())) {
throw new Error('Type mismatch: Attempted to push onto object container as if it were an array.');
}
this.setStore(this.all().push(value));
return this;
}
/**
* ## container.transform

@@ -442,3 +459,3 @@ *

isTrue(key) {
return this.is(key, true);
return this.is(key, true || 'true');
}

@@ -460,3 +477,3 @@ /**

enabled(key) {
return this.isTrue(key);
return this.is(key, true || 'true');
}

@@ -476,3 +493,3 @@ /**

isFalse(key) {
return this.is(key, false);
return this.is(key, false || 'false');
}

@@ -494,3 +511,3 @@ /**

disabled(key) {
return this.isFalse(key);
return this.isFalse(key || 'false');
}

@@ -541,3 +558,3 @@ /**

isIndexed(key) {
const value = key ? this.get(key) : this.getStore();
const value = key ? this.get(key) : this.all();
return (this.has(key) &&

@@ -697,4 +714,19 @@ lodash_1.default.isObject(value) &&

}
/**
* ## container.isFunction
*
* Return true if object is a function
*
* ### Usage
*
* ```js
* container.isFunction('my-key')
* // True if object associated with 'my-key' is a fn.
* ````
*/
isFunction(key) {
return lodash_1.default.isFunction(this.get(key));
}
}
exports.Container = Container;
//# sourceMappingURL=index.js.map

@@ -13,19 +13,5 @@ import _ from 'lodash';

/**
* ## container.getStore
*
* Get the store contents
*
* ### Usage
*
* ```js
* container.getStore()
* ```
*/
getStore() {
return this.repository;
}
/**
* ## container.all
*
* Does the same thing as container.getStore
* Does the same thing as container.all
*

@@ -39,3 +25,3 @@ * ### Usage

all() {
return this.getStore();
return this.repository;
}

@@ -71,3 +57,3 @@ /**

mergeStore(values) {
this.setStore(Object.assign(Object.assign({}, this.getStore()), values));
this.setStore(Object.assign(Object.assign({}, this.all()), values));
return this;

@@ -89,3 +75,3 @@ }

transformStore(transformFn) {
return transformFn(this.getStore());
return transformFn(this.all());
}

@@ -163,3 +149,3 @@ /**

getEntries(key) {
return Object.entries(key ? this.get(key) : this.getStore());
return Object.entries(key ? this.get(key) : this.all());
}

@@ -222,2 +208,9 @@ /**

}
findKey(...searchItem) {
return _.findKey(this.repository, ...searchItem);
}
findKeyOf(key, ...searchItem) {
const parseInner = v => (!_.isArray(v) ? Object.entries(v) : v).reduce((a, [k, v]) => (Object.assign(Object.assign({}, a), { [k]: v })), {});
return _.findKey(parseInner(this.get(key)), ...searchItem);
}
/**

@@ -260,3 +253,3 @@ * ## container.mutateEntries

getValues(key) {
return Object.values(key ? this.get(key) : this.getStore());
return Object.values(key ? this.get(key) : this.all());
}

@@ -283,3 +276,3 @@ /**

getKeys(key) {
return Object.keys(key ? this.get(key) : this.getStore());
return Object.keys(key ? this.get(key) : this.all());
}

@@ -331,2 +324,26 @@ /**

/**
* ## container.push
*
* Push an item or entry onto the container
*
* ```js
* container.unique('containerKey') // unique values of containerKey
* ```
*
* ```js
* container.unique() // unique values of container
* ```
*/
push(value, key) {
if (key) {
this.mutate(key, k => k.push(value));
return this;
}
if (!_.isArray(this.all())) {
throw new Error('Type mismatch: Attempted to push onto object container as if it were an array.');
}
this.setStore(this.all().push(value));
return this;
}
/**
* ## container.transform

@@ -436,3 +453,3 @@ *

isTrue(key) {
return this.is(key, true);
return this.is(key, true || 'true');
}

@@ -454,3 +471,3 @@ /**

enabled(key) {
return this.isTrue(key);
return this.is(key, true || 'true');
}

@@ -470,3 +487,3 @@ /**

isFalse(key) {
return this.is(key, false);
return this.is(key, false || 'false');
}

@@ -488,3 +505,3 @@ /**

disabled(key) {
return this.isFalse(key);
return this.isFalse(key || 'false');
}

@@ -535,3 +552,3 @@ /**

isIndexed(key) {
const value = key ? this.get(key) : this.getStore();
const value = key ? this.get(key) : this.all();
return (this.has(key) &&

@@ -691,3 +708,18 @@ _.isObject(value) &&

}
/**
* ## container.isFunction
*
* Return true if object is a function
*
* ### Usage
*
* ```js
* container.isFunction('my-key')
* // True if object associated with 'my-key' is a fn.
* ````
*/
isFunction(key) {
return _.isFunction(this.get(key));
}
}
//# sourceMappingURL=index.js.map
{
"name": "@roots/container",
"version": "2.2.0",
"version": "3.0.0-alpha.0",
"description": "Collections utility",

@@ -59,3 +59,3 @@ "homepage": "https://roots.io/bud",

},
"gitHead": "d24ea6900f9a196874d75155079909874976ac10"
"gitHead": "80a0d55354c6094b419f56f90e765187fb309fcf"
}
import _ from 'lodash'
import {ValueOf} from 'type-fest'
/**
* Container iem.
*/
export type Item<T = any> = T
/**
* Indexed container value store.
*/
export type Repository<I = any> = {
[key: string]: Item<I>
[key: string]: I
}

@@ -22,3 +18,3 @@

*/
public repository: Repository<I>
repository: any

@@ -28,3 +24,3 @@ /**

*/
constructor(repository: Repository) {
constructor(repository?: I) {
this.setStore(repository ?? {})

@@ -34,20 +30,5 @@ }

/**
* ## container.getStore
*
* Get the store contents
*
* ### Usage
*
* ```js
* container.getStore()
* ```
*/
public getStore(): Repository {
return this.repository
}
/**
* ## container.all
*
* Does the same thing as container.getStore
* Does the same thing as container.all
*

@@ -60,4 +41,4 @@ * ### Usage

*/
public all(): Repository {
return this.getStore()
public all() {
return this.repository
}

@@ -97,3 +78,3 @@

this.setStore({
...this.getStore(),
...this.all(),
...values,

@@ -119,3 +100,3 @@ })

public transformStore(transformFn: (value: any) => any): any {
return transformFn(this.getStore())
return transformFn(this.all())
}

@@ -134,5 +115,3 @@

*/
public mutateStore<T = any>(
mutationFn: (value?: T) => T,
): this {
public mutateStore(mutationFn: (value?: I) => I): this {
this.setStore(this.transformStore(mutationFn))

@@ -154,7 +133,7 @@

*/
public mutateStoreEntries<T = any>(
mutateFn: (key: string, value: T) => T,
public mutateStoreEntries(
mutateFn: (key: string, value: I) => I,
): this {
this.fromEntries(
this.getEntries().map(([key, value]: [string, T]) => [
this.getEntries().map(([key, value]: [string, I]) => [
key,

@@ -185,4 +164,4 @@ mutateFn(key, value),

*/
public get(key: string): any {
return _.get(this.repository, key)
public get<T = any>(key: any) {
return _.get(this.repository, key) as T
}

@@ -207,4 +186,8 @@

*/
public getEntries<T = any>(key?: string): [string, T][] {
return Object.entries(key ? this.get(key) : this.getStore())
public getEntries<T = any>(
key?: keyof T,
): [keyof T, ValueOf<T>][] {
return Object.entries(
key ? this.get(key as string) : this.all(),
) as [keyof T, ValueOf<T>][]
}

@@ -229,3 +212,3 @@

*/
public fromEntries<T = any>(entries: [string, T][]): this {
public fromEntries(entries: [string, any][]): this {
this.mergeStore(Object.fromEntries(entries))

@@ -247,7 +230,4 @@

*/
public each<T = any>(
key: string,
callFn: (key: string, value: T) => void,
): this {
this.getEntries(key).forEach(([key, value]: [string, T]) => [
public each(key: string, callFn: (key, value) => void): this {
this.getEntries(key).forEach(([key, value]) => [
key,

@@ -279,2 +259,19 @@ callFn(key, value),

public findKey(...searchItem: any): any {
return _.findKey(this.repository, ...searchItem)
}
public findKeyOf(key: string, ...searchItem: any[]): any {
const parseInner = v =>
(!_.isArray(v) ? Object.entries(v) : v).reduce(
(a, [k, v]) => ({
...a,
[k]: v,
}),
{},
)
return _.findKey(parseInner(this.get(key)), ...searchItem)
}
/**

@@ -291,8 +288,8 @@ * ## container.mutateEntries

*/
public mutateEntries<T = any>(
public mutateEntries(
key: string,
mutateFn: (key: string, value: T) => T,
mutateFn: (key: string, value: any) => any,
): this {
this.fromEntries(
this.getEntries(key).map(([key, value]: [string, T]) => [
this.getEntries(key).map(([key, value]: [string, any]) => [
key,

@@ -324,4 +321,4 @@ mutateFn(key, value),

*/
public getValues(key?: string): unknown[] {
return Object.values(key ? this.get(key) : this.getStore())
public getValues(key?: string): any[] {
return Object.values(key ? this.get(key) : this.all())
}

@@ -349,3 +346,3 @@

public getKeys(key?: string): string[] {
return Object.keys(key ? this.get(key) : this.getStore())
return Object.keys(key ? this.get(key) : this.all())
}

@@ -372,6 +369,9 @@

*/
public getMap<T = unknown>(key?: string): Map<string, T> {
public getMap(key?: string): Map<string, any> {
const reducer: [
(acc: Map<string, T>, curr: [string, T]) => Map<string, T>,
Map<string, T>,
(
acc: Map<string, any>,
curr: [string, any],
) => Map<string, any>,
Map<string, any>,
] = [

@@ -399,3 +399,3 @@ (map, [key, value]) => {

*/
public set<T = any>(key: string, value: T): this {
public set(key: string, value: any): this {
_.set(this.repository, key, value)

@@ -407,2 +407,32 @@

/**
* ## container.push
*
* Push an item or entry onto the container
*
* ```js
* container.unique('containerKey') // unique values of containerKey
* ```
*
* ```js
* container.unique() // unique values of container
* ```
*/
public push(value: any, key?: any) {
if (key) {
this.mutate(key, k => k.push(value))
return this
}
if (!_.isArray(this.all())) {
throw new Error(
'Type mismatch: Attempted to push onto object container as if it were an array.',
)
}
this.setStore(this.all().push(value))
return this
}
/**
* ## container.transform

@@ -420,6 +450,6 @@ *

*/
public transform<T = any>(
public transform(
key: string,
mutationFn: (value?: T) => T,
): T {
mutationFn: (value?: any) => any,
): any {
return mutationFn(this.get(key))

@@ -439,7 +469,7 @@ }

*/
public mutate<T = any>(
public mutate(
key: string,
mutationFn: (value?: T) => T,
mutationFn: (value?: any) => any,
): this {
this.set<T>(key, this.transform(key, mutationFn))
this.set(key, this.transform(key, mutationFn))

@@ -460,4 +490,4 @@ return this

*/
public merge<T = any>(key: string, value: T): this {
this.set<T>(key, _.merge(this.get(key), value))
public merge(key: string, value: any): this {
this.set(key, _.merge(this.get(key), value))

@@ -513,3 +543,3 @@ return this

*/
public is<T = any>(key: string, value: T): boolean {
public is(key: string, value: any): boolean {
return this.get(key) === value

@@ -531,3 +561,3 @@ }

public isTrue(key: string): boolean {
return this.is<boolean>(key, true)
return this.is(key, true || 'true')
}

@@ -550,3 +580,3 @@

public enabled(key: string): boolean {
return this.isTrue(key)
return this.is(key, true || 'true')
}

@@ -567,3 +597,3 @@

public isFalse(key: string): boolean {
return this.is<boolean>(key, false)
return this.is(key, false || 'false')
}

@@ -586,3 +616,3 @@

public disabled(key: string): boolean {
return this.isFalse(key)
return this.isFalse(key || 'false')
}

@@ -603,3 +633,3 @@

public enable(key: string): void {
this.set<boolean>(key, true)
this.set(key, true)
}

@@ -637,3 +667,3 @@

public isIndexed(key?: string): boolean {
const value = key ? this.get(key) : this.getStore()
const value = key ? this.get(key) : this.all()
return (

@@ -805,2 +835,18 @@ this.has(key) &&

}
/**
* ## container.isFunction
*
* Return true if object is a function
*
* ### Usage
*
* ```js
* container.isFunction('my-key')
* // True if object associated with 'my-key' is a fn.
* ````
*/
public isFunction(key: string): boolean {
return _.isFunction(this.get(key))
}
}

@@ -0,10 +1,7 @@

import { ValueOf } from 'type-fest';
/**
* Container iem.
*/
export declare type Item<T = any> = T;
/**
* Indexed container value store.
*/
export declare type Repository<I = any> = {
[key: string]: Item<I>;
[key: string]: I;
};

@@ -18,23 +15,11 @@ /**

*/
repository: Repository<I>;
repository: any;
/**
* Class constructor
*/
constructor(repository: Repository);
constructor(repository?: I);
/**
* ## container.getStore
*
* Get the store contents
*
* ### Usage
*
* ```js
* container.getStore()
* ```
*/
getStore(): Repository;
/**
* ## container.all
*
* Does the same thing as container.getStore
* Does the same thing as container.all
*

@@ -47,3 +32,3 @@ * ### Usage

*/
all(): Repository;
all(): any;
/**

@@ -100,3 +85,3 @@ * ## container.setStore

*/
mutateStore<T = any>(mutationFn: (value?: T) => T): this;
mutateStore(mutationFn: (value?: I) => I): this;
/**

@@ -113,3 +98,3 @@ * ## container.mutateStore

*/
mutateStoreEntries<T = any>(mutateFn: (key: string, value: T) => T): this;
mutateStoreEntries(mutateFn: (key: string, value: I) => I): this;
/**

@@ -132,3 +117,3 @@ * ## container.get

*/
get(key: string): any;
get<T = any>(key: any): T;
/**

@@ -151,3 +136,3 @@ * ## container.getEntries

*/
getEntries<T = any>(key?: string): [string, T][];
getEntries<T = any>(key?: keyof T): [keyof T, ValueOf<T>][];
/**

@@ -170,3 +155,3 @@ * ## container.fromEntries

*/
fromEntries<T = any>(entries: [string, T][]): this;
fromEntries(entries: [string, any][]): this;
/**

@@ -183,3 +168,3 @@ * ## container.withEntries

*/
each<T = any>(key: string, callFn: (key: string, value: T) => void): this;
each(key: string, callFn: (key: any, value: any) => void): this;
/**

@@ -197,2 +182,4 @@ * ## container.every

every(fn: (key: string, value: any) => any): this;
findKey(...searchItem: any): any;
findKeyOf(key: string, ...searchItem: any[]): any;
/**

@@ -209,3 +196,3 @@ * ## container.mutateEntries

*/
mutateEntries<T = any>(key: string, mutateFn: (key: string, value: T) => T): this;
mutateEntries(key: string, mutateFn: (key: string, value: any) => any): this;
/**

@@ -229,3 +216,3 @@ * ## container.getValues

*/
getValues(key?: string): unknown[];
getValues(key?: string): any[];
/**

@@ -270,3 +257,3 @@ * ## container.getKeys

*/
getMap<T = unknown>(key?: string): Map<string, T>;
getMap(key?: string): Map<string, any>;
/**

@@ -283,4 +270,18 @@ * ## container.set

*/
set<T = any>(key: string, value: T): this;
set(key: string, value: any): this;
/**
* ## container.push
*
* Push an item or entry onto the container
*
* ```js
* container.unique('containerKey') // unique values of containerKey
* ```
*
* ```js
* container.unique() // unique values of container
* ```
*/
push(value: any, key?: any): this;
/**
* ## container.transform

@@ -298,3 +299,3 @@ *

*/
transform<T = any>(key: string, mutationFn: (value?: T) => T): T;
transform(key: string, mutationFn: (value?: any) => any): any;
/**

@@ -311,3 +312,3 @@ * ## container.mutate

*/
mutate<T = any>(key: string, mutationFn: (value?: T) => T): this;
mutate(key: string, mutationFn: (value?: any) => any): this;
/**

@@ -324,3 +325,3 @@ * ## container.merge

*/
merge<T = any>(key: string, value: T): this;
merge(key: string, value: any): this;
/**

@@ -364,3 +365,3 @@ * ## container.has

*/
is<T = any>(key: string, value: T): boolean;
is(key: string, value: any): boolean;
/**

@@ -592,3 +593,16 @@ * ## container.isTrue

isUndefined(key: string): boolean;
/**
* ## container.isFunction
*
* Return true if object is a function
*
* ### Usage
*
* ```js
* container.isFunction('my-key')
* // True if object associated with 'my-key' is a fn.
* ````
*/
isFunction(key: string): boolean;
}
//# sourceMappingURL=index.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc