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

donot

v0.4.1

Published

Do not use this utility library

Downloads

7

Readme

donot

Do not use this Javascript utility library

This is basically my collection of functions that i often use in projects. They can probably be found in other libraries (like Lodash), but i might not want to use those libraries (because they're big) or because it's overkill.

Because this is a bit of a grabbag of things you probably shouldn't be using this library. Hence the name.

Install

Using npm:

$ npm install --save donot

Using yarn:

$ yarn add donot

donot is a UMD library and thus can be used as a CommonJS module for Node.js, AMD (with Require.js) or as a plain old Javacript global.

API

Here are all the functions:

$(selector: string): HTMLElement A shortcut for document.querySelector.

$("body").style.background = 'red';`

$$(selector: string): HTMLElement A shortcut for document.querySelectorAll. Converts the elements in an array.

$$("p").forEach((p) => p.style.color = 'red');

chunk(array: array, size: number): array Chunks a given array in multiple arrays of maximum size size.

const nrs = _.range(1, 10);
const chunks = _.chunk(nrs, 4);
console.log(chunks); // [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8 ], [ 9 ] ]

combinations(list: array, opts?:object): array Create a list of all unique combinations, where a,b === b,a. By default, equals like 'a,a' are allowed, if you don't want that, pass { allowEquals : false } as a second argument.

const options = combinations([1, 2]);
console.log(options); // [ [ 1, 1 ], [ 1, 2 ], [ 2, 2 ] ]

const options = combinations([1, 2], { allowEquals : false });
console.log(options); // [ [ 1, 2 ] ]

degToRad(deg: number): number Converts from degrees to radians.

console.log(degToRad(180)); // 3.141592....

getCssProp(el: string | HTMLElement, property: string) : string Returns the value of a CSS property of an element. If el is the string root, the property is fetched from the :root element.

Also see setCssProp.

setCssProp('root', '--color', '#f9f9f9');
console.log(getCssProp('root', '--color')); // '#f9f9f9'

getJson(url: string): Promise getJson(url: string, params: object): Promise Uses fetch to do a HTTP call and return JSON. params can be an object that will be transformed into URL arguments (see also urlWithParams).

const data = await getJson('http://www.example.com/data.json');

matrix(cols: number, rows: number): arrray Creates a multidimensional array.

const grid = matrix([1,2,3], [4,5,6]);
console.log(grid[0][1]); // 4

noop(): function Returns an empty function.

range(max: number): number range(min: number, max: number): number Creates a filled array with number from min (or 0 if that is not given) to, but not including max.

console.log(range(3)); // [ 0, 1, 2 ]
console.log(range(2, 5)); // [ 2, 3, 4 ]

randInt(max: number) : number randInt(min: number, max: number) Returns a random integer between min (or 0 if that is not given) and max.

sample(list: array): any Returns a random element from an array.

setCssProp(el: string | HTMLElement, property: string, value: string) : void Set a CSS property of an element. If el is the string root, the property is set on the :root element.

Also see getCssProp.

setCssProp('root', '--color', '#f9f9f9');

const el = document.querySelector("#main");
setCssProp(el, '--color', '#f9f9f9');

shuffle(list: array): array Returns a shuffled (randomized) copy of list.

sum(list: array): number Returns the sum of all numbers in list.

console.log(sum([1,2,3,4])); // 10

timeout(ms: number): Promise Returns a promisified version of window.setTimeout (browser) or setTimeout) (Node) with a time of ms miliseconds.

console.log("Let's wait 2 seconds");
await timeout(2000);
console.log("That was 2 seconds");

urlWithParams(url: string, params: object): string Transform a url with an object params into an URL with arguments.

const url = _.urlWithParams('http://example.com', {
        foo : 'bar',
        1 : '2'
});

License

MIT © Hay Kranen