Skip to content

AuxStudio/js-simple-utils

Repository files navigation

js-simple-utils

Build Status

A collection of Javascript utilities that we use internally.

Installation

yarn add js-simple-utils

Usage

import { convertObjectToArray } from 'js-simple-utils';

const array = convertObjectToArray({ foo: { name: 'bar' } });

Utilities

  • addZeroPadding - Takes a number/string and adds 0 padding if necessary and returns a string
  • cleanObject - Remove all falsy fields from an object
  • cloneObject - Returns a copy of an object
  • convertObjectToArray - Converts an object into an array, keeping the key (as id)
  • countKeys - Counts an objects keys (nesting included)
  • createUID - Creates a unique id
  • firstCharToUpperCase - Converts the first character of a string to uppercase
  • getDistanceBetweenCoordinates - Gets the distance between two sets of coordinates
  • getElapsedDays - Get the amount of days that have elapsed since a timestamp
  • getElapsedHours - Get the amount of hours (rounded) that have elapsed since a timestamp
  • getHoursMinutes - Get the hours and minutes in the format HH:MM from a timestamp
  • getPercentage - Takes two numbers and returns the percentage representation of them rounded
  • getPrettyDate - Get date in a pretty format from a timestamp
  • getRandomInt - Returns a random integer
  • isEmptyObject - Checks if an object is empty and returns true or false
  • reorderArrayItems - Reorders an item in an array
  • sortArrayOfObjectsByKey - Sorts an array of objects by key with optional reverse order functionality
  • stringToTitleCase - Convert a string to Title Case
  • validateCellNumber - Validate South African cell phone numbers
  • validateEmail - Validate email addresses
  • validateIDNumber - Validate South African ID numbers

Development

  1. Clone the project:
git clone https://github.com/AuxStudio/js-simple-utils
  1. Do some work.
  2. Create a PR.

Releases

  1. Run tests to make sure that they're passing.
yarn test
  1. Login to npm
npm login
  1. Run the publish script.
npm publish

TODOS

  • Fix export (use one object for both)

About

A collection of Javascript utilities that we use internally

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Packages

No packages published