@locker/shared
Advanced tools
Comparing version 0.11.7 to 0.11.9
@@ -10,38 +10,29 @@ /** | ||
const MathMin = Math.min; | ||
function unapply(func) { | ||
return (thisArg, ...args) => ReflectApply(func, thisArg, args); | ||
function isFunction(value) { | ||
return typeof value === 'function'; | ||
} | ||
function unconstruct(func) { | ||
return (...args) => ReflectConstruct(func, args); | ||
function isObject(value) { | ||
return typeof value === 'object' && value !== null; | ||
} | ||
function isUndefined(obj) { | ||
return obj === undefined; | ||
function isObjectLike(value) { | ||
const type = typeof value; | ||
return type === 'function' || (type === 'object' && value !== null); | ||
} | ||
function isNull(obj) { | ||
return obj === null; | ||
function isNull(value) { | ||
return value === null; | ||
} | ||
function isNullOrUndefined(obj) { | ||
return isUndefined(obj) || isNull(obj); | ||
function isNullOrUndefined(value) { | ||
return isNull(value) || isUndefined(value); | ||
} | ||
function isTrue(obj) { | ||
return obj === true; | ||
function isTrue(value) { | ||
return value === true; | ||
} | ||
function isFunction(obj) { | ||
return typeof obj === 'function'; | ||
function isUndefined(value) { | ||
return value === undefined; | ||
} | ||
// To sanitizeArguments that require no transformation | ||
function toIgnore(obj) { | ||
return obj; | ||
function unapply(func) { | ||
return (thisArg, ...args) => ReflectApply(func, thisArg, args); | ||
} | ||
function sanitizeArguments(args, sanitizers) { | ||
const argsLen = args.length; | ||
const sLen = sanitizers.length; | ||
const len = MathMin(argsLen, sLen); | ||
const sanitizedArgs = ArrayFrom(args); | ||
for (let i = 0; i < len; i += 1) { | ||
sanitizedArgs[i] = sanitizers[i](args[i]); | ||
} | ||
return sanitizedArgs; | ||
function unconstruct(func) { | ||
return (...args) => ReflectConstruct(func, args); | ||
} | ||
@@ -64,3 +55,3 @@ | ||
const { assign: ObjectAssign, create: ObjectCreate, defineProperty: ObjectDefineProperty, getOwnPropertyDescriptors: ObjectGetOwnPropertyDescriptors, freeze: ObjectFreeze, getOwnPropertySymbols: ObjectGetOwnPropertySymbols, keys: ObjectKeys, seal: ObjectSeal, isSealed: ObjectIsSealed, isFrozen: ObjectIsFrozen, preventExtensions: ObjectPreventExtensions, } = Object; | ||
const { assign: ObjectAssign, create: ObjectCreate, defineProperty: ObjectDefineProperty, getOwnPropertyDescriptors: ObjectGetOwnPropertyDescriptors, freeze: ObjectFreeze, getOwnPropertyNames: ObjectGetOwnPropertyNames, getOwnPropertySymbols: ObjectGetOwnPropertySymbols, keys: ObjectKeys, seal: ObjectSeal, isSealed: ObjectIsSealed, isFrozen: ObjectIsFrozen, preventExtensions: ObjectPreventExtensions, } = Object; | ||
const ObjectHasOwnProperty = unapply(Object.prototype.hasOwnProperty); | ||
@@ -80,2 +71,14 @@ function createSafeObject(object) { | ||
} | ||
function defaults(object, source) { | ||
if (isObjectLike(source)) { | ||
const keys = ObjectGetOwnPropertyNames(source); | ||
ArrayPush(keys, ObjectGetOwnPropertySymbols(source)); | ||
ArrayForEach(keys, (name) => { | ||
if (object[name] === undefined || !ObjectHasOwnProperty(object, name)) { | ||
object[name] = source[name]; | ||
} | ||
}); | ||
} | ||
return object; | ||
} | ||
@@ -140,4 +143,21 @@ const ProxyCreate = unconstruct(Proxy); | ||
const MathMin = Math.min; | ||
const RegExpTest = unapply(RegExp.prototype.test); | ||
// To sanitizeArguments that require no transformation | ||
function toIgnore(value) { | ||
return value; | ||
} | ||
function sanitizeArguments(args, sanitizers) { | ||
const argsLen = args.length; | ||
const sLen = sanitizers.length; | ||
const len = MathMin(argsLen, sLen); | ||
const sanitizedArgs = ArrayFrom(args); | ||
for (let i = 0; i < len; i += 1) { | ||
sanitizedArgs[i] = sanitizers[i](args[i]); | ||
} | ||
return sanitizedArgs; | ||
} | ||
const SetCreate = unconstruct(Set); | ||
@@ -207,2 +227,3 @@ const SetAdd = unapply(Set.prototype.add); | ||
exports.ObjectGetOwnPropertyDescriptors = ObjectGetOwnPropertyDescriptors; | ||
exports.ObjectGetOwnPropertyNames = ObjectGetOwnPropertyNames; | ||
exports.ObjectGetOwnPropertySymbols = ObjectGetOwnPropertySymbols; | ||
@@ -257,5 +278,8 @@ exports.ObjectHasOwnProperty = ObjectHasOwnProperty; | ||
exports.createSafeObject = createSafeObject; | ||
exports.defaults = defaults; | ||
exports.isFunction = isFunction; | ||
exports.isNull = isNull; | ||
exports.isNullOrUndefined = isNullOrUndefined; | ||
exports.isObject = isObject; | ||
exports.isObjectLike = isObjectLike; | ||
exports.isTrue = isTrue; | ||
@@ -271,2 +295,2 @@ exports.isUndefined = isUndefined; | ||
exports.unconstruct = unconstruct; | ||
/** version: 0.11.7 */ | ||
/** version: 0.11.9 */ |
@@ -6,38 +6,29 @@ /** | ||
const MathMin = Math.min; | ||
function unapply(func) { | ||
return (thisArg, ...args) => ReflectApply(func, thisArg, args); | ||
function isFunction(value) { | ||
return typeof value === 'function'; | ||
} | ||
function unconstruct(func) { | ||
return (...args) => ReflectConstruct(func, args); | ||
function isObject(value) { | ||
return typeof value === 'object' && value !== null; | ||
} | ||
function isUndefined(obj) { | ||
return obj === undefined; | ||
function isObjectLike(value) { | ||
const type = typeof value; | ||
return type === 'function' || (type === 'object' && value !== null); | ||
} | ||
function isNull(obj) { | ||
return obj === null; | ||
function isNull(value) { | ||
return value === null; | ||
} | ||
function isNullOrUndefined(obj) { | ||
return isUndefined(obj) || isNull(obj); | ||
function isNullOrUndefined(value) { | ||
return isNull(value) || isUndefined(value); | ||
} | ||
function isTrue(obj) { | ||
return obj === true; | ||
function isTrue(value) { | ||
return value === true; | ||
} | ||
function isFunction(obj) { | ||
return typeof obj === 'function'; | ||
function isUndefined(value) { | ||
return value === undefined; | ||
} | ||
// To sanitizeArguments that require no transformation | ||
function toIgnore(obj) { | ||
return obj; | ||
function unapply(func) { | ||
return (thisArg, ...args) => ReflectApply(func, thisArg, args); | ||
} | ||
function sanitizeArguments(args, sanitizers) { | ||
const argsLen = args.length; | ||
const sLen = sanitizers.length; | ||
const len = MathMin(argsLen, sLen); | ||
const sanitizedArgs = ArrayFrom(args); | ||
for (let i = 0; i < len; i += 1) { | ||
sanitizedArgs[i] = sanitizers[i](args[i]); | ||
} | ||
return sanitizedArgs; | ||
function unconstruct(func) { | ||
return (...args) => ReflectConstruct(func, args); | ||
} | ||
@@ -60,3 +51,3 @@ | ||
const { assign: ObjectAssign, create: ObjectCreate, defineProperty: ObjectDefineProperty, getOwnPropertyDescriptors: ObjectGetOwnPropertyDescriptors, freeze: ObjectFreeze, getOwnPropertySymbols: ObjectGetOwnPropertySymbols, keys: ObjectKeys, seal: ObjectSeal, isSealed: ObjectIsSealed, isFrozen: ObjectIsFrozen, preventExtensions: ObjectPreventExtensions, } = Object; | ||
const { assign: ObjectAssign, create: ObjectCreate, defineProperty: ObjectDefineProperty, getOwnPropertyDescriptors: ObjectGetOwnPropertyDescriptors, freeze: ObjectFreeze, getOwnPropertyNames: ObjectGetOwnPropertyNames, getOwnPropertySymbols: ObjectGetOwnPropertySymbols, keys: ObjectKeys, seal: ObjectSeal, isSealed: ObjectIsSealed, isFrozen: ObjectIsFrozen, preventExtensions: ObjectPreventExtensions, } = Object; | ||
const ObjectHasOwnProperty = unapply(Object.prototype.hasOwnProperty); | ||
@@ -76,2 +67,14 @@ function createSafeObject(object) { | ||
} | ||
function defaults(object, source) { | ||
if (isObjectLike(source)) { | ||
const keys = ObjectGetOwnPropertyNames(source); | ||
ArrayPush(keys, ObjectGetOwnPropertySymbols(source)); | ||
ArrayForEach(keys, (name) => { | ||
if (object[name] === undefined || !ObjectHasOwnProperty(object, name)) { | ||
object[name] = source[name]; | ||
} | ||
}); | ||
} | ||
return object; | ||
} | ||
@@ -136,4 +139,21 @@ const ProxyCreate = unconstruct(Proxy); | ||
const MathMin = Math.min; | ||
const RegExpTest = unapply(RegExp.prototype.test); | ||
// To sanitizeArguments that require no transformation | ||
function toIgnore(value) { | ||
return value; | ||
} | ||
function sanitizeArguments(args, sanitizers) { | ||
const argsLen = args.length; | ||
const sLen = sanitizers.length; | ||
const len = MathMin(argsLen, sLen); | ||
const sanitizedArgs = ArrayFrom(args); | ||
for (let i = 0; i < len; i += 1) { | ||
sanitizedArgs[i] = sanitizers[i](args[i]); | ||
} | ||
return sanitizedArgs; | ||
} | ||
const SetCreate = unconstruct(Set); | ||
@@ -173,3 +193,3 @@ const SetAdd = unapply(Set.prototype.add); | ||
export { ArrayConcat, ArrayFilter, ArrayForEach, ArrayFrom, ArrayIncludes, ArrayIsArray, ArrayJoin, ArrayMap, ArrayPush, ArraySome, ErrorCreate, FunctionBind, FunctionCall, JSONParse, JSONStringify, LockerRangeError, LockerSecurityError, MapConcat, MapCreate, MapEntries, MapForEach, MapGet, MapIteratorCreate, MapSet, MathMin, ObjectAssign, ObjectCreate, ObjectDefineProperty, ObjectFreeze, ObjectGetOwnPropertyDescriptors, ObjectGetOwnPropertySymbols, ObjectHasOwnProperty, ObjectIsFrozen, ObjectIsSealed, ObjectKeys, ObjectPreventExtensions, ObjectSeal, ProxyCreate, ProxyRevocable, RangeErrorCreate, ReflectApply, ReflectConstruct, ReflectDefineProperty, ReflectDeleteProperty, ReflectGet, ReflectGetOwnPropertyDescriptor, ReflectGetPrototypeOf, ReflectHas, ReflectIsExtensible, ReflectOwnKeys, ReflectPreventExtensions, ReflectSet, ReflectSetPrototypeOf, RegExpTest, SetAdd, SetCreate, SetDelete, SetHas, StringCharCodeAt, StringEndsWith, StringIncludes, StringIndexOf, StringMatch, StringReplace, StringSplit, StringStartsWith, StringSubstring, StringToLowerCase, StringToUpperCase, StringTrim, SymbolFor, SymbolIterator, TypeErrorCreate, WeakMapCreate, WeakMapGet, WeakMapHas, WeakMapSet, createRevokedProxy, createSafeObject, isFunction, isNull, isNullOrUndefined, isTrue, isUndefined, maskDistortion, sanitizeArguments, toBoolean, toIgnore, toString, toStringIfNotNullOrUndefined, unapply, unconstruct }; | ||
/** version: 0.11.7 */ | ||
export { ArrayConcat, ArrayFilter, ArrayForEach, ArrayFrom, ArrayIncludes, ArrayIsArray, ArrayJoin, ArrayMap, ArrayPush, ArraySome, ErrorCreate, FunctionBind, FunctionCall, JSONParse, JSONStringify, LockerRangeError, LockerSecurityError, MapConcat, MapCreate, MapEntries, MapForEach, MapGet, MapIteratorCreate, MapSet, MathMin, ObjectAssign, ObjectCreate, ObjectDefineProperty, ObjectFreeze, ObjectGetOwnPropertyDescriptors, ObjectGetOwnPropertyNames, ObjectGetOwnPropertySymbols, ObjectHasOwnProperty, ObjectIsFrozen, ObjectIsSealed, ObjectKeys, ObjectPreventExtensions, ObjectSeal, ProxyCreate, ProxyRevocable, RangeErrorCreate, ReflectApply, ReflectConstruct, ReflectDefineProperty, ReflectDeleteProperty, ReflectGet, ReflectGetOwnPropertyDescriptor, ReflectGetPrototypeOf, ReflectHas, ReflectIsExtensible, ReflectOwnKeys, ReflectPreventExtensions, ReflectSet, ReflectSetPrototypeOf, RegExpTest, SetAdd, SetCreate, SetDelete, SetHas, StringCharCodeAt, StringEndsWith, StringIncludes, StringIndexOf, StringMatch, StringReplace, StringSplit, StringStartsWith, StringSubstring, StringToLowerCase, StringToUpperCase, StringTrim, SymbolFor, SymbolIterator, TypeErrorCreate, WeakMapCreate, WeakMapGet, WeakMapHas, WeakMapSet, createRevokedProxy, createSafeObject, defaults, isFunction, isNull, isNullOrUndefined, isObject, isObjectLike, isTrue, isUndefined, maskDistortion, sanitizeArguments, toBoolean, toIgnore, toString, toStringIfNotNullOrUndefined, unapply, unconstruct }; | ||
/** version: 0.11.9 */ |
{ | ||
"name": "@locker/shared", | ||
"version": "0.11.7", | ||
"version": "0.11.9", | ||
"description": "Locker Next Shared Utilities", | ||
@@ -23,3 +23,3 @@ "main": "dist/index.cjs.js", | ||
}, | ||
"gitHead": "d95b59d9623ee44939cd6d3f2b33b487ea308bdc" | ||
"gitHead": "7fd681f08f87206dfb944c258dac4eb12a98a6eb" | ||
} |
@@ -0,11 +1,9 @@ | ||
export declare function isFunction(value: any): value is Function; | ||
export declare function isObject(value: any): boolean; | ||
export declare function isObjectLike(value: any): boolean; | ||
export declare function isNull(value: any): value is null; | ||
export declare function isNullOrUndefined(value: any): value is null | undefined; | ||
export declare function isTrue(value: any): value is true; | ||
export declare function isUndefined(value: any): value is undefined; | ||
export declare function unapply(func: Function): Function; | ||
export declare function unconstruct(func: Function): Function; | ||
export declare function isUndefined(obj: any): obj is undefined; | ||
export declare function isNull(obj: any): obj is null; | ||
export declare function isNullOrUndefined(obj: any): obj is null | undefined; | ||
export declare function isTrue(obj: any): obj is true; | ||
export declare function isFunction(obj: any): obj is Function; | ||
export declare function toIgnore(obj: any): any; | ||
declare type SanitizerFn = (obj: any) => any; | ||
export declare function sanitizeArguments(args: IArguments | Array<any>, sanitizers: Array<SanitizerFn>): Array<any>; | ||
export {}; |
@@ -14,2 +14,3 @@ export * from './Array'; | ||
export * from './RegExp'; | ||
export * from './Sanitize'; | ||
export * from './Set'; | ||
@@ -16,0 +17,0 @@ export * from './String'; |
@@ -15,3 +15,3 @@ export declare const ObjectAssign: { | ||
<T_2>(o: T_2): Readonly<T_2>; | ||
}, ObjectGetOwnPropertySymbols: (o: any) => symbol[], ObjectKeys: { | ||
}, ObjectGetOwnPropertyNames: (o: any) => string[], ObjectGetOwnPropertySymbols: (o: any) => symbol[], ObjectKeys: { | ||
(o: object): string[]; | ||
@@ -24,1 +24,2 @@ (o: {}): string[]; | ||
}; | ||
export declare function defaults(object: any, source: any): any; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
26731
22
578
0