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

@oreo9875/web-app-utils

v1.0.5

Published

This toolkit is used to assist web application developers to complete some common but tedious coding tasks.

Downloads

1

Readme

web-app-utils

This toolkit is used to assist web application developers to complete some common but tedious coding tasks.

import _ from 'web-app-utils';

📖 Contents

🧾 API List

| API | Describe | | --------------------- | --------------------------------------------------------- | | storage.setStorage | Set up a time-sensitive localstorage | | storage.getStorage | Get a time-sensitive localstorage | | storage.removeStorage | Remove a time-sensitive localstorage | | deepCopy | Deep copy an object or an array | | deepEqual | Deeply compare whether two objects or arrays are the same | | getType | Get detailed data types | | debounce | Debounce a function | | throttle | Throttle a function | | judgePlainObject | Determine whether an object is an ordinary object | | token.setToken | Set encryption token through json-web-token | | token.getToken | Decrypt token |

🔧 Usage

- storage

storage.setStorage

Params

  • key string: The key of localstorage that needs to be stored
  • value string: The value of localStorage that needs to be stored
  • aging number: The effective duration of storage, in hours (optional, by default the time limit is permanent)
  • return boolean: The operation returns 'true' on success and 'false' on failure

Example

_.storage.setStorage('a', 'b-value', 20);

Store a localstorage whose key is 'a', value is 'b-value', and is valid for 20 hours.

storage.getStorage

Params

  • key string: The key of localstorage that needs to be stored
  • return string|null: If the storage corresponding to 'key' is found and within the valid period, return the corresponding 'value', if not within the valid period or an error occurs, return 'null'

Example

_.storage.getStorage('a');

storage.removeStorage

Params

  • key string: The key of localstorage that needs to be removed

Example

_.storage.removeStorage('a');

- deepCopy

Params

  • obj Array|Object: The object or array that needs to be deep copied
  • return Array|Object: The result of a deep copy

Example

const obj_clone = _.deepCopy(obj1);

- deepEqual

Params

  • obj1 Array|Object: The object1 or array1 that need to be compared deeply
  • obj2 Array|Object: The object2 or array2 that need to be compared deeply
  • return boolean: Returns whether two values are deeply equal

Example

const result = _.deepEqual(obj1, obj2);

- getType

Params

  • value any: The data that needs to be typed
  • return string: Data type

Example

const type = _.getType(value);

- debounce

Returns a function that can be called multiple times (possibly in quick succession), but only fires the callback after waiting x milliseconds after the last call

Params

  • func Function: The function that needs anti-shake
  • delay number: The delay time that needs to be configured for the function, in milliseconds
  • return Function: The processed function

Example

const new_func = _.debounce(old_func, 1000);

- throttle

Returns a function that can be called multiple times (possibly in quick succession), but only every x milliseconds, triggering the callback.

Params

  • func Function: The function that needs throttle

  • interval number: Throttling Interval

  • return Function: The processed function

Example

const new_func = _.throttle(old_func, 1000);

- judgePlainObject

Params

  • obj Object: Object to determine whether it is a plain object
  • return boolean: Returns true if the input object is a plain object, otherwise returns false

Example

const isPlainObject = _.judgePlainObject(obj);

- token

token.setToken

Params

  • data Object: The data that the token needs to contain
  • secret string: The encryption key
  • age string: Token validity period
  • return string: A JSON Web Token string

Example

const token = _.token.setToken({name: 'xxx', phone: 'xxx'}, 'husib&hs2#', '2d');

token.getToken

Params

  • token string: The token that needs to be solved
  • secret string: The encryption key
  • return { status: boolean, data: Object }: Decrypted data, when the status is true, the decryption is successful, and when it is false, the decryption fails

Example

const data = _.token.getToken('xxx', 'husib&hs2#');