Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@leafer/data

Package Overview
Dependencies
Maintainers
1
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafer/data - npm Package Compare versions

Comparing version
1.8.0
to
1.9.0
+48
src/data.ts
import { IObject } from '@leafer/interface'
export enum Answer {
No = 0,
Yes = 1,
NoAndSkip = 2,
YesAndSkip = 3
}
export const emptyData: IObject = {}
export function isUndefined(value: any): boolean {
return value === undefined
}
export function isNull(value: any): boolean {
return value === undefined || value === null
}
export function isString<T extends string>(value: any): value is T {
return typeof value === 'string'
}
export const { isFinite } = Number
export function isNumber<T extends number>(value: any): value is T {
return typeof value === 'number'
}
const numberReg = /^-?\d+(?:\.\d+)?$/
export function tryToNumber(value: any): number {
return (typeof value === 'string' && numberReg.test(value)) ? +value : value
}
export const { isArray } = Array
export function isObject<T extends object>(value: any): value is T {
return value && typeof value === 'object' // fix: null is object
}
export function isData<T extends object>(value: any): value is T { // 检测 {} 对象
return isObject(value) && !isArray(value) // 排除数组
}
export function isEmptyData(value: any): boolean {
return JSON.stringify(value) === '{}'
}
+2
-2
{
"name": "@leafer/data",
"version": "1.8.0",
"version": "1.9.0",
"description": "@leafer/data",

@@ -25,4 +25,4 @@ "author": "Chao (Leafer) Wan",

"devDependencies": {
"@leafer/interface": "1.8.0"
"@leafer/interface": "1.9.0"
}
}
import { IBooleanMap, IObject } from '@leafer/interface'
import { isUndefined } from './data'
export const DataHelper = {

@@ -27,3 +27,3 @@

include.forEach(key => {
if (from[key] !== undefined) t[key] = from[key]
if (!isUndefined(from[key])) t[key] = from[key]
})

@@ -30,0 +30,0 @@ return t

@@ -1,21 +0,3 @@

import { IObject } from '@leafer/interface'
export { DataHelper } from './DataHelper'
export { LeafData } from './LeafData'
export enum Answer {
No = 0,
Yes = 1,
NoAndSkip = 2,
YesAndSkip = 3
}
export const emptyData: IObject = {}
export function isNull(value: any): boolean {
return value === undefined || value === null
}
export function isEmptyData(value: any): boolean {
return JSON.stringify(value) === '{}'
}
export { Answer, emptyData, isUndefined, isNull, isString, isFinite, isNumber, isArray, isObject, isData, isEmptyData, tryToNumber } from './data'
import { ILeafData, ILeaf, IObject, IValue, IPathCommandData, IJSONOptions } from '@leafer/interface'
import { isArray, isUndefined } from './data'

@@ -38,3 +39,3 @@

const value = this.__input[name]
if (value !== undefined) return value
if (!isUndefined(value)) return value
}

@@ -50,3 +51,3 @@ return (this as IObject)[name]

inputValue = __input ? __input[key] : undefined
data[key] = (inputValue === undefined) ? this[key] : inputValue
data[key] = isUndefined(inputValue) ? this[key] : inputValue
}

@@ -65,3 +66,3 @@ }

const value = this.__input[name]
if (value !== undefined) return value
if (!isUndefined(value)) return value
}

@@ -75,3 +76,3 @@

public __removeInput(name: string): void {
if (this.__input && this.__input[name] !== undefined) this.__input[name] = undefined
if (this.__input && !isUndefined(this.__input[name])) this.__input[name] = undefined
}

@@ -84,3 +85,3 @@

if (names instanceof Array) {
if (isArray(names)) {
for (let name of names) data[name] = this.__getInput(name)

@@ -98,3 +99,3 @@ } else {

value = (this as IObject)['_' + key]
if (value !== undefined) {
if (!isUndefined(value)) {

@@ -104,3 +105,3 @@ if (key === 'path' && !(this as ILeafData).__pathInputed) continue // no path mode

inputValue = __input ? __input[key] : undefined
data[key] = (inputValue === undefined) ? value : inputValue
data[key] = isUndefined(inputValue) ? value : inputValue
}

@@ -107,0 +108,0 @@ }

@@ -45,5 +45,13 @@ import { IObject, IBooleanMap, ILeafData, ILeaf, IPathCommandData, IJSONOptions } from '@leafer/interface';

declare const emptyData: IObject;
declare function isUndefined(value: any): boolean;
declare function isNull(value: any): boolean;
declare function isString<T extends string>(value: any): value is T;
declare const isFinite: (number: unknown) => boolean;
declare function isNumber<T extends number>(value: any): value is T;
declare function tryToNumber(value: any): number;
declare const isArray: (arg: any) => arg is any[];
declare function isObject<T extends object>(value: any): value is T;
declare function isData<T extends object>(value: any): value is T;
declare function isEmptyData(value: any): boolean;
export { Answer, DataHelper, LeafData, emptyData, isEmptyData, isNull };
export { Answer, DataHelper, LeafData, emptyData, isArray, isData, isEmptyData, isFinite, isNull, isNumber, isObject, isString, isUndefined, tryToNumber };