GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - zero-dependency/utils: 🛠 Additional utilities

BranchesTags
Open more actions menu

Latest commit

 

History

113 Commits
113 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.prettierignore
.prettierignore
 
 
.prettierrc.cjs
.prettierrc.cjs
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
vite.config.ts
vite.config.ts
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation

@zero-dependency/utils

npm version npm bundle size (scoped) npm license

Installation

npm install @zero-dependency/utils
yarn add @zero-dependency/utils
pnpm add @zero-dependency/utils

Usage

import {
  hexToRgb,
  rgbToHex,
  isHexColor,
  debounce,
  throttle,
  toNumber,
  addZero,
  entries,
  pick,
  omit,
  pluralize,
  randomNum,
  randomToken,
  generateChars,
  capitalize
  wait,
  match
} from '@zero-dependency/utils'

// hex
console.log(hexToRgb('#000')) // { r: 0, g: 0, b: 0 }
console.log(rgbToHex({ r: 0, g: 0, b: 0 })) // #000000
console.log(isHexColor('#000')) // RegExpExecArray
console.log(isHexColor('wrong')) // null

// debounce
const debounced = debounce((msg) => console.log(msg), 1000)

// throttle
const throttled = throttle((msg) => console.log(msg), 1000)

// number
console.log(toNumber('1')) // 1
console.log(addZero(1)) // '01'
console.log(randomNum(1, 10))

// object
console.log(entries({ a: 1, b: 2 })) // [['a', 1], ['b', 2]]
console.log(pick({ a: 1, b: 2 }, ['a'])) // { a: 1 }
console.log(omit({ a: 1, b: 2 }, ['a'])) // { b: 2 }

// pluralize
const tasksPluralize = pluralize({
  one: 'задание',
  two: 'задания',
  few: 'заданий',
  prefix: true
})

console.log(tasksPluralize(1)) // '1 задание'
console.log(tasksPluralize(3)) // '3 задания'
console.log(tasksPluralize(5)) // '5 заданий'
console.log(tasksPluralize(999)) // '999 заданий'

// string
console.log(randomToken()) // 'vpxi4hpzmy'
console.log(generateChars('a', 'd')) // ['a', 'b', 'c', 'd']
console.log(capitalize('hello')) // 'Hello'

// wait
await wait(1000)
console.log('resolve after 1s')

// pattern matching
const matcher = match<[string, string], string>((test) => ({
  [test((firstName) => !firstName)]: 'User not found',
  [test((firstName) => firstName.length < 8)]: (firstName, lastName) => `${firstName} ${lastName}`,
  [test((firstName) => firstName.length >= 8)]: (firstName) => firstName
}))

matcher('', 'Doe') // 'User not found'
matcher('John', 'Doe') // 'John Doe'

About

🛠 Additional utilities

Resources

Readme
MIT license
Activity
Custom properties

Stars

2 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Used by

Contributors

Languages

Generated from zero-dependency/template
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.