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

quasarx

v1.2.0

Published

JavaScript utils.

Downloads

1

Readme

Introduction

JavaScript utils.

Start

npm install quasarx
x[method]()

APIs

alias

  • x.stringify or x.json -> JSON.stringify

  • x.parse -> JSON.parse

  • x.el -> document.querySelector

  • x.createEl -> document.createElement

  • x.now -> Date.now

  • x.type -> x.getType

getType

/**
* type detection.
* 
* @param {*} v - value
* @returns {string} result(lowercase)
*/

x.getType({}) // output: 'object'
x.isString()
x.isNumber()
x.isBoolean()
x.isNull()
x.isUndefined()
x.isSymbol()
x.isBigInt()
x.isArray()
x.isArrayLike()
x.isPlainObject()
x.isObject()

each

/**
 * traverse object, array, array-like.
 * 
 * @param {(Array|Object)} target - target
 * @param {Function} cb - stop loop when cb returns false
 */

const o = { foo: 'foo', bar: 'bar', baz: 'baz' }

x.each(o, (value, key) => {
  // ...

  if (key === 'bar') {
    return false 
  }
})

keys

/**
 * get object's keys.
 * 
 * @param {Object} target - target
 * @returns {Array} - an array of key
 */

const o = {
  foo: 'foo',
  bar: 'bar'
}

x.keys(o) // output: ['foo', 'bar']

last

/**
 * get last item of array
 * 
 * @param {Array} ary - array
 * @returns {*} - last item
 */

const ary = [1, 2, 3]

x.last(ary) // output: 3

wait

/**
 * wait function
 * 
 * @param {number} time - wait time
 */

async function foo () {
  await x.wait(1000)
  // after 1s
  console.log('foo')
}

foo()

urlParams

/**
 * parse url
 * 
 * @param {string} url - url
 * @returns {Object} - result
 */

x.urlParams('http://example.com?foo=bar#baz') // output: { foo: bar, hash: baz }

css

/**
 * set or get style
 * 
 * @param {HTMLElement} el - element
 * @param {string|Object} propOrPairs - options
 * @param {string} [value=undefined] - style value
 */

const { body } = document

// set
x.css(body, 'width', '100vw')
x.css(body, {
  width: '100vw',
  height: '100vh'
})
x.css(body, ['color', 'backgroundColor'], 'red')

// get
x.css(body, 'width') // output: 100vw
x.css(body, ['width', 'height']) // output: ['100vw', '100vh']

attr

like css

delete

/**
 * delete property
 * 
 * @param {Object} target - target
 * @param {string|Array} props - the props you want to delete
 * @returns {Object} - result
 */

const o = { foo: 'foo', bar: 'bar', baz: 'baz' }

x.delete(o, 'foo') // { bar: 'bar', baz: 'baz' }
x.delete(o, ['bar', 'baz']) // {}

addEventListener

/**
 * add event listener
 * 
 * @param {HTMLElement} el - element
 * @param {string} type - event type
 * @param {Function} cb - callback
 * @returns {Function} - remove listener
 */

const unListen = x.addEventListener(document.body, 'click', () => {
  // ...
})

setTimeout(() => {
  unListen() // remove listener
}, 3000)