10.0.111 • Published 2 years ago

enigma-x-utilities v10.0.111

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Enigma X Utilities NPM version Coverage Status Bundlephobia

Features

  • URL validator: Check URL validaity & domain/path formatter
  • Tags separator: Separate tags
  • Password strength/validator: Check for password strength & validity
  • Number modifier: Modify number
  • Phone number modifier: Modify phone number
  • Number positivity checker: Check if number is negative or positive
  • IP address validation: Validate IP
  • Remove spaces: Remove spaces
  • Email domain checker: Check email domain
  • Special chars removal: Remove special chars from
  • Handle errors with success status & detailed message

CodeSandbox Example

https://codesandbox.io/s/magical-germain-w7wjv

Install

npm i enigma-x-utilities

Configuration

Configuration is optional, you can use most of the functions as they are, every optional option has default value. But if you would like to modifiy the values use the setConfig function.

const { setConfig } = require('enigma-x-utilities');

/**
 * setConfig for configuration
 * @param {configName} string function to config
 * @param {parameters} object fields to config
 * @returns void
 */
setConfig('phones', {
	format: '10',
	isInternational: true,
});

Usage

Check number positivity

Feature for checking number positivity, checks number value. Return boolean

const { checkNumberPositivity, setConfig } = require('enigma-x-utilities');

// Config Default values
setConfig('checkNumberPositivity', {
	zeroIncluded: false,
});

Success

// Checking number positivity
checkNumberPositivity(1)

// Output
{
  success: true,
  message: 'successfully processed number',
  data: true,
}

Error

// Checking number positivity
checkNumberPositivity('blbalbla')

// Output
{ success: false, message: 'blbalbla' should be type number }

Number Formatter

Feature for formatting number according to overall and decimal digits count limit.

const { numberFormatter, setConfig } = require('enigma-x-utilities');

// Config Default values
setConfig('numberFormatter', {
	overallDigitLimit: 5,
	decimalDigitLimit: 2,
	useColors: true,
	colors: {
		positive: 'green',
		negative: 'red',
	},
});

Success

numberFormatter(123456.1)

// Output

{
  success: true,
  message: 'Successfully formatted number',
  data: {
    number: '123.45K',
    color : 'green'
  }
}

Error

numberFormatter('asd')

// Output
{ success: false, message: 'Input is not a valid number' }

URL Validator

Feature for validating & formatting URL, check if URL is valid & format the URL. Return formatted URL.

const { URLValidator, setConfig } = require('enigma-x-utilities');

// Config Default values
setConfig('URLValidator', {
	domainName: false,
	pathIncluded: true,
});

Success

// Validating & formatting URL
URLValidator('https://www.youtube.com/watch?v=OLK49ZTbmWM&list=PLtK75qxsQaMLZSo7KL-PmiRarU7hrpnwK&index=5')

// Output
{
  success: true,
  message: 'Successfully modified URL',
  data: 'https://www.youtube.com/watch?v=OLK49ZTbmWM&list=PLtK75qxsQaMLZSo7KL-PmiRarU7hrpnwK&index=5'
}

Error

// Validating & formatting URL
URLValidator('blablablablo')

// Output
{ success: false, message: 'URL is invalid' }

Tags Separator

Feature for sepataring tags, Receives string and splits it into an array. Optionaly you can config the separators passing an array of chars to the config function. Return sepatarted tags array.

const { tagsSeparator, setConfig } = require('enigma-x-utilities');

//Config default values
setConfig('tagsSeparator', {
	separators: undefined,
});
setConfig('tags', {
	separators: ['$', '^', '&'],
});

Description

  • If no array of separators is passed, the function will decide what should be treated as the separator by looking for all the *special characters in the string and taking the most frequent one as the separator (if there are a couple of separators equally frequent at the top - the one that shows up first in the string is selected).

  • If the array contains only one item, the function treats it as the separtor and splits the string into tags according to it.

  • If the array contains more than one item, the array is treated as optional allowed separators. The actual separator will be the option that shows up most frequently in the passed string.

  • The array of separators may only contain *special characters. Each separator should consist of one character only.

*Special characters: any character that is not a-z, A-Z,0-9, _

Success

// Separating tags
tagsSeparator('Sun Earth Mars', [" ", ","])

// Output
{
  success: true,
  message: 'Tags array created successfully',
  data: ['Sun','Earth','Mars']
}

Error

tagsSeparator('Sun Earth Mars', ["--"])

// Output
{
  success: false,
  message: 'Separators may only include one character each',
}

Password Validation

Feature for password validation ,check if password is valid based on configuration, and the strength of it. Return object after validation is succeed.

configuration

const { passwordValidation, setConfig } = require('enigma-x-utilities');

//Config default values
setConfig('passwordValidation', {
	strengthOptions: [
		{
			value: 1,
			minDiversity: 1,
			minLength: 8,
		},

		{
			value: 'Medium',
			minDiversity: 3,
			minLength: 10,
		},

		{
			value: 'Strong',
			minDiversity: 4,
			minLength: 12,
		},
	],
	characterLen: 12,
	upperCase: 1,
	lowerCase: 1,
	num: 1,
	symbol: '#?!@$%^&*-',
});

Success

//Validating the password.
passwordValidation("112412$@Aa")

//Output

