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

@ctx-core/object

Package Overview
Dependencies
Maintainers
1
Versions
666
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ctx-core/object - npm Package Compare versions

Comparing version 5.0.1 to 5.0.2

151

lib.js

@@ -55,27 +55,27 @@ import { _andand } from '@ctx-core/function'

/**
* Returns the [ctx](#ctx) with default values. If `ctx[key] == null`, use `default[key]`
* @param {ctx} ctx
* @param {...*} a1__defaults values to set on `ctx` if `ctx[key] == null`
* @returns {ctx}
* Returns the obj with default values. If `obj[key] == null`, use `default[key]`
* @param {*} obj
* @param {...*} a1__defaults values to set on `obj` if `obj[key] == null`
* @returns {obj}
*/
export function defaults(ctx, ...a1__defaults) {
export function defaults(obj, ...a1__defaults) {
const defaults = clone(...a1__defaults)
for (let key in ctx) {
if (ctx[key] == null) ctx[key] = defaults[key]
for (let key in obj) {
if (obj[key] == null) obj[key] = defaults[key]
}
return ctx
return obj
}
/**
* Assign only if ctx is not null
* @param {ctx} ctx
* Assign only if obj is not null
* @param {*} obj
* @param {...*} *
* @returns {ctx} ctx
* @returns {obj} obj
*/
export function assign__unless__null(ctx) {
return (ctx == null) ? ctx : assign(...arguments)
export function assign__unless__null(obj) {
return (obj == null) ? obj : assign(...arguments)
}
/**
* Assigns [ctx__assign](#ctx__assign) to a new [ctx](#ctx).
* @param {...ctx__assign} * Assigned to cloned `ctx`
* @returns {ctx} ctx
* Assigns arguments to new object
* @param {...*} * Assigned to cloned object
* @returns {*} assigned object
*/

@@ -143,14 +143,14 @@ export function clone() {

/**
* Ensures that the keys in `a1__ctx__rest` are added to ctx
* only if the key is not defined on [ctx](#ctx) (== null).
* Ensures that the keys in `a1__ctx__rest` are added to obj
* only if the key is not defined on obj (== null).
* The order of precedence is from left to right.
* @param {ctx} ctx
* @param {...ctx} a1__ctx__rest
* Rest of key/value pairs to define if not defined on [ctx](#ctx)
* @returns {ctx}
* @param {obj} obj
* @param {...obj} a1__ctx__rest
* Rest of key/value pairs to define if not defined on obj
* @returns {obj}
* @example
* ctx = {baz: 99}
* ensure(ctx, {foo: 1, baz: 4}, {foo: 2, bar: 3}) // {baz:99, foo: 1, bar: 3}
* obj = {baz: 99}
* ensure(obj, {foo: 1, baz: 4}, {foo: 2, bar: 3}) // {baz:99, foo: 1, bar: 3}
*/
export function ensure(ctx, ...a1__ctx__rest) {
export function ensure(obj, ...a1__ctx__rest) {
for (let i = 0; i < a1__ctx__rest.length; i++) {

@@ -161,8 +161,8 @@ const rest = a1__ctx__rest[i]

const key = a1__key__ctx__rest[j]
if (ctx[key] == null) {
ctx[key] = rest[key]
if (obj[key] == null) {
obj[key] = rest[key]
}
}
}
return ctx
return obj
}

@@ -186,10 +186,10 @@ /**

* not including including inherited property values (i.e. if hasOwnProperty is false).
* @param {ctx} ctx
* @param {*} obj
* @param {...string} a1__key
*/
export function pick__hasOwnProperty(ctx, ...a1__key) {
export function pick__hasOwnProperty(obj, ...a1__key) {
let memo = {}
for (let i = 0; i < a1__key.length; i++) {
const key = a1__key[i]
if (ctx.hasOwnProperty(key)) memo[key] = ctx[key]
if (obj.hasOwnProperty(key)) memo[key] = obj[key]
}

@@ -213,28 +213,28 @@ return memo

/**
* Picks the keys on `obj__keys` from `ctx`
* @param {ctx} ctx
* Picks the keys on `obj__keys` from `obj`
* @param {*} obj
* @param {*} obj__keys
*/
export function pick__keys(ctx, obj__keys) {
return pick(ctx, ...Object.keys(obj__keys))
export function pick__keys(obj, obj__keys) {
return pick(obj, ...Object.keys(obj__keys))
}
/**
* Does not include keys on `obj__keys` from `ctx`
* @param {ctx} ctx
* Does not include keys on `obj__keys` from `obj`
* @param {*} obj
* @param {*} obj__keys
*/
export function unpick__keys(ctx, obj__keys) {
return unpick(ctx, ...Object.keys(obj__keys))
export function unpick__keys(obj, obj__keys) {
return unpick(obj, ...Object.keys(obj__keys))
}
/**
* Returns an array of objects with [pick](#pick) applied.
* @param {ctx} ctx
* @param {*} obj
* @param {...string} a1__key
* @returns {*[]}
*/
export function _a1__value__pick(ctx, ...a1__key) {
export function _a1__value__pick(obj, ...a1__key) {
let a1__value = []
for (let i = 0; i < a1__key.length; i++) {
const key = a1__key[i]
a1__value.push(ctx[key])
a1__value.push(obj[key])
}

@@ -245,3 +245,3 @@ return a1__value

* Exclude keys from obj
* @param obj
* @param {*}obj
* @param {...string} a1__key

@@ -285,16 +285,16 @@ * @returns {*}

* @param {string} key
* @param {function(ctx): *} ensure Called when `ctx[key]` is falsy.
* @param {function(*): *} ensure Called when `ctx[key]` is falsy.
* `ctx[key]` is set to the return value.
* @param {function(ctx, *)} refresh Called with the ensured value of `ctx[key]`.
* @param {function(*, *)} refresh Called with the ensured value of `obj[key]`.
*/
/**
* `ensure` `ctx[key]` is present or call `ctx__refresh.init`. Then call `ctx__refresh.refresh`.
* `ensure` `obj[key]` is present or call `ctx__refresh.init`. Then call `ctx__refresh.refresh`.
*
* - if `!ctx[key]` `ctx__refresh.ensure(ctx)`
* - `a1__ctx__refresh.refresh(ctx, ctx[key])`
* @param {ctx} ctx
* - if `!obj[key]` `ctx__refresh.ensure(obj)`
* - `a1__ctx__refresh.refresh(obj, obj[key])`
* @param {*} obj
* @param {...ctx__ensure__refresh} a1__ctx__refresh
* @returns {*} The value of the ctx[key]
* @returns {*} The value of the obj[key]
*/
export function ensure__refresh(ctx, ...a1__ctx__refresh) {
export function ensure__refresh(obj, ...a1__ctx__refresh) {
const ctx__refresh = clone(...a1__ctx__refresh)

@@ -306,23 +306,26 @@ const {

} = ctx__refresh
if (!ctx[key]) {
ctx[key] = ensure(ctx)
if (!obj[key]) {
obj[key] = ensure(obj)
}
refresh(ctx, ctx[key])
return ctx[key]
refresh(obj, obj[key])
return obj[key]
}
/**
* @typedef opts__or
* @param {*} value
* @param {*} value__or
* @param {*=} value__nor
*/
/**
* return the `value` if not null or `value__or`
* @param {ctx} ctx
* @param {*} ctx.value - if not null; ctx.value$ || ctx.value
* @param {*} ctx.value__or - if null; ctx.value__or
* @param {*=} ctx.value__ if not null; use optional value$ instead of value
* @returns {value|value__or} `value` if not null or `value__or`
* @param {opts__or} opts
* @returns {*} `value` if not null or `value__or`
*/
export function or__null(ctx) {
export function or__null(opts) {
const {
value,
value__or,
value__
} = ctx
return value == null ? value__or : (value__ || value)
value__nor
} = opts
return value == null ? value__or : (value__nor || value)
}

@@ -361,3 +364,3 @@ const symbol__no_key_arg = Symbol('no_key_arg')

/**
* Returns [ctx](#ctx) with keys in `a1__key` having `value__clear`.
* Returns obj with keys in `a1__key` having `value__clear`.
* @param {string[]} a1__key

@@ -376,3 +379,3 @@ * @param value__clear

/**
* Returns [ctx](#ctx) with zipped a1__value
* Returns obj with zipped a1__value
* @param {string[]} a1__key

@@ -392,11 +395,13 @@ * @param {*[]} a1__value

/**
* Sets [ctx](#ctx) values to false when `== null`.
* @param {ctx}
* Sets obj values to false when `== null`.
* @param {*} obj
* @param {...string} a1__key
* @returns {*}
*/
export function set__false__if__null(ctx, ...keys) {
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
if (ctx[key] == null) ctx[key] = false
export function set__false__if__null(obj, ...a1__key) {
for (let i = 0; i < a1__key.length; i++) {
const key = a1__key[i]
if (obj[key] == null) obj[key] = false
}
return ctx
return obj
}

@@ -403,0 +408,0 @@ /**

{
"name": "@ctx-core/object",
"version": "5.0.1",
"version": "5.0.2",
"description": "ctx-core object",

@@ -26,3 +26,3 @@ "main": "lib.js",

},
"gitHead": "c97042056c7030acb6501292a8e45b8b4d62549c"
"gitHead": "56e78df3eb92b1fa2abccd93c93b66b7d4711e82"
}
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