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

les-utils

v2.0.12

Published

Utilities used by lesky

Downloads

20

Readme

npm npm NPM

Les Utils (Less but still powerful)

This project was originally created to help support lesky. Originally, these utils were confined to that project, but since these utils can be nifty and reusable, I thought it would be wise to separate them out into their own project. That's exactly what this is. les-utils is less but versatile. With any luck, les-utils will become even less as the ES language features improve.

Installation:

  1. First install globally

npm i -g les-utils

  1. Then to use in a project folder link to it:

npm link les-utils

Usage:

import { LangUtils, PromiseUtils, Rexter, StringUtils } from 'les-utils'
// Currently exposed utils
// Read below for further explanation

Current utilities:

  1. Rexter: Like a good dog, fetches and requests things...sometimes in batch. Promise-based.

a) Example: (single request)

const rexter = Rexter({ host: api.host.com })
const resp = await rexter.request({ path: '/some/data/123' })

b) Example: (batch request)

const rexter = Rexter({ host: api.host.com, auth: 'user:pass' }) // in case auth is needed
const userIds = ['123', '453', '897']
const resp = await rexter.requestMany({
  items: userIds
  pathTemplate: '/some/data/[ITEM]', // [ITEM] will be replaced by each userId
  outputFmt: 'json', // Can be 'json', 'string', or 'xml' (default is buffered byte stream)
  notify({ data }) { // Set up an optional per-item notification handler 
    const { item, resp } = data
    // If interested, handle each items response as it comes in
    // otherwise, it's sufficient to simply wait for the promise to resolve
  }
})
  1. Language:
  • Gets a list of supported languages from the specified service (currently supported services are Yandex and IBM)
  • Translates text using those APIs. (IBM and Yandex require free API keys, but the free limits are pretty good!)
  1. String:
  • ParseXML (promise-based)
  • Camelcase
  • Startcase
  1. Promises:
  • PromiseUtils.delay (a promise-based delay method so you can stop calling setTimeout. Easy!)
  • PromiseUtils.each (similar to async.each but promise-based and more versatile)
  • PromiseUtils.series (similar to async.series but promise-based and more versatile)

a) Example:

const items = ['item1', 'item2']
const resp = await PromiseUtils.each({
  items,
  async handleItem() {
    await PromiseUtils.delay(100)
    return 'ok'
  },
  notify({ evt, data }) {
    const { item, resp } = data
    // do something with item's resp if you want
  }
})
// resp = { item1: 'ok', item2: 'ok' }

Why not just use Promise.all? In many cases, yes, I'm happy to use Promise.all. However, if there are MANY promises to be fulfilled, I like to have the option to be notified when each promise has been fulfilled. I found this to a be a relatively simple way to do what I want.

  1. Security:
  • generateSelfSignedCert (does what it says)
  1. NetUtils:
  • findFreePort (finds a free port for a specified range)
  • isPortTaken (does what it says)