@aryth/bound-vector
Advanced tools
Comparing version 0.1.9 to 0.1.10
@@ -6,2 +6,3 @@ 'use strict'; | ||
var utilBound = require('@aryth/util-bound'); | ||
var enumCheckLevels = require('@typen/enum-check-levels'); | ||
@@ -18,19 +19,17 @@ const iniNumEntry = (ar, lo, hi, { | ||
* | ||
* @param {*[]} arr | ||
* @param {boolean} [dif=false] | ||
* @param {number} [level=0] 0:no check, 1:loose, 2:strict | ||
* @param {*[]} vec | ||
* @returns {{min: *, max: *}|{min: *, dif: *}}} | ||
*/ | ||
function bound(arr, { | ||
dif = false, | ||
level = utilBound.NUM_LEVEL_NONE | ||
} = {}) { | ||
const bo = utilBound.BoundOutput(dif), | ||
toNum = utilBound.ToNum(level); | ||
let l = arr && arr.length; | ||
if (!l) return bo(NaN, NaN); | ||
let [i, x] = iniNumEntry(arr, 0, l, { | ||
level | ||
}); | ||
function bound(vec) { | ||
/** @type {{dif: boolean, level: number}} */ | ||
const config = this || { | ||
dif: false, | ||
level: enumCheckLevels.LOOSE | ||
}; | ||
const toOutput = utilBound.boundOutput.bind(config), | ||
toNum = utilBound.ToNum(config.level); | ||
let l = vec === null || vec === void 0 ? void 0 : vec.length; | ||
if (!l) return toOutput(NaN, NaN); | ||
let [i, x] = iniNumEntry(vec, 0, l, config); | ||
let min, | ||
@@ -40,5 +39,5 @@ max = min = toNum(x); | ||
for (++i; i < l; i++) { | ||
var _arr$i; | ||
var _vec$i; | ||
if ((x = (_arr$i = arr[i], toNum(_arr$i))) < min) { | ||
if ((x = (_vec$i = vec[i], toNum(_vec$i))) < min) { | ||
min = x; | ||
@@ -50,5 +49,14 @@ } else if (x > max) { | ||
return bo(max, min); | ||
return toOutput(max, min); | ||
} | ||
function leap(vec) { | ||
/** @type {{dif: boolean, level: number}} */ | ||
const config = this || { | ||
level: enumCheckLevels.LOOSE | ||
}; | ||
config.dif = true; | ||
return bound.call(config, vec); | ||
} | ||
exports.bound = bound; | ||
exports.leap = leap; |
@@ -1,2 +0,3 @@ | ||
import { IsNum, NUM_LEVEL_NONE, BoundOutput, ToNum } from '@aryth/util-bound'; | ||
import { IsNum, boundOutput, ToNum } from '@aryth/util-bound'; | ||
import { LOOSE } from '@typen/enum-check-levels'; | ||
@@ -13,19 +14,17 @@ const iniNumEntry = (ar, lo, hi, { | ||
* | ||
* @param {*[]} arr | ||
* @param {boolean} [dif=false] | ||
* @param {number} [level=0] 0:no check, 1:loose, 2:strict | ||
* @param {*[]} vec | ||
* @returns {{min: *, max: *}|{min: *, dif: *}}} | ||
*/ | ||
function bound(arr, { | ||
dif = false, | ||
level = NUM_LEVEL_NONE | ||
} = {}) { | ||
const bo = BoundOutput(dif), | ||
toNum = ToNum(level); | ||
let l = arr && arr.length; | ||
if (!l) return bo(NaN, NaN); | ||
let [i, x] = iniNumEntry(arr, 0, l, { | ||
level | ||
}); | ||
function bound(vec) { | ||
/** @type {{dif: boolean, level: number}} */ | ||
const config = this || { | ||
dif: false, | ||
level: LOOSE | ||
}; | ||
const toOutput = boundOutput.bind(config), | ||
toNum = ToNum(config.level); | ||
let l = vec === null || vec === void 0 ? void 0 : vec.length; | ||
if (!l) return toOutput(NaN, NaN); | ||
let [i, x] = iniNumEntry(vec, 0, l, config); | ||
let min, | ||
@@ -35,5 +34,5 @@ max = min = toNum(x); | ||
for (++i; i < l; i++) { | ||
var _arr$i; | ||
var _vec$i; | ||
if ((x = (_arr$i = arr[i], toNum(_arr$i))) < min) { | ||
if ((x = (_vec$i = vec[i], toNum(_vec$i))) < min) { | ||
min = x; | ||
@@ -45,5 +44,13 @@ } else if (x > max) { | ||
return bo(max, min); | ||
return toOutput(max, min); | ||
} | ||
function leap(vec) { | ||
/** @type {{dif: boolean, level: number}} */ | ||
const config = this || { | ||
level: LOOSE | ||
}; | ||
config.dif = true; | ||
return bound.call(config, vec); | ||
} | ||
export { bound }; | ||
export { bound, leap }; |
{ | ||
"name": "@aryth/bound-vector", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "A math util library", | ||
@@ -18,3 +18,4 @@ "main": "dist/index.cjs.js", | ||
"dependencies": { | ||
"@aryth/util-bound": "^0.1.9" | ||
"@aryth/util-bound": "^0.1.10", | ||
"@typen/enum-check-levels": "^0.1.1" | ||
}, | ||
@@ -36,3 +37,3 @@ "repository": { | ||
"homepage": "https://github.com/hoyeungw/aryth#readme", | ||
"gitHead": "2ec613356e3ef3c2830d2ef3a1432b5d99925919" | ||
"gitHead": "4cd961e05a538dddd74f9433385d855ea68072c9" | ||
} |
@@ -0,0 +0,0 @@ # @aryth/bound-vector |
Sorry, the diff of this file is not supported yet
5917
93
2
Updated@aryth/util-bound@^0.1.10