appolo-utils
Advanced tools
Comparing version 0.0.57 to 0.0.58
@@ -9,4 +9,20 @@ "use strict"; | ||
static arrayify(val) { | ||
return Array.isArray(val) ? val : [val]; | ||
return val ? (Array.isArray(val) ? val : [val]) : []; | ||
} | ||
static nullifyEmptyArray(arr) { | ||
return (arr && arr.length) ? arr : null; | ||
} | ||
static areArraysEqual(arrA, arrB) { | ||
const a = new Set(arrA); | ||
const b = new Set(arrB); | ||
if (a.size !== b.size) { | ||
return false; | ||
} | ||
for (let k of a) { | ||
if (!b.has(k)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
static compact(array) { | ||
@@ -13,0 +29,0 @@ let index = -1, length = array == null ? 0 : array.length, resIndex = 0, result = []; |
@@ -9,5 +9,24 @@ import {Classes} from "./classes"; | ||
public static arrayify<T>(val: any): T[] { | ||
return Array.isArray(val) ? val : [val]; | ||
return val ? (Array.isArray(val) ? val : [val]) : []; | ||
} | ||
public static nullifyEmptyArray<T>(arr: T[]): T[] { | ||
return (arr && arr.length) ? arr : null; | ||
} | ||
public static areArraysEqual(arrA: any[], arrB: any[]): boolean { | ||
const a = new Set(arrA); | ||
const b = new Set(arrB); | ||
if (a.size !== b.size) { | ||
return false; | ||
} | ||
for (let k of a) { | ||
if (!b.has(k)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
public static compact<T>(array: T[]): T[] { | ||
@@ -14,0 +33,0 @@ let index = -1, |
@@ -21,2 +21,5 @@ "use strict"; | ||
} | ||
static isNumber(str) { | ||
return (typeof str === 'number' || str instanceof Number); | ||
} | ||
static randomInt(min, max) { | ||
@@ -34,4 +37,16 @@ if (max === undefined) { | ||
} | ||
static round(value, step) { | ||
step || (step = 1.0); | ||
let inv = 1.0 / step; | ||
return Math.round(value * inv) / inv; | ||
} | ||
static diff(a, b) { | ||
if (a === 0) { | ||
return 0; | ||
} | ||
const diff = a - b; | ||
return diff / a; | ||
} | ||
} | ||
exports.Numbers = Numbers; | ||
//# sourceMappingURL=numbers.js.map |
@@ -25,2 +25,6 @@ export class Numbers { | ||
public static isNumber(str: any): str is String { | ||
return (typeof str === 'number' || str instanceof Number); | ||
} | ||
public static randomInt(min: number, max?: number): number { | ||
@@ -42,2 +46,16 @@ | ||
} | ||
public static round(value: number, step: number): number { | ||
step || (step = 1.0); | ||
let inv = 1.0 / step; | ||
return Math.round(value * inv) / inv; | ||
} | ||
public static diff(a: number, b: number): number { | ||
if (a === 0) { | ||
return 0; | ||
} | ||
const diff = a - b; | ||
return diff / a; | ||
} | ||
} |
@@ -111,4 +111,19 @@ "use strict"; | ||
} | ||
static set(obj, path, value) { | ||
if (!obj) { | ||
return; | ||
} | ||
const parts = path.split('.'); | ||
let current = obj; | ||
for (let i = 0, len = parts.length; i < len - 1; i++) { | ||
const part = parts[i]; | ||
if (!current[part]) { | ||
current[part] = {}; | ||
} | ||
current = current[part]; | ||
} | ||
current[parts[parts.length - 1]] = value; | ||
} | ||
} | ||
exports.Objects = Objects; | ||
//# sourceMappingURL=objects.js.map |
@@ -153,2 +153,18 @@ import {Arrays} from "./arrays"; | ||
public static set(obj: any, path: string, value: any) { | ||
if (!obj) { | ||
return; | ||
} | ||
const parts = path.split('.'); | ||
let current = obj; | ||
for (let i = 0, len = parts.length; i < len - 1; i++) { | ||
const part = parts[i]; | ||
if (!current[part]) { | ||
current[part] = {}; | ||
} | ||
current = current[part]; | ||
} | ||
current[parts[parts.length - 1]] = value; | ||
} | ||
} |
@@ -33,4 +33,25 @@ "use strict"; | ||
} | ||
static serializeToQueryString(obj) { | ||
let keys = Object.keys(obj || {}); | ||
let output = []; | ||
for (let i = 0, length = keys.length; i < length; i++) { | ||
let key = keys[i]; | ||
output.push(`${key}=${obj[key]}`); | ||
} | ||
return output.join('&'); | ||
} | ||
static convertStringToFloatArray(str) { | ||
if (!str) { | ||
return []; | ||
} | ||
let output = []; | ||
let arr = str.split(","); | ||
for (let i = 0, length = arr.length; i < length; i++) { | ||
let int = parseFloat(arr[i]); | ||
!isNaN(int) && output.push(int); | ||
} | ||
return output; | ||
} | ||
} | ||
exports.Strings = Strings; | ||
//# sourceMappingURL=strings.js.map |
@@ -41,2 +41,33 @@ import {Functions} from "../index"; | ||
} | ||
public static serializeToQueryString(obj: any): string { | ||
let keys = Object.keys(obj || {}); | ||
let output = []; | ||
for (let i = 0, length = keys.length; i < length; i++) { | ||
let key = keys[i]; | ||
output.push(`${key}=${obj[key]}`); | ||
} | ||
return output.join('&'); | ||
} | ||
public static convertStringToFloatArray(str: string): number[] { | ||
if (!str) { | ||
return []; | ||
} | ||
let output = []; | ||
let arr = str.split(","); | ||
for (let i = 0, length = arr.length; i < length; i++) { | ||
let int = parseFloat(arr[i]); | ||
!isNaN(int) && output.push(int); | ||
} | ||
return output; | ||
} | ||
} |
@@ -17,3 +17,3 @@ { | ||
"main": "./index.js", | ||
"version": "0.0.57", | ||
"version": "0.0.58", | ||
"license": "MIT", | ||
@@ -20,0 +20,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
125489
2271