# @evolis/evolis-library

> Dependencies used both in Evolis API and Evolis UI

Latest version **1.2.8** (published 2021-10-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @evolis/evolis-library
pnpm add @evolis/evolis-library
yarn add @evolis/evolis-library
bun add @evolis/evolis-library
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.8 |
| Published | 2021-10-15 |
| First published | 2021-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 30.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | EmpireDemocratiqueDuPoulpe |
| Maintainers | spoonoverlord |
| Keywords | evolis, library |

## Links

- npm: https://www.npmjs.com/package/@evolis/evolis-library
- Repository: https://github.com/EmpireDemocratiqueDuPoulpe/evolis-library
- Homepage: https://github.com/EmpireDemocratiqueDuPoulpe/evolis-library#readme
- Issues: https://github.com/EmpireDemocratiqueDuPoulpe/evolis-library/issues
- npm.io page: https://npm.io/package/@evolis/evolis-library

## Recent versions

- 1.2.8 (latest) — 2021-10-15
- 1.2.7 — 2021-10-13
- 1.2.6 — 2021-10-13
- 1.2.5 — 2021-10-08
- 1.2.4 — 2021-10-08
- 1.2.3 — 2021-10-07
- 1.2.2 — 2021-09-29
- 1.2.1 — 2021-09-20
- 1.2.0 — 2021-09-20
- 1.1.1-b — 2021-09-20
- 1.1.1 — 2021-09-20
- 1.1.0 — 2021-09-17
- 1.0.9 — 2021-09-09
- 1.0.8 — 2021-09-03
- 1.0.7 — 2021-08-30
- … 1 more at https://npm.io/package/@evolis/evolis-library/versions

## README

# Evolis Library
A simple package that groups together frequently used functions in front-end and in back-end at Evolis.

## Note
This package is marked as public and you can use it under the MIT license. But most of this stuff may be useless to you and you can probably find another good library that fits your needs.
> Warning: Breaking changes since 1.2.0

## Install
This is a  [Node.js](https://nodejs.org/en/)  module available through the  [npm registry](https://www.npmjs.com/). Installation is done using the  [`npm install`  command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):

`$ npm install --save @evolis/evolis-library`

## Usage
This module is divided into six sub-modules with "Evo" as prefix: `EvoArray`, `EvoDate`, `EvoMisc`, `EvoNumber`, `EvoObject` and `EvoString`.
Import it into your script using:

`import { EvoArray, EvoMisc, ... } from "@evolis/evolis-library";`

## EvoArray
- ### Checkers
  - **isArray(value: any)**
    - value: The value to test
    - *return: true if the value is an array*
  - **isDeepEqual(array1: Array, array2: Array, [sortBy]: String)**
    - array1: First array
    - array2: Second array
    - [sortBy]: Property name used to sort objects in the array. Two identical arrays in different order will not be equal (default: null)
    - *return: true if the value is an array*
- ### Converters
  - **toSerialComma(array: Array)**
    - array: The array to convert
    - *return: A string formatted as a serial comma*
- ### Functions
  - **shuffle(array: Array)**
    - array: The array to shuffle
		- *return: The shuffled array*

## EvoDate
- ### Checkers
  - **isDate(value: any)**
    - value: The value to test
    - *return: true if the value is a valid date*
  - **isMySQLDate(value: any)**
    - value: The value to test
    - *return: true if the value is a string with the valid MySQL date format (yyyy-mm-dd)*
- ### Converters
  - **toDate(d: any)**
    - s: The thing to convert
    - *return: A date object, null/undefined if the provided value is null/undefined and NaN if it's not convertible.*
  - **toString(date: Date, [withTime]: Bool, [locale]: String)**
    - date: The value to convert
    - [withTime]: Include time in the result (default: true)
    - [locale]: The locale used in the conversion. It may changed the returned string format (default: "fr-FR")
    - *return: A date formatted like "dd/MM/yyyy [hh:mm:ss]"*
  - **toTimeString(date: Date, [locale]: String)**
    - date: The date to convert
    - [locale]: The locale used in the conversion. It may changed the returned string format (default: "fr-FR")
    - *return: A date formatted like "hh:mm:ss"*
  - **toFieldString(date: Date)**
    - date: The value to convert
    - *return: A date formatted like "yyyy-MM-dd"*
  - **timeStrToDate(time: String, [format]: String)**
    - time: The date to convert
    - [format]: The format used for conversion (default: "hh:mm")
    - *return: A date object filled with the time string provided*
  - **secondsToReadable(seconds: Number)**
    - seconds: Seconds to convert
    - *return: The converted seconds and epoch*
- ### Functions
  - **dayDiff(start: Date, end: Date)**
    - start: Start date
    - end: End date
    - *return: How many days between these two dates*

## EvoFunctions
- ### Checkers
  - **isFunction(value: any)**
    - value: The value to test
    - *return: true if the value is a function*
- ### Functions
  - **measurePromise(func: Function)**
    - func: The function to measure
    - *return: Returns an object with perf and returned data of the measured promise*
    - *throw: Same as return but as an Error*

## EvoMisc
- ### Checkers
  - **isDefined(value: any)**
    - value: The value to test
    - *return: true if the value is not undefined or null*
  - **isEmail(value: any)**
    - value: The value to test
    - *return: true if the value is a string containing a valid email address*
  - **isPasswordSafe(value: any|[any])**
    - value: The value(s) to test
    - rules: Object with these properties:
       ```js
       {
        mustContain: {
          lowerCase: true|false (default: true),
          upperCase: true|false (default: true),
          digit: true|false (default: true),
          special: true|false (default: true),
        },
        minLength: Number (default: 8)
       }
       ```
    - *return: true if the value is a safe password*
- ### Converters
  - **bytesToReadable(bytes: Number, [decimals]: Number)**
    - bytes: Bytes to convert
    - [decimals]: How many decimals (default: 2)
    - *return: The converted bytes size to the closest unit*
- ### Functions
  - **padLeft(value: any, [pad]: String)**
    - value: The value to pad
    - [pad]: With what to pad (default: "00")
    - *return: The padded string*
	- **asOptions(data: Array, nameProp: String|Function, [valueProp])**
		- data: The data array to transform
		- nameProp: What prop name to use for the name
		- [valueProp]: What prop name to use for the value. If null, use nameProp instead
		- *return: Return the array with a name and a value prop on each item*

## EvoNumber
- ### Checkers
  - **isNumber(value: any, [parse]: Bool)**
	  - value: The value to test
	  - [parse]: If set to true, the function will parse the value to find a integer (base 10) (default: false)
	  - *return: true if the value is a number*
  - **isFloat(value: any, [parse]: Bool)**
    - value: The value to test
    - [parse]: If set to true, the function will parse the value to find a float (default: false)
    - *return: true if the value is a float*

## EvoObject
- ### Checkers
	- **isDeepEqual(obj1: Object, obj2: Object)**
		- obj1: First object
		- obj2: Second object
		- *return: true if the two objects are deeply equal*

## EvoString
- ### Checkers
  - **isString(value: any)**
	  - value: The value to test
	  - *return: true if the value is a string*
  - **isEmpty(value: any)**
	  - value: The value to test
	  - *return: true if the value is a string and if its empty*
  - **isBlank(value: any)**
    - value: The value to test
    - *return: true if the value is a string and if its blank*
	- **isNotBlank(value: any)**
		- value: The value to test
		- *return: true if the value is a string and if its not blank*
  - **inRange(value: any|[any], [min]: Number, [max]: Number, [includeBounds]: Bool, [canBeNull]: Bool)**
	  - value: The value(s) to test
	  - [min]: Minimum string length (default: null)
	  - [max]: Maximum string length (default: null)
	  - [includeBounds]: Include the min and max bounds in the range (default: true)
	  - [canBeNull]: Authorize or not the string to be null or undefined (default: false)
	  - *return: true if the value is a string between min and max or if it's an undefined/null with canBeNull set at true*

## License

[MIT](https://github.com/EmpireDemocratiqueDuPoulpe/evolis-library/blob/main/LICENSE).

---
_Source: https://npm.io/package/@evolis/evolis-library · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
