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

some-javascript-utils

v0.10.3

Published

some functions for javascript

Downloads

29

Readme

some-javascript-utils

Some functions to work better with arrays, objects and more!!

Functions

Arrays

sortBy

sortBy

How to import it?

import { Array } from "some-javascript-utils";
// import { sortBy } from "some-javascript-utils/array";

or

const { Array } from "some-javascript-utils";
// const { sortBy } = require("some-javascript-utils/array");

In Action!

🔶⚠Very important⚠🔶!!

just work with array of objects

// ... imports

const array = [{ id: 5 }, { id: 2 }, { id: 3 }, { id: 6 }];

Array.sortBy(array, "id", "asc") ;
// attribute "id" and "asc" are by default

// result
// [ { id: 2 }, { id: 3 }, { id: 5 }, { id: 6 } ]

Browser

getUserLanguage

How to import it?

import { Browser } from "some-javascript-utils";
// import { getUserLanguage } from "some-javascript-utils/Browser";

or

const { Browser } = "some-javascript-utils";
// const { getUserLanguage } = "some-javascript-utils/Browser";

In Action!

🔶⚠Very important⚠🔶!!

just work in browsers

// ... imports

const userLang = getUserLanguage();
// if pass a string parameter will save the language to a cookie ()
// example: "en"

parseQueries

How to import it?


import { Browser } from "some-javascript-utils";
// import { parseQueries } from "some-javascript-utils/Browser";

or


const { Browser } = "some-javascript-utils";
// const { parseQueries } = "some-javascript-utils/Browser";

In Action!

🔶⚠Very important⚠🔶!!

just work in browsers


// ...imports

//! using location from useLocation() hook from "react-router-dom"

useEffect(() => {
    const { search } = location // ex: [some-url]?id=1&folder=sito
    const queryParams = parseQueries(search)
    // queryParams will value { id: "1", folder: "sito" }
},[location])

scrollTo

How to import it?


import { Browser } from "some-javascript-utils";
// import { scrollTo } from "some-javascript-utils"/Browser;

or


const { Browser } = "some-javascript-utils";
// const { scrollTo } = "some-javascript-utils/Browser";

In Action!

🔶⚠Very important⚠🔶!!

just work in browsers


// ... imports

// it's obviously how it works
scrollTo(0) // go to top of the page

createCookie

How to import it?


import { Browser } from "some-javascript-utils";
// import { createCookie } from "some-javascript-utils/Browser";

or


const { Browser } = "some-javascript-utils";
// const { createCookie } = "some-javascript-utils/Browser";

In Action!

🔶⚠Very important⚠🔶!!

just work in browsers


// ...imports

const name = "user";
const value = "sito";
const expiration = 765 // count of days or "2019-12-31 23:59:59"
createCookie(name, expiration, value);

// result
// a new cookie in document.cookie = `${name}=${value};${expires}";path=/`;

getCookie

How to import it?


import { Browser } from "some-javascript-utils";
// import { getCookie } from "some-javascript-utils/Browser";

or


const { Browser } = "some-javascript-utils";
// const { getCookie } = "some-javascript-utils/Browser";

In Action!

🔶⚠Very important⚠🔶!!

just work in browsers


// ...imports

const name = "user";
getCookie(name);

// result
// sito (of previous example)

deleteCookie

How to import it?


import { Browser } from "some-javascript-utils";
// import { deleteCookie } from "some-javascript-utils/Browser";

or


const { Browser } = "some-javascript-utils";
// const { deleteCookie } = "some-javascript-utils/Browser";

In Action!

🔶⚠Very important⚠🔶!!

just work in browsers


// ...imports

const name = "user";
deleteCookie(name);

// result
// (document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`);/

validation

To validates a storage key

How to import it?


import { Browser } from "some-javascript-utils";
// import { validation } from "some-javascript-utils/Browser";

or


const { Browser } = "some-javascript-utils";
// const { validation } = "some-javascript-utils/Browser";

In Action!

🔶⚠Very important⚠🔶!!

just work in browsers


// ...imports

localStorage.setItem("user", "yo");
validation("user", "local");

// result
// true

toSlug

To turn a string to url slug

How to import it?


import { toSlug } from "some-javascript-utils";

or


const { toSlug } = "some-javascript-utils";

In Action!


// ...imports

const urlName = toSlug("The Man on the Hills")

// urlName = the-man-on-the-hills