nice-utils

1.0.3 • Public • Published

npm: nice-utils

Introduction

A collection of useful utilities for the browser and node.js environments.

Installation

$ npm install nice-utils

or 

$ yarn add nice-utils

Usage

// Import ES6 way

import {
  arrayIntersection,
  changeURLHash,
  htmlSanitize,
  isArray,
  isArrayEqual,
  isElementLoaded,
  isFloat,
  isFunction,
  isImageLoaded,
  isInt,
  isIos,
  isJson,
  isNumber,
  isObject,
  isString,
  isTouchDevice,
  netElementWidth,
  niceBytes,
  onlyNumbers,
  percentage,
  quickHash,
  randomNumber,
  replaceAll,
  replaceBulk,
  rtrim,
  splitIntoLines,
  springTruncate,
  stripTags,
  toObject,
  truncate,
  undefinedOrNull,
  undefinedOrNullChained,
  urlSanitize,
  urls
} from 'nice-utils';

// Import ES2015 way
const niceUtils = require('nice-utils')	

Methods Overview

  • arrayIntersection - Intersect common elements of two arrays
arrayIntersection([1], [1, 2]);

//output: [1]
  • isArray - Checks whether the input is an Array
isArray([1]);

//output: true
  • isArrayEqual - Checks whether the inputted arrays are equal
isArrayEqual([1], [1]);

//output: true
  • isElementLoaded - Wait for a DOM element to load
//Example:
isElementLoaded(
  '#id', //selector
  200 //timeout (optional)
).
then(response => {
  console.log(`The element was successfully loaded into the DOM`);
}).
catch(e => {
  console.error(e);
});
  • isImageLoaded - Wait for an image to load.
isImageLoaded(
    'https://sample-videos.com/img/Sample-jpg-image-500kb.jpg').
then(res => {
  console.log(`Success`);
  
  const img = document.createElement('img');
  img.src = res.src;
  parentSelector.appendChild(img);
}).
catch(e => {
  console.error(`Error`);
});
Rest of the documentation shall be updated very soon. In the mean time please find the methods and usage information from src/index.js

Building from Source

Requirements: Node.js v6+, Git and npm

Clone

$ git clone --depth 1 --single-branch --branch master https://github.com/ganeshrvel/npm-nice-utils.git

$ cd npm-nice-utils

Contribute

  • Fork the repo and create your branch from master.
  • Ensure that the changes pass linting.
  • Update the documentation if needed.
  • Make sure your code lints.
  • Issue a pull request!

When you submit code changes, your submissions are understood to be under the same MIT License that covers the project. Feel free to contact the maintainers if that's a concern.

Buy me a coffee

Help me keep the app FREE and open for all. Paypal me: paypal.me/ganeshrvel

Contacts

Please feel free to contact me at ganeshrvel@outlook.com

More repos

License

nice-utils | A collection of useful utilities for the browser and node.js environments is released under MIT License.

Copyright © 2018-Present Ganesh Rathinavel

Package Sidebar

Install

npm i nice-utils

Weekly Downloads

3

Version

1.0.3

License

MIT

Unpacked Size

18.1 kB

Total Files

6

Last publish

Collaborators

  • ganeshrvel