npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

futils-lite

v0.2.4

Published

A modern JavaScript utility library.

Downloads

10

Readme

futils-lite

A modern JavaScript utility library.

📦 Install

npm install futils-lite --save
yarn add futils-lite

🔨 Usage

###_join

_join(arr, identifier = 'name', separator = ', ')

Converts all elements in array object into a string separated by separator.

Arguments

  • arr (array).
  • [identifier = 'name'] (string)
  • [separator = ', '] (string)

Returns

  • String: Return string

Example

const authors = [
	{ id: 1, username: 'Hunt' },
	{ id: 2, username: 'Sam' }
];

console.log(_join(authors, 'username'));
//expected output: "Hunt, Sam"

###arrayMove

arrayMove(array, from, to)

Move an array item to a different index.

Arguments

  • array (array).
  • from (integer)
  • to (integer)

Returns

  • array: Return array

Example

const authors = ['Hunt', 'Sam'];

console.log(arrayMove(authors, 0, 1));
//expected output: ['Sam', 'Hunt']

###currencyFormatter

currencyFormatter(value, options, [locales = null])

Enable language sensitive currency or number formatting

Arguments

  • value (Number).
  • options (Object): An object with some or all of the following properties.
  • [locales = null] (String): A string with a BCP 47 language tag, or an array of such strings.

Returns

  • String: Return string with locale

Example

const number = 123456.789;

console.log(currencyFormatter(number,  { style: 'currency', currency: 'EUR' } , 'de-DE'));
// expected output: "123.456,79 €"

// the Japanese yen doesn't use a minor unit
console.log(currencyFormatter(number,   { style: 'currency', currency: 'JPY' } , 'ja-JP'));
// expected output: "¥123,457"

// limit to three significant digits
console.log(currencyFormatter(number,   { maximumSignificantDigits: 3 } , 'en-IN'));
// expected output: "1,23,000"

###numberFormatter

numberFormatter(value, options = {}, [locales = null])

Enable language sensitive number formatting

Arguments

  • value (Number).
  • options (Object): An object with some or all of the following properties.
  • [locales = null] (String): A string with a BCP 47 language tag, or an array of such strings.

Returns

  • String: Return string with locale

Example

const number = 123456.789;

// limit to three significant digits
console.log(currencyFormatter(number,   { maximumSignificantDigits: 3 } , 'en-IN'));
// expected output: "1,23,000"

###filterBuilder

filterBuilder(schema, values)

Arguments

  • schema (object)
  • values (object)

Returns

  • Object: Return as object

Schema Type

  • bt: between
  • eq: equal
  • ne: not equal
  • gt: greater than
  • gte: greater than equal
  • lt: less than
  • lte: less than equal
  • rl: like (as regex)

Example

const schema = { name: { type: 'rl' }, price: { type: 'eq'} };
const values = { name: 'saas', price: 29.00 }

console.log(filterBuilder(schema values));
// expected output: { name: { $regex: `.*saas.*`, $options: 'i' }, price: 29 }

###findURLQueryParams

findURLQueryParams(paramsName, [url = null])

Arguments

  • paramsName (array string): array names of url query string.
  • URL (window.location.search): search url of window location

Returns

  • Object: Return object of param(s) name

Example

const URL = '<URL>?type=new&id=123';
const search = 'type=new&id=123'

console.log(findURLQueryParams( ['type'] , search));
// expected output: { type: new }

console.log(findURLQueryParams( ['type', 'id'] , search));
// expected output: { type: new, id: 123 }

###http

async http(options)

Arguments

Example

const [ status, payload ] = await http(
	{
		method: 'post',
		url: '/user/12345',
		data: {
		firstName: 'Fred',
		lastName: 'Flintstone'
		}
	}
);

###http{Post, Put, Patch, Get, Delete}

async httpPost(options)
async httpPut(options)
async httpPatch(options)
async httpGet(options)
async httpDelete(options)

Arguments

  • options (post, put, patch): Object of { url: string, [ data: any , config: AxiosRequestConfig ] }.
  • options (get, delete): Object of { url: string, [ config: AxiosRequestConfig ] }.

Example

const [ status, payload ] = await httpPost(
	{
		url: '/user/12345',
		data: {
			firstName: 'Hunt',
			lastName: 'RK'
		}
	}
);
const [ status, payload ] = await httpGet({ url: '/user/12345' });

###slug

slug(value, separator = '-')

Arguments

  • value (string)
  • [separator = '-'] (string)

Example

console.log(slug('Hunter Blog'));
//expected output: hunter-blog

###toUTC

toUTC(value, dateOnly = false, format = null)

Arguments

  • value (string)
  • dateOnly (boolean): false
  • format (string | boolean): null

Example

[ Notes: local timezone: Asia/Jakarta = +07:00 ]
const value = '2019-07-25T13:00:00.48Z';

console.log(toUTC(value));
// expected output: (as moment)  2019-07-25T06:00:00.48Z

console.log(toUTC(value, false, 'dd-mm-YYYY'));
// expected output:  25-07-2019

console.log(toUTC(value, true));
// expected output: (as moment)  2019-07-25T12:00:00.00Z

console.log(toUTC(value, true, true));
// expected output:  (as string) 2019-07-25T12:00:00.00Z

###toTZ

toTZ(value, dateOnly = false, format = null)

Arguments

  • value (string)
  • timezone (string)
  • format (string | boolean): null

Example

const utcString = '2019-07-25T13:00:00.48Z';

console.log(toTZ(utcString, 'Asia/Jakarta'));
// expected output: (as moment)  2019-07-25T20:00:00.48Z

console.log(toTZ(utcString, 'Asia/Jakarta', 'dd-mm-YYYY'));
// expected output:  25-07-2019