number-helper-functions
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -123,2 +123,13 @@ export declare type NumberLike = string | number | null | undefined; | ||
/** | ||
* Creates a range between start and end, including them, according to step | ||
* | ||
* @static | ||
* @param {number} start Starting value | ||
* @param {number} end End value | ||
* @param {number} step Step to use for the range | ||
* @return {number[]} The range | ||
* @memberof NumberHelper | ||
*/ | ||
static rangeBetween(start: number, end: number, step: number): number[]; | ||
/** | ||
* Converts to number | ||
@@ -125,0 +136,0 @@ * @private |
@@ -218,2 +218,34 @@ 'use strict'; | ||
/** | ||
* Creates a range between start and end, including them, according to step | ||
* | ||
* @static | ||
* @param {number} start Starting value | ||
* @param {number} end End value | ||
* @param {number} step Step to use for the range | ||
* @return {number[]} The range | ||
* @memberof NumberHelper | ||
*/ | ||
; | ||
NumberHelper.rangeBetween = function rangeBetween(start, end, step) { | ||
var stepIsBiggerThanDifference = step > end - start; | ||
var stepIsZero = step === 0; | ||
var numberOfItems = (end - start) / step; | ||
var stepWillNotCoverRange = NumberHelper.isFloat(numberOfItems); | ||
if (start > end) { | ||
throw new Error('Start should be smaller than end'); | ||
} | ||
if (stepIsBiggerThanDifference || stepIsZero || stepWillNotCoverRange) { | ||
throw new Error('Invalid step value'); | ||
} // eslint-disable-next-line @typescript-eslint/naming-convention | ||
return Array(numberOfItems + 1).fill(0).map(function (_, index) { | ||
var valueToAdd = step * index; | ||
return NumberHelper.processNumber(start + valueToAdd, NumberHelper.checkDecimals(step)); | ||
}); | ||
} | ||
/** | ||
* Converts to number | ||
@@ -220,0 +252,0 @@ * @private |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(){function r(){}return r.isNumber=function(e){return!isNaN(r.enforceNumber(e))},r.isInt=function(e){return!!r.isNumber(e)&&r.enforceNumber(e)%1==0},r.isFloat=function(e){return!!r.isNumber(e)&&r.enforceNumber(e).toString().includes(".")},r.isEven=function(e){return r.enforceNumber(e)%2==0},r.isOdd=function(e){return r.enforceNumber(e)%2!=0},r.isFinite=function(r){function e(e){return r.apply(this,arguments)}return e.toString=function(){return r.toString()},e}((function(e){return isFinite(r.enforceNumber(e))})),r.isPrime=function(r){return r>1&&Array(Math.floor(Math.sqrt(r))-1).fill(0).map((function(r,e){return e+2})).every((function(e){return r%e!=0}))},r.getRandom=function(r,e){return Math.floor(Math.random()*(e-r+1))+r},r.prefixWithZeros=function(r,e){return String(r).padStart(e,"0")},r.checkDecimals=function(e){if(r.isNumber(e)){var n=r.enforceNumber(e).toString().split(".").pop();return void 0!==n?n.length:0}throw new Error("Entered number is NaN")},r.convertToNumber=function(e,n){void 0===n&&(n=2);var t=0;return r.isInt(e)?t=r.enforceNumber(e):r.isFloat(e)&&(t=r.enforceNumber(r.enforceNumber(e).toFixed(n))),t},r.processNumber=function(e,n){return void 0===n&&(n=2),r.convertToNumber(e,n)},r.enforceNumber=function(r){return Number(r)},r}(); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(){function r(){}return r.isNumber=function(e){return!isNaN(r.enforceNumber(e))},r.isInt=function(e){return!!r.isNumber(e)&&r.enforceNumber(e)%1==0},r.isFloat=function(e){return!!r.isNumber(e)&&r.enforceNumber(e).toString().includes(".")},r.isEven=function(e){return r.enforceNumber(e)%2==0},r.isOdd=function(e){return r.enforceNumber(e)%2!=0},r.isFinite=function(r){function e(e){return r.apply(this,arguments)}return e.toString=function(){return r.toString()},e}((function(e){return isFinite(r.enforceNumber(e))})),r.isPrime=function(r){return r>1&&Array(Math.floor(Math.sqrt(r))-1).fill(0).map((function(r,e){return e+2})).every((function(e){return r%e!=0}))},r.getRandom=function(r,e){return Math.floor(Math.random()*(e-r+1))+r},r.prefixWithZeros=function(r,e){return String(r).padStart(e,"0")},r.checkDecimals=function(e){if(r.isNumber(e)){var n=r.enforceNumber(e).toString().split(".").pop();return void 0!==n?n.length:0}throw new Error("Entered number is NaN")},r.convertToNumber=function(e,n){void 0===n&&(n=2);var t=0;return r.isInt(e)?t=r.enforceNumber(e):r.isFloat(e)&&(t=r.enforceNumber(r.enforceNumber(e).toFixed(n))),t},r.processNumber=function(e,n){return void 0===n&&(n=2),r.convertToNumber(e,n)},r.rangeBetween=function(e,n,t){var u=t>n-e,o=0===t,i=(n-e)/t,c=r.isFloat(i);if(e>n)throw new Error("Start should be smaller than end");if(u||o||c)throw new Error("Invalid step value");return Array(i+1).fill(0).map((function(n,u){return r.processNumber(e+t*u,r.checkDecimals(t))}))},r.enforceNumber=function(r){return Number(r)},r}(); | ||
//# sourceMappingURL=number-helper-functions.cjs.production.min.js.map |
@@ -214,2 +214,34 @@ /** | ||
/** | ||
* Creates a range between start and end, including them, according to step | ||
* | ||
* @static | ||
* @param {number} start Starting value | ||
* @param {number} end End value | ||
* @param {number} step Step to use for the range | ||
* @return {number[]} The range | ||
* @memberof NumberHelper | ||
*/ | ||
; | ||
NumberHelper.rangeBetween = function rangeBetween(start, end, step) { | ||
var stepIsBiggerThanDifference = step > end - start; | ||
var stepIsZero = step === 0; | ||
var numberOfItems = (end - start) / step; | ||
var stepWillNotCoverRange = NumberHelper.isFloat(numberOfItems); | ||
if (start > end) { | ||
throw new Error('Start should be smaller than end'); | ||
} | ||
if (stepIsBiggerThanDifference || stepIsZero || stepWillNotCoverRange) { | ||
throw new Error('Invalid step value'); | ||
} // eslint-disable-next-line @typescript-eslint/naming-convention | ||
return Array(numberOfItems + 1).fill(0).map(function (_, index) { | ||
var valueToAdd = step * index; | ||
return NumberHelper.processNumber(start + valueToAdd, NumberHelper.checkDecimals(step)); | ||
}); | ||
} | ||
/** | ||
* Converts to number | ||
@@ -216,0 +248,0 @@ * @private |
{ | ||
"name": "number-helper-functions", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Helper with multiple number-related methods", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
113
README.md
# number-helper-functions | ||
Library with multiple number-related methods. | ||
## Installation | ||
### Using npm | ||
`npm i number-helper-functions` | ||
### Using yarn | ||
`yarn add number-helper-functions` | ||
## Usage | ||
### In a CommonJS env | ||
```javascript | ||
const NumberHelper = require('number-helper-functions'); | ||
NumberHelper.isInt(4); // returns true | ||
``` | ||
or | ||
```javascript | ||
const { isFinite } = require('number-helper-functions'); | ||
NumberHelper.isFinite(Infinity); // returns false | ||
``` | ||
### Using ES6 imports | ||
```javascript | ||
import NumberHelper from 'number-helper-functions'; | ||
NumberHelper.isInt(4); // returns true | ||
``` | ||
or | ||
```javascript | ||
import { processNumber } from 'number-helper-functions'; | ||
NumberHelper.processNumber('4.5432', 2); // returns 4.54 | ||
``` | ||
## Documentation | ||
## Table of contents | ||
### Classes | ||
- [default](#) | ||
### Type aliases | ||
- [NumberLik#numberlike) | ||
- [NumberLike](#numberlike) | ||
@@ -15,3 +67,3 @@ ## Type aliases | ||
Defined in: index.ts:1 | ||
Defined in: [index.ts:1](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L1) | ||
@@ -45,2 +97,3 @@ # Class: default | ||
- [processNumber](#processnumber) | ||
- [rangeBetween](#rangebetween) | ||
@@ -51,5 +104,5 @@ ## Constructors | ||
\+ **new default**(): [_default_]() | ||
\+ **new default**(): [_default_](#) | ||
**Returns:** [_default_]() | ||
**Returns:** [_default_](#) | ||
@@ -78,3 +131,3 @@ ## Methods | ||
Defined in: index.ts:146 | ||
Defined in: [index.ts:146](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L146) | ||
@@ -104,3 +157,3 @@ --- | ||
Defined in: index.ts:165 | ||
Defined in: [index.ts:165](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L165) | ||
@@ -129,3 +182,3 @@ --- | ||
Defined in: index.ts:196 | ||
Defined in: [index.ts:228](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L228) | ||
@@ -155,3 +208,3 @@ --- | ||
Defined in: index.ts:122 | ||
Defined in: [index.ts:122](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L122) | ||
@@ -181,3 +234,3 @@ --- | ||
Defined in: index.ts:64 | ||
Defined in: [index.ts:64](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L64) | ||
@@ -206,3 +259,3 @@ --- | ||
Defined in: index.ts:89 | ||
Defined in: [index.ts:89](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L89) | ||
@@ -231,3 +284,3 @@ --- | ||
Defined in: index.ts:47 | ||
Defined in: [index.ts:47](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L47) | ||
@@ -256,3 +309,3 @@ --- | ||
Defined in: index.ts:31 | ||
Defined in: [index.ts:31](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L31) | ||
@@ -281,3 +334,3 @@ --- | ||
Defined in: index.ts:19 | ||
Defined in: [index.ts:19](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L19) | ||
@@ -307,3 +360,3 @@ --- | ||
Defined in: index.ts:77 | ||
Defined in: [index.ts:77](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L77) | ||
@@ -333,3 +386,3 @@ --- | ||
Defined in: index.ts:102 | ||
Defined in: [index.ts:102](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L102) | ||
@@ -359,3 +412,3 @@ --- | ||
Defined in: index.ts:135 | ||
Defined in: [index.ts:135](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L135) | ||
@@ -385,2 +438,28 @@ --- | ||
Defined in: index.ts:184 | ||
Defined in: [index.ts:184](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L184) | ||
--- | ||
### rangeBetween | ||
▸ `Static`**rangeBetween**(`start`: _number_, `end`: _number_, `step`: _number_): _number_[] | ||
Creates a range between start and end, including them, according to step | ||
**`static`** | ||
**`memberof`** NumberHelper | ||
#### Parameters: | ||
| Name | Type | Description | | ||
| :------ | :------- | :------------------------ | | ||
| `start` | _number_ | Starting value | | ||
| `end` | _number_ | End value | | ||
| `step` | _number_ | Step to use for the range | | ||
**Returns:** _number_[] | ||
The range | ||
Defined in: [index.ts:198](https://github.com/alrico88/number-helper-functions/blob/8a2bab7/src/index.ts#L198) |
@@ -189,2 +189,34 @@ export type NumberLike = string | number | null | undefined; | ||
/** | ||
* Creates a range between start and end, including them, according to step | ||
* | ||
* @static | ||
* @param {number} start Starting value | ||
* @param {number} end End value | ||
* @param {number} step Step to use for the range | ||
* @return {number[]} The range | ||
* @memberof NumberHelper | ||
*/ | ||
public static rangeBetween(start: number, end: number, step: number): number[] { | ||
const stepIsBiggerThanDifference = step > end - start; | ||
const stepIsZero = step === 0; | ||
const numberOfItems = (end - start) / step; | ||
const stepWillNotCoverRange = NumberHelper.isFloat(numberOfItems); | ||
if (start > end) { | ||
throw new Error('Start should be smaller than end'); | ||
} | ||
if (stepIsBiggerThanDifference || stepIsZero || stepWillNotCoverRange) { | ||
throw new Error('Invalid step value'); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
return Array(numberOfItems + 1).fill(0).map((_, index) => { | ||
const valueToAdd = step * index; | ||
return NumberHelper.processNumber(start + valueToAdd, NumberHelper.checkDecimals(step)); | ||
}); | ||
} | ||
/** | ||
* Converts to number | ||
@@ -191,0 +223,0 @@ * @private |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
70208
842
450
0
12