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

petite-utils

v0.0.15

Published

A collection of small util function in JavaScript.

Downloads

55

Readme

petite-utils

A collection of small util function in JavaScript.

features:

  • small and fast.
  • node.js and browser support.
  • tree-shakable.

WIP. 🚧 Don't use in production.

Installation

# npm
npm i petite-utils
# yarn 
yarn add petite-utils
# pnpm
pnpm add petite-utils

Usage

// cjs module
const { randomStr } = require('petite-utils')
// ES module
import { randomStr } from 'petite-utils'

use esm in html by cdn

<!-- load ES module -->
<script type="module">
  import { randomStr } from 'https://unpkg.com/petite-utils/dist/index.js'
  const result = randomStr(20, 50)
  console.log(result)
  console.log('test in browser using esm')
</script>

use umd in html by cdn

<!-- load umd -->
<script src="https://unpkg.com/petite-utils"></script>
<!-- then use function from PU object -->
<script>
  const str = PU.randomStr()
</script>

isNumber

check if the value is a number.

import {
    isNumber
} from 'petite-utils'
isNumber(1) // true
isNumber('1') // true
isNumber(4.917736942280289e-10) // true
isNumber(
    BigInt('0b11111111111111111111111111111111111111111111111111111'),
) // true
isNumber(NaN) // false
isNumber('a') // false

operate cookie

operate cookie in browser.

import {
    setCookie,
    getCookie,
    removeCookie,
    clearAllCookie
} from 'petite-utils'

setCookie('name', 'value', 10) // set cookie with name, value and expires in 10 day.
getCookie('name') // get cookie by name. get value
removeCookie('name') // remove cookie by name.
clearAllCookie() // clear all cookies.

setCookie('obj', { age: 10 }, 100) // set cookie with name, complex value and expires in 100 day.
getCookie('obj') // get cookie by name. {age:10}

setCookie('array', [{ name: 'petite-utils' }], 0.5) // set cookie with array 

chunk

split array into chunks.

import {
    chunk
} from 'petite-utils'

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
const result = chunk(arr, 3)
console.log(result) // [[1,2,3],[4,5,6],[7,8,9]]

copy

copy some text to clipboard.

import {
    copy
} from 'petite-utils'
const text = 'copy this text to clipboard'
copy(text) // copy text to clipboard