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

@rigu/js-toolkit

v1.0.8

Published

A collection of JavaScript utilities for strings, objects and arrays.

Downloads

31

Readme

js-toolkit

npm package

A set of JavaScript utils to check and manage javascript string, array and object (with TypeScript typings)

# NPM
npm install @rigu/js-toolkit

# Yarn
yarn add @rigu/js-toolkit

Usage

import { asArray, emptyDefault, isNotEmpty, isStringNotEmpty } from '@rigu/js-toolkit';

String utils

  • isString( value )

    Check if value is a string type
    isString(undefined); // return false
    isString(null);      // return false
    isString(0);         // return false
    isString(1);         // return false
    isString('');        // return true
    isString('a');       // return true
    isString([]);        // return false
  • isStringNotEmpty( value )

    Check if value is a string type and if is not empty
    isStringNotEmpty(undefined); // false
    isStringNotEmpty(null);      // false
    isStringNotEmpty(0);         // false
    isStringNotEmpty(1);         // false
    isStringNotEmpty('');        // false
    isStringNotEmpty('a');       // true
    isStringNotEmpty([]);        // false
    isStringNotEmpty(['abc']);   // false
  • defaultEmpty( value )

  • emptyDefault( value )

    Return empty string if provided null or undefined
    defaultEmpty(undefined); // return ''
    defaultEmpty(null);      // return ''
    defaultEmpty(0);         // return 0
    defaultEmpty(1);         // return 1
    defaultEmpty('');        // return ''
    defaultEmpty('a');       // return 'a'
    defaultEmpty([]);        // return []`
  • lowerCaseIfString( value )

  • lowerCase( value )

    Return lower case if the argument object type is string, otherwise return the provided value
    lowerCaseIfString('AbCdEfgH');  // return 'abcdefgh'
    lowerCaseIfString('');          // return ''
    
    lowerCaseIfString(['AbCd', 'EfgH']);    // return ['abcd', 'efgh']
    lowerCaseIfString([1234, 'EfgH']);      // return [1234, 'efgh']
    
    lowerCaseIfString(null);            // return null
    lowerCaseIfString(undefined);       // return undefined
    lowerCaseIfString(0);               // return 0
    lowerCaseIfString(1);               // return 1
    lowerCaseIfString(true);            // return true
    lowerCaseIfString([]);              // return []
    lowerCaseIfString([123, 456]);      // return [123, 456]
    lowerCaseIfString([true, false]);   // return [true, false]
  • upperCaseIfString( value )

  • upperCase( value )

    Return upper case if the argument object type is string, otherwise return the provided value
    upperCaseIfString('AbCdEfgH');  // return 'ABCDEFGH'
    upperCaseIfString('');          // return ''
    
    upperCaseIfString(['AbCd', 'EfgH']);    // return ['ABCD', 'EFGH']
    upperCaseIfString([1234, 'EfgH']);      // return [1234, 'EFGH']
    
    upperCaseIfString(null);            // return null
    upperCaseIfString(undefined);       // return undefined
    upperCaseIfString(0);               // return 0
    upperCaseIfString(1);               // return 1
    upperCaseIfString(true);            // return true
    upperCaseIfString([]);              // return []
    upperCaseIfString([123, 456]);      // return [123, 456]
    upperCaseIfString([true, false]);   // return [true, false]
  • includeIgnoreCase( strToCheck, value )

    Check if strToCheck include the value, ignoring case
  • capitalize( value, returnEmptyIfNull = true )

    Capitalize string value in a null-safe manner Return empty string if null or undefined value is provided If the flag returnEmptyIfNull is set to false, return the provided value if is undefined, null, or is not string
    capitalize('abc');          // return 'Abc'
    capitalize('abc', false);   // return 'Abc'
    
    capitalize(['abc', 123]);           // return ['Abc', 123]
    capitalize(['abc', 123], false);    // return ['Abc', 123]
      
    capitalize('');         // return ''
    capitalize(undefined);  // return ''
    capitalize(null);       // return ''
    capitalize(0);          // return ''
    capitalize(1);          // return ''
    capitalize(true);       // return ''
    capitalize([]);         // return ''
    capitalize([123]);      // return '';
    
    capitalize('', false);         // return ''
    capitalize(undefined, false);  // return undefined
    capitalize(null, false);       // return null
    capitalize(0, false);          // return 0
    capitalize(1, false);          // return 1
    capitalize(true, false);       // return true
    capitalize([], false);         // return []
    capitalize([123], false);      // return [123];
  • compareIgnoreCase( str1, str2 )

    Compares two strings ignoring case and special chars in a null-safe manner
    compareIgnoreCase(undefined, undefined); // return true
    compareIgnoreCase(undefined, null);      // return false
    compareIgnoreCase(null, null);           // return true
    compareIgnoreCase('','');                // return true
    compareIgnoreCase('ast', 'ast');         // return true
    compareIgnoreCase('âșț', 'ast');         // return true
    compareIgnoreCase('Ast', 'asT');         // return true
    compareIgnoreCase('âȘț', 'Ast');         // return true

Array utils

  • asArray( value )

  • arrayOf( value )

    Improved version of Array.of
    asArray(undefined); // return []
    asArray(null);      // return []
    asArray('');        // return ['']
    asArray('abc');     // return ['abc']
    asArray(['abc']);   // return ['abc']
    asArray(11);        // return [11]
    asArray([11]);      // return [11]
    asArray([5, 6, 7]); // return [5, 6, 7]`
  • isNotEmpty( value )

  • notEmpty( value )

    Check if object is array, and is not empty in a null-safe manner
    isNotEmpty(undefined); // return false
    isNotEmpty(null);      // return false
    isNotEmpty(123);       // return false
    isNotEmpty([]);        // return false
    isNotEmpty('');        // return false
    isNotEmpty('a');       // return true
    isNotEmpty('abc');     // return true
    isNotEmpty([1]);       // return true

Object utils

  • isDefined( value )

    Check if object is defined
    isDefined(undefined); // return false
    isDefined(null);      // return false
    isDefined(0);         // return true
    isDefined(1);         // return true
    isDefined('');        // return true
    isDefined('a');       // return true
    isDefined('[]');      // return true
  • asDefined( value )

    Return empty object if the obj is not defined, otherwise the same object
    asDefined(undefined); // return {}
    asDefined(null);      // return {}
    asDefined(0);         // return 0
    asDefined(1);         // return 1
    asDefined('');        // return ''
    asDefined('a');       // return 'a'
    asDefined('[]');      // return []

License: MIT