@appolo/utils
Advanced tools
Comparing version 8.0.33 to 8.0.34
@@ -38,2 +38,17 @@ "use strict"; | ||
} | ||
static range(start, end, increment) { | ||
const isEndDef = typeof end !== 'undefined'; | ||
end = isEndDef ? end : start; | ||
start = isEndDef ? start : 0; | ||
if (typeof increment === 'undefined') { | ||
increment = Math.sign(end - start); | ||
} | ||
const length = Math.abs((end - start) / (increment || 1)); | ||
let arr = Array.from({ length }), current = start; | ||
for (let i = 0; i < length; i++) { | ||
arr[i] = current; | ||
current = current + increment; | ||
} | ||
return arr; | ||
} | ||
static random(arr) { | ||
@@ -40,0 +55,0 @@ if (!arr || !arr.length) { |
@@ -46,2 +46,24 @@ import {Classes} from "./classes"; | ||
public static range(start: number, end?: number, increment?: number): number[] { | ||
const isEndDef = typeof end !== 'undefined' | ||
end = isEndDef ? end : start | ||
start = isEndDef ? start : 0 | ||
if (typeof increment === 'undefined') { | ||
increment = Math.sign(end - start) | ||
} | ||
const length = Math.abs((end - start) / (increment || 1)); | ||
let arr: number[] = Array.from({length}), | ||
current = start; | ||
for (let i = 0; i < length; i++) { | ||
arr[i] = current; | ||
current = current + increment | ||
} | ||
return arr | ||
} | ||
public static random<T>(arr: T[]): T { | ||
@@ -48,0 +70,0 @@ |
@@ -5,2 +5,3 @@ "use strict"; | ||
const arrays_1 = require("./arrays"); | ||
const chainObject_1 = require("./chainObject"); | ||
class Chain { | ||
@@ -141,5 +142,5 @@ constructor(_value) { | ||
function _(arr) { | ||
return new Chain(arr); | ||
return Array.isArray(arr) ? new Chain(arr) : new chainObject_1.ChainObject(arr); | ||
} | ||
exports._ = _; | ||
//# sourceMappingURL=chain.js.map |
import {Arrays} from "./arrays"; | ||
import {ChainObject} from "./chainObject"; | ||
@@ -180,5 +181,6 @@ export class Chain<K> { | ||
} | ||
export function _<K>(arr: K[]): Chain<K> { | ||
return new Chain(arr); | ||
export function _<K>(arr: K[]): Chain<K> | ||
export function _<K extends object>(arr: K): ChainObject<K> | ||
export function _<K = any>(arr: K[]): Chain<K> | ChainObject<any> { | ||
return Array.isArray(arr) ? new Chain<K>(arr) : new ChainObject<any>(arr as any) | ||
} |
@@ -20,3 +20,3 @@ { | ||
"main": "./index.js", | ||
"version": "8.0.33", | ||
"version": "8.0.34", | ||
"license": "MIT", | ||
@@ -23,0 +23,0 @@ "repository": { |
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
235689
101
4305