{
  validation: [
    { title: 'Char', valid: true, re: /^.{12,}$/ },
    { title: 'UpperCase', valid: true, re: /^(.*?[A-Z]){1,}/ },
    { title: 'LowerCase', valid: true, re: /^(.*?[a-z]){1,}/ },
    { title: 'Number', valid: true, re: /^(.*?[0-9]){1,}/ },
    {
      title: 'NonAlphaNumeric',
      valid: true,
      re: /^(.*?[#?!@$%^&*-,])/
    }
  ],
  strength:"Weak"
}

Error

//Error will happend if one of the value's of the default value is incorrect.
{
  validation: [
    { title: 'Char', valid: true, re: /^.{12,}$/ },
    { title: 'UpperCase', valid: true, re: /^(.*?[A-Z]){1,}/ },
    { title: 'LowerCase', valid: true, re: /^(.*?[a-z]){1,}/ },
    { title: 'Number', valid: true, re: /^(.*?[0-9]){1,}/ },
    {
      title: 'NonAlphaNumeric',
      valid: true,
      re: /^(.*?[#?!@$%^&*-,])/
    }
  ],
  //this Error happend when the default value at the strength config set to argument that not string.
  strength: { success: false, message: [ 'value must be type of string' ] }
}

Phone number validator

Feature for international phone number validation ,check if the phone number is valid based on the input, And reformat the phone number by user configuration.

const { phoneNumberFormatter, setConfig } = require('enigma-x-utilities');

// Config Default values
setConfig('phoneNumberFormatter', {
	format: '3-3-3-4',
	isInternational: true,
});

Success

// Validating & formatting phone number
phoneNumberFormatter('255-777-4708834')

// Output
{
  success: true,
  message: 'Phone number successfully formatted',
  data: '255-777-470-8834'
}

Error

// Validating & formatting phone number
phoneNumberFormatter('255-777-470')

// Output
{ success: false, message: 'Format does not match the number of digits in phone number' }

Special chars modifier

configuration

const { specialCharsModifier, setConfig } = require('enigma-x-utilities');

//you can call the function without configuration it . and then all the special chars in your string will be deleted.
//You can config this function to filter which chars you want to still appear.

setConfig('specialCharsModifier', '@');

Success

specialCharsModifier('12#$3%4567');
//Output
{success:true,
message:"String modify successfully
data:string
}

Error

specialCharsModifier(123$4%^&)
//Output
{success:false,message:"123$4%^& must be a string"}

Ip validation

Configuration

const { ipValidation } = require('enigma-x-utilities');

Success

ipValidation('130.75.164.95');
//Output
{success:true,message:ip is valid}

Error

ipValidation('130.75.164');
//Output
{success:false,message:ip is not valid}

Email domain validator

Feature for testing if inserted email input is contained inside a list of approved domains.

const { emailDomainValidator, setConfig } = require('enigma-x-utilities');

// Config Default values
setConfig('emailDomainValidator', {
	domainList: ['gmail.com', 'yahoo.com', 'blabla.co.il'],
});

Success

// Validating email input
emailDomainValidator('eli@yahoo.com')

// Output
{
  success: true,
  message: 'Email inserted is valid',
  data: true
  }

Error

// Validating email outside list of domains
emailDomainValidator('eli@capital.com')

// Output
{ success: false, message: 'Email inserted is not in domain list' }

Space Remover

Feature for removing unneeded whitespace from text. Receives a string and returns a string.

const { removeSpaces } = require('enigma-x-utilities');

Description

  • removeSpaces removes whitespace of any sort before and after text; removes more than one whitespace between words and any whitespace between words and punctuation marks.

Success

// Removing unneeded spaces
removeSpaces('user      sends empty separators array, string is split according to most frequent char')

// Output
{
  success: true,
  message: 'Spaces removed successfully',
  data: 'user sends empty separators array, string is split according to most frequent char'
}
10.0.111

2 years ago

10.0.110

2 years ago

10.0.109

2 years ago

10.0.107

2 years ago

10.0.106

2 years ago

10.0.105

2 years ago

10.0.104

2 years ago

10.0.103

2 years ago

10.0.102

2 years ago

10.0.101

2 years ago

10.0.100

2 years ago

10.0.99

2 years ago

10.0.98

2 years ago

10.0.97

2 years ago

10.0.96

2 years ago

10.0.95

2 years ago

10.0.94

2 years ago

10.0.93

2 years ago

10.0.92

2 years ago

10.0.91

2 years ago

10.0.90

2 years ago

10.0.89

2 years ago

10.0.88

2 years ago

10.0.87

2 years ago

10.0.86

2 years ago

10.0.85

2 years ago

10.0.84

2 years ago

1.0.83

2 years ago

1.0.82

2 years ago

1.0.81

2 years ago

1.0.80

2 years ago

1.0.79

2 years ago

1.0.78

2 years ago

1.0.77

2 years ago

1.0.76

2 years ago

1.0.75

2 years ago

1.0.74

2 years ago

1.0.73

2 years ago

1.0.72

2 years ago

1.0.71

2 years ago

1.0.70

2 years ago

1.0.69

2 years ago

1.0.68

2 years ago

1.0.67

2 years ago

1.0.66

2 years ago

1.0.65

2 years ago

1.0.64

2 years ago

1.0.63

2 years ago

1.0.62

2 years ago

1.0.61

2 years ago

1.0.60

2 years ago

1.0.59

2 years ago

1.0.58

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.55

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.0.48

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.44

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.40

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago