javascript-helper-functions

🐠 A list of helpful javascript functions!

Usage no npm install needed!

<script type="module">
  import javascriptHelperFunctions from 'https://cdn.skypack.dev/javascript-helper-functions';
</script>

README

javascript-helper-functions

🐠 A list of helpful javascript functions!

NPM JavaScript Style Guide

Install

npm install --save javascript-helper-functions

Usage

import React, { Component } from "react";
import { truncateText } from "javascript-helper-functions";

class Example extends Component {
  render() {
    const bodyText =
      "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting.";

    return <div>{truncateText(bodyText, 20)}</div>;
    // This will return "Lorem Ipsum is simpl..."
  }
}

export default Example;

String Helpers

Function Description Example Args
truncateText Returns truncated text ending with "..." truncateText(string, 20) 1. string 2. length
toTitleCase Returns string in title case toTitleCase(string) 1. string

Number Helpers

Function Description Example Args
intComma Returns number in comma seperated number intComma(number) 1. number
isEven Returns if number is even or not isEven(number) 1. number

Array Helpers

Object Helpers

Function Description Example Args
copyObject Returns a copy of the object copyObject(obj) 1. object

URL Helpers

Function Description Example Args
addParam Adds parameter to url, EG: www.google.com/?page=1 addParam('page', 1) 1. option, 2. option
updateParam Updates parameter to url, EG: www.google.com/?page=1 => ?page=2 addParam('page', 2) 1. option, 2. option

License

MIT © dane-brown