1.2.8 • Published 3 years ago

@evolis/evolis-library v1.2.8

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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 module available through the npm registry. Installation is done using the npm install command:

$ 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:
        {
         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.

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.2.1

3 years ago

1.1.1

3 years ago

1.1.1-b

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago