Pedash 🌶
A simple Javascript utility library to ease in your daily development routines when it comes to array, object, as well as string manipulations. You can think of it as a mini-lodash.
Anyway, pedash means spicy in Bahasa Indonesia, literally. 🌶🥵🥵
CodeSandbox
Play around with it at CodeSandbox to get the basic idea of what Pedash can do for you.
How to use
Install
npm install pedash
or yarn add pedash
Import it somewhere in your app
import { getLongest } from pedash;
const foods = ["Pizza", "Lasagna", "Karedok", "Banana split", "Rendang", "Souffle"];
console.log(getLongest(foods));
Available methods
getCharCountsByKey(arr: any[])
import { getCharCountsByKey } from "pedash"
const chars = [34, 2, 90, 99, 45, 99, 99, 34]
console.log(getCharCountsByKey(chars))
randomId()
import { randomId } from "pedash"
console.log(randomId())
getLongest(arr: any[], key?: string)
import { getLongest } from "pedash"
const people = ["Sid", "Rusmanto", "Udin", "Zainab"]
console.log(getLongest(people))
const peopleObj = [
{ id: 1, name: "Glenn" },
{ id: 2, name: "Abi" },
{ id: 3, name: "Batugana" },
{ id: 4, name: "Zulu" }
]
console.log(getLongest(peopleObj, "name"))
getUnique(arr: any[])
import { getUnique } from "pedash"
const uniqueValues = [100, 44, 30, 100, 54, 54]
console.log(getUnique(uniqueValues))
groupByKey(arr: any[], key?: string)
import { groupByKey } from "pedash"
const valObj = [
{ id: 1, name: "Glenn", age: 56 },
{ id: 2, name: "Abi", age: 17 },
{ id: 3, name: "Batugana", age: 26 },
{ id: 4, name: "Zulu", age: 45 }
]
console.log(groupByKey(valObj, "name"))
getSmallest(arr: any[], limiter?: number)
import { getSmallest } from "pedash"
const nums = [34, 90, 78, 100, 12]
console.log(getSmallest(nums))
console.log(getSmallest(nums, 3))
console.log(getSmallest(nums, 8))
getHighest(arr: any[], key?: string)
import { getHighest } from "pedash"
const numbers = [34, 2300, 56, 900]
console.log(getHighest(numbers))
shuffle(arr: any[])
import { shuffle } from pedash;
const numbers = [56, 89, 21, 20, 7];
console.log(shuffle(numbers));
removeDoubleWords(sentence: string)
import { removeDoubleWords } from pedash;
const sentence = "You you can do it now now"
console.log(removeDoubleWords(sentence));
removeWhitespaces(sentence: string)
import { removeWhitespaces } from pedash;
const sentence = " You can do it now or never "
console.log(removeWhitespaces(sentence));
stripTags(htmlString: string)
import { stripTags } from pedash;
const tags = "<p><em>Hello</em> <strong>world!</strong></p>"
console.log(stripTags(tags));
getParamsToObject(url: string)
import { getParamsToObject } from pedash;
const completeUrl = "http://website.com?page=77&size=120&is_completed=true"
console.log(getParamsToObject(completeUrl));
renameKeys(keysMap: any, obj: any)
import { renameKeys } from pedash;
const obj = { name: "Samsul", location: "Toa Payoh, Singapore", isRetired: true }
console.log(renameKeys({ name: "firstName", location: "address" }, obj));
getRandomInRange(min: number, max: number)
import { getRandomInRange } from pedash;
console.log(getRandomInRange(2, 55);
console.log(getRandomInRange(1, 10);