npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

enigma-x-utilities

v10.0.111

Published

EnigmaX NPM utilities package

Downloads

126

Readme

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('[email protected]')

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

Error

// Validating email outside list of domains
emailDomainValidator('[email protected]')

// 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'
}