Comparing version 0.2.4 to 0.2.5
@@ -10,3 +10,4 @@ import { HttpHelper } from './http'; | ||
names(value: string): string[]; | ||
getValue(name: string, source: any): any; | ||
getValue(source: any, name: string): any; | ||
setValue(source: any, name: string, value: any): void; | ||
sort(source: any): any; | ||
@@ -13,0 +14,0 @@ fromEntries(array: any[]): any; |
@@ -53,3 +53,3 @@ "use strict"; | ||
} | ||
getValue(name, source) { | ||
getValue(source, name) { | ||
const names = this.names(name); | ||
@@ -86,2 +86,32 @@ let value = source; | ||
} | ||
setValue(source, name, value) { | ||
const names = name.split('.'); | ||
const level = names.length - 1; | ||
let data = source; | ||
for (let i = 0; i < names.length; i++) { | ||
const name = names[i]; | ||
// if is an array and name is a positive integer | ||
if (Array.isArray(data) && this.validator.isPositiveInteger(name)) { | ||
const index = Number(name); | ||
// If the index exceeds the length of the array, nothing assigns it. | ||
if (index >= data.length) { | ||
return; | ||
} | ||
if (i === level) { | ||
data[index] = value; | ||
} | ||
else { | ||
data = data[index]; | ||
} | ||
} | ||
else { | ||
if (i === level) { | ||
data[name] = value; | ||
} | ||
else { | ||
data = data[name]; | ||
} | ||
} | ||
} | ||
} | ||
sort(source) { | ||
@@ -88,0 +118,0 @@ const target = {}; |
{ | ||
"name": "h3lp", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Helper for nodeJs", | ||
@@ -5,0 +5,0 @@ "author": "Flavio Lionel Rita <flaviolrita@hotmail.com>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
125442
1683