pedash
Advanced tools
Comparing version 0.1.18 to 0.1.19
26
index.js
@@ -91,1 +91,27 @@ export function getCharCountsByKey(arr) { | ||
} | ||
export function getParamsToObject(url) { | ||
if (!url) throw new Error("Don't forget to pass the URL") | ||
const regex = /([^?=&]+)(=([^&]*))/g | ||
return (url.match(regex) || []).reduce((accu, current) => { | ||
const index = current.indexOf("=") | ||
return (accu[current.slice(0, index)] = current.slice(index + 1)), accu | ||
}, {}) | ||
} | ||
export function renameKeys(keysMap, obj = {}) { | ||
if (Object.keys(obj).length === 0) throw new Error("Don't forget to pass the object data") | ||
return Object.keys(obj).reduce( | ||
(acc, key) => ({ | ||
...acc, | ||
...{ [keysMap[key] || key]: obj[key] } | ||
}), | ||
{} | ||
) | ||
} | ||
export function getRandomInRange(min, max) { | ||
return Math.floor(Math.random() * (max - min + 1)) + min | ||
} |
{ | ||
"name": "pedash", | ||
"version": "0.1.18", | ||
"description": "A lodash-like javascript helper -- for dummies", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"pedash", | ||
"lodash", | ||
"helper", | ||
"utils", | ||
"utilities", | ||
"javascript" | ||
], | ||
"author": "Bejo Karmila", | ||
"license": "ISC" | ||
"name": "pedash", | ||
"version": "0.1.19", | ||
"description": "A lodash-like javascript helper -- for dummies", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"pedash", | ||
"lodash", | ||
"utility", | ||
"helper", | ||
"string manipulation", | ||
"array helper", | ||
"utilities", | ||
"javascript" | ||
], | ||
"author": "Bejo Karmila", | ||
"license": "ISC" | ||
} |
@@ -178,1 +178,35 @@ ## Pedash 🌶 | ||
``` | ||
#### getParamsToObject(url: string) | ||
``` | ||
import { getParamsToObject } from pedash; | ||
const completeUrl = "http://website.com?page=77&size=120&is_completed=true" | ||
console.log(getParamsToObject(completeUrl)); | ||
// { page: 77, size: 120, is_completed: true } | ||
``` | ||
#### 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)); | ||
// { firstName: "Samsul", location: "Toa Payoh, Singapore", isRetired: true } | ||
``` | ||
#### getRandomInRange(min: number, max: number) | ||
``` | ||
import { getRandomInRange } from pedash; | ||
console.log(getRandomInRange(2, 55); | ||
// 34 | ||
console.log(getRandomInRange(1, 10); | ||
// 10 | ||
``` |
7948
96
212