Comparing version 1.0.0 to 1.0.1
57
index.js
@@ -39,1 +39,58 @@ export function setValueToState(params) { | ||
} | ||
const parsePath = function(path) { | ||
if (typeof path !== "string") return path; | ||
let paths = path | ||
.replace(/\[/g, ".") | ||
.replace(/\]/g, ".") | ||
.split("."); | ||
return paths; | ||
}; | ||
class Jter { | ||
constructor(ins) { | ||
this.ins = ins; | ||
} | ||
get(path) { | ||
const paths = Array.isArray(path) ? path : parsePath(path); | ||
try { | ||
let value = this.ins; | ||
paths.forEach(item => { | ||
value = value[item]; | ||
}); | ||
return value; | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} | ||
getJ(path) { | ||
const value = this.get(path); | ||
return new Jter(value); | ||
} | ||
set(path, val) { | ||
if (typeof this.ins !== "object") return false; | ||
const paths = parsePath(path); | ||
let value = this.ins; | ||
const lastKey = paths.pop(); | ||
paths.forEach(item => { | ||
if (!value[item]) value[item] = {}; | ||
value = value[item]; | ||
}); | ||
value[lastKey] = val; | ||
return true; | ||
} | ||
delete(path) { | ||
const paths = parsePath(path); | ||
const lastKey = paths.pop(); | ||
const target = this.get(paths); | ||
if (typeof target === "object" && target[lastKey] !== undefined) | ||
delete target[lastKey]; | ||
} | ||
value() { | ||
return this.ins; | ||
} | ||
} | ||
export function jter(ins) { | ||
return new Jter(ins); | ||
} |
{ | ||
"name": "ant-ai", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Common tools for AI-FE.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,1 +6,3 @@ ## functions | ||
#### asyncClass | ||
#### jter |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2695
91
8