0.10.3 • Published 6 months ago

some-javascript-utils v0.10.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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
0.10.1

6 months ago

0.10.3

6 months ago

0.9.4

8 months ago

0.9.3

10 months ago

0.9.6

8 months ago

0.9.5

8 months ago

0.9.2

10 months ago

0.8.3

11 months ago

0.9.1

11 months ago

0.8.2

11 months ago

0.7.1

1 year ago

0.4.1

1 year ago

0.3.1

1 year ago

0.6.1

1 year ago

0.5.2

1 year ago

0.2.1

1 year ago

0.1.1

1 year ago

0.0.1

1 year ago