A lightweight library that provides simple validation and conversion JavaScript functions to make your code more intuitive and readable.
npm install readablefn
- adds the library to your project.
Feel free to import the modules you need using import
or require
.
import { isNotNull } from 'readablefn/base';
import { Numbers } from 'readablefn';
const value = 5;
if (isNotNull(value)&& Numbers.isNumber(value) && Numbers.inRange(value, { start: 1, end: 10 })) {
console.log('Value is a valid number in range!');
}
Function | Description | Example |
---|---|---|
isNull | Checks if value is null or undefined |
isNull(null) -> true isNull(1) -> false |
isNotNull | Checks if value is not null or undefined |
isNotNull(1) -> true isNotNull(null) -> false |
isUndefined | Checks if value is undefined |
isUndefined(undefined) -> true isUndefined(0) -> false |
isNotUndefined | Checks if value is not undefined |
isNotUndefined(1) -> true isNotUndefined(undefined) -> false |
Function | Description | Example |
---|---|---|
isString | Checks if value is a string | isString('abc') -> true isString(123) -> false |
isEmpty | Checks if value is empty ('' , null , undefined ) |
isEmpty('') -> true isEmpty('abc') -> false |
isNotEmpty | Checks if value is not empty | isNotEmpty('abc') -> true isNotEmpty('') -> false |
Function | Description | Example |
---|---|---|
isNumber | Checks if value is a number (not NaN, not Infinity) | isNumber(5) -> true isNumber('5') -> false |
isNotNumber | Checks if value is not a number | isNotNumber('abc') -> true isNotNumber(5) -> false |
inRange | Checks if number is in the given range | inRange(5, {start: 1, end: 10}) -> true inRange(0, {start: 1, end: 10}) -> false |
You are welcome to contribute to this library.
- Node.js with NPM
npm ci
- install dependenciesnpm test
- run build and tests
NOTE: Please submit your PRs to the
develop
branch.