@lowdefy/helpers
Advanced tools
Comparing version 4.0.0-alpha.5 to 4.0.0-alpha.6
@@ -27,2 +27,3 @@ /* | ||
import urlQuery from './urlQuery.js'; | ||
export { applyArrayIndices, cachedPromises, get, mergeObjects, omit, serializer, set, stableStringify, swap, type, unset, urlQuery }; | ||
import wait from './wait.js'; | ||
export { applyArrayIndices, cachedPromises, get, mergeObjects, omit, serializer, set, stableStringify, swap, type, unset, urlQuery, wait }; |
@@ -90,4 +90,3 @@ /* eslint-disable no-param-reassign */ /* | ||
; | ||
const serialize = (json, options = { | ||
})=>{ | ||
const serialize = (json, options = {})=>{ | ||
if (type.isUndefined(json)) return json; | ||
@@ -106,4 +105,3 @@ if (type.isDate(json)) { | ||
}; | ||
const serializeToString = (json, options = { | ||
})=>{ | ||
const serializeToString = (json, options = {})=>{ | ||
if (type.isUndefined(json)) return json; | ||
@@ -124,14 +122,11 @@ if (type.isDate(json)) { | ||
}; | ||
const deserialize = (json, options = { | ||
})=>{ | ||
const deserialize = (json, options = {})=>{ | ||
if (type.isUndefined(json)) return json; | ||
return JSON.parse(JSON.stringify(json), makeReviver(options.reviver)); | ||
}; | ||
const deserializeFromString = (str, options = { | ||
})=>{ | ||
const deserializeFromString = (str, options = {})=>{ | ||
if (type.isUndefined(str)) return str; | ||
return JSON.parse(str, makeReviver(options.reviver)); | ||
}; | ||
const copy = (json, options = { | ||
})=>{ | ||
const copy = (json, options = {})=>{ | ||
if (type.isUndefined(json)) return undefined; | ||
@@ -138,0 +133,0 @@ if (type.isDate(json)) return new Date(json.valueOf()); |
@@ -44,4 +44,3 @@ /* eslint-disable no-plusplus */ /* eslint-disable no-use-before-define */ /* eslint-disable no-param-reassign */ /* | ||
if (merge && isObjectOrFunction(target[path]) && isObjectOrFunction(value)) { | ||
target[path] = merge({ | ||
}, target[path], value); | ||
target[path] = merge({}, target[path], value); | ||
} else { | ||
@@ -52,4 +51,3 @@ target[path] = value; | ||
// eslint-disable-next-line no-use-before-define | ||
set.memo = { | ||
}; | ||
set.memo = {}; | ||
function set(target, path, value, options) { | ||
@@ -59,4 +57,3 @@ if (!type.isObject(target)) { | ||
} | ||
const opts = options || { | ||
}; | ||
const opts = options || {}; | ||
if (!type.isArray(path) && !type.isString(path)) { | ||
@@ -81,4 +78,3 @@ return target; | ||
// changed | ||
target[prop] = { | ||
}; | ||
target[prop] = {}; | ||
} else if (!isObjectOrFunction(target[prop]) && type.isInt(parseInt(propUp, 10))) { | ||
@@ -85,0 +81,0 @@ // added |
@@ -35,4 +35,3 @@ /* eslint-disable no-continue */ /* eslint-disable no-plusplus */ /* eslint-disable consistent-return */ /* eslint-disable no-param-reassign */ /* | ||
function stableStringify(obj, opts) { | ||
if (!opts) opts = { | ||
}; | ||
if (!opts) opts = {}; | ||
if (typeof opts === 'function') opts = { | ||
@@ -39,0 +38,0 @@ cmp: opts |
@@ -68,8 +68,8 @@ /* eslint-disable indent */ /* eslint-disable default-case */ /* | ||
if (val === null) return 'null'; | ||
let type = typeof val; | ||
if (type === 'boolean') return 'boolean'; | ||
if (type === 'string') return 'string'; | ||
if (type === 'number') return 'number'; | ||
if (type === 'symbol') return 'symbol'; | ||
if (type === 'function') { | ||
let type1 = typeof val; | ||
if (type1 === 'boolean') return 'boolean'; | ||
if (type1 === 'string') return 'string'; | ||
if (type1 === 'number') return 'number'; | ||
if (type1 === 'symbol') return 'symbol'; | ||
if (type1 === 'function') { | ||
return isGeneratorFn(val) ? 'generatorfunction' : 'function'; | ||
@@ -123,4 +123,4 @@ } | ||
// Non-plain objects | ||
type = toString.call(val); | ||
switch(type){ | ||
type1 = toString.call(val); | ||
switch(type1){ | ||
case '[object Object]': | ||
@@ -139,3 +139,3 @@ return 'object'; | ||
// other | ||
return type.slice(8, -1).toLowerCase().replace(/\s/g, ''); | ||
return type1.slice(8, -1).toLowerCase().replace(/\s/g, ''); | ||
} | ||
@@ -146,41 +146,40 @@ const reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*))(?:Z|(\+|-)([\d|:]*))?$/; | ||
} | ||
const type1 = { | ||
}; | ||
type1.typeOf = kindOf; | ||
type1.isArray = isArray; | ||
type1.isDate = isDate; | ||
type1.isError = isError; | ||
type1.isDateString = isDateString; | ||
type1.isObject = (value)=>kindOf(value) === 'object' | ||
const type = {}; | ||
type.typeOf = kindOf; | ||
type.isArray = isArray; | ||
type.isDate = isDate; | ||
type.isError = isError; | ||
type.isDateString = isDateString; | ||
type.isObject = (value)=>kindOf(value) === 'object' | ||
; | ||
type1.isString = (value)=>typeof value === 'string' | ||
type.isString = (value)=>typeof value === 'string' | ||
; | ||
type1.isRegExp = (value)=>kindOf(value) === 'regexp' | ||
type.isRegExp = (value)=>kindOf(value) === 'regexp' | ||
; | ||
type1.isFunction = (value)=>kindOf(value) === 'function' | ||
type.isFunction = (value)=>kindOf(value) === 'function' | ||
; | ||
type1.isBoolean = (value)=>typeof value === 'boolean' | ||
type.isBoolean = (value)=>typeof value === 'boolean' | ||
; | ||
type1.isNumber = (value)=>typeof value === 'number' && Number.isFinite(value) | ||
type.isNumber = (value)=>typeof value === 'number' && Number.isFinite(value) | ||
; | ||
type1.isNumeric = (value)=>!Number.isNaN(Number(value)) | ||
type.isNumeric = (value)=>!Number.isNaN(Number(value)) | ||
; | ||
type1.isInt = (value)=>Number.isInteger(value) === true | ||
type.isInt = (value)=>Number.isInteger(value) === true | ||
; | ||
type1.isSet = (value)=>kindOf(value) === 'set' | ||
type.isSet = (value)=>kindOf(value) === 'set' | ||
; | ||
type1.isNull = (value)=>kindOf(value) === 'null' | ||
type.isNull = (value)=>kindOf(value) === 'null' | ||
; | ||
type1.isUndefined = (value)=>kindOf(value) === 'undefined' | ||
type.isUndefined = (value)=>kindOf(value) === 'undefined' | ||
; | ||
type1.isNone = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null' | ||
type.isNone = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null' | ||
; | ||
type1.isPrimitive = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null' || kindOf(value) === 'string' || kindOf(value) === 'number' || kindOf(value) === 'boolean' || kindOf(value) === 'date' | ||
type.isPrimitive = (value)=>kindOf(value) === 'undefined' || kindOf(value) === 'null' || kindOf(value) === 'string' || kindOf(value) === 'number' || kindOf(value) === 'boolean' || kindOf(value) === 'date' | ||
; | ||
type1.isEmptyObject = (value)=>kindOf(value) === 'object' && Object.keys(value).length === 0 | ||
type.isEmptyObject = (value)=>kindOf(value) === 'object' && Object.keys(value).length === 0 | ||
; | ||
// Lowdefy operator types | ||
function isName(value) { | ||
if (!type1.isString(value)) return false; | ||
const noLeadingNumeric = value.split('.').reduce((acc, val)=>acc && !type1.isNumeric(val.charAt(0)) | ||
if (!type.isString(value)) return false; | ||
const noLeadingNumeric = value.split('.').reduce((acc, val)=>acc && !type.isNumeric(val.charAt(0)) | ||
, true); | ||
@@ -195,22 +194,22 @@ const noLeadTrailStop = value.charAt(0) !== '.' && value.charAt(value.length - 1) !== '.'; | ||
// Lowdefy | ||
type1.isOpRequest = isOpRequest; | ||
type1.isName = isName; | ||
type.isOpRequest = isOpRequest; | ||
type.isName = isName; | ||
function enforceType(typeName, value) { | ||
switch(typeName){ | ||
case 'string': | ||
return type1.isString(value) && value !== '' ? value : null; | ||
return type.isString(value) && value !== '' ? value : null; | ||
case 'number': | ||
return type1.isNumber(value) ? value : null; | ||
return type.isNumber(value) ? value : null; | ||
case 'boolean': | ||
return type1.isBoolean(value) ? value : false; | ||
return type.isBoolean(value) ? value : false; | ||
case 'date': | ||
return type1.isDate(value) ? value : null; | ||
return type.isDate(value) ? value : null; | ||
case 'array': | ||
return type1.isArray(value) ? value : []; | ||
return type.isArray(value) ? value : []; | ||
case 'primitive': | ||
return type1.isString(value) && value !== '' || type1.isNumber(value) || type1.isDate(value) || type1.isBoolean(value) ? value : null; | ||
return type.isString(value) && value !== '' || type.isNumber(value) || type.isDate(value) || type.isBoolean(value) ? value : null; | ||
case 'object': | ||
return type1.isObject(value) ? value : null; | ||
return type.isObject(value) ? value : null; | ||
case 'any': | ||
return !type1.isUndefined(value) ? value : null; | ||
return !type.isUndefined(value) ? value : null; | ||
default: | ||
@@ -220,3 +219,3 @@ return null; | ||
} | ||
type1.enforceType = enforceType; | ||
export default type1; | ||
type.enforceType = enforceType; | ||
export default type; |
@@ -21,4 +21,3 @@ /* | ||
const parsed = queryString.parse(str); | ||
const deserialized = { | ||
}; | ||
const deserialized = {}; | ||
Object.keys(parsed).forEach((key)=>{ | ||
@@ -37,4 +36,3 @@ try { | ||
} | ||
const toSerialize = { | ||
}; | ||
const toSerialize = {}; | ||
Object.keys(object).forEach((key)=>{ | ||
@@ -41,0 +39,0 @@ toSerialize[key] = serializer.serializeToString(object[key]); |
{ | ||
"name": "@lowdefy/helpers", | ||
"version": "4.0.0-alpha.5", | ||
"version": "4.0.0-alpha.6", | ||
"licence": "Apache-2.0", | ||
@@ -45,5 +45,5 @@ "description": "", | ||
"devDependencies": { | ||
"@swc/cli": "0.1.52", | ||
"@swc/core": "1.2.112", | ||
"@swc/jest": "0.2.9", | ||
"@swc/cli": "0.1.55", | ||
"@swc/core": "1.2.130", | ||
"@swc/jest": "0.2.17", | ||
"jest": "27.3.1", | ||
@@ -55,3 +55,3 @@ "jest-diff": "27.3.1" | ||
}, | ||
"gitHead": "995fcdb020927f3cdc626fc99c15a2e4137bd962" | ||
"gitHead": "2530e31af795b6a3c75ac8f72c8dbe0ab5d1251b" | ||
} |
54316
17
989