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

@edge/misc-utils

v1.0.7

Published

Provides commonly-used libraries across Edge products

Downloads

26

Readme

Edge Miscellaneous Utilities

Provides commonly-used libraries across Edge products

Overview

cycle

cycle provides a simple wrapper for background jobs.

import { cycle } from '@edge/misc-utils'

const hello: cycle.Job = {
  name: 'hello',
  interval: 2000,
  async do() {
    console.log('Hello')
  }
}
cycle.run([hello]).catch(err => console.error(err))

http

http provides convenience methods for Express-based JSON APIs.

import { RequestHandler } from 'express'
import { http } from '@edge/misc-utils'

const handler: RequestHandler = (req, res, next) => {
  http.notFound(res, next, { reason: 'this is just a README demonstration' })
}

query

query provides type-safe access to query string data.

import { RequestHandler } from 'express'
import { query } from '@edge/misc-utils'

const handler: RequestHandler = (req, res, next) => {
  const page = query.integer(req.query.page, 1) || 1
  res.send(`Page ${page}`)
  next()
}

validate

validate provides a basic validation library, plus a powerful validate() function that sanitises input. This is particularly useful for Express-based JSON APIs.

import { RequestHandler } from 'express'
import { validate } from '@edge/misc-utils'

const handler = (): RequestHandler => {
  type Data = {
    name: string
  }
  const readBody = validate.validate<Data>({
    name: validate.seq(validate.str, validate.minLength(1), validate.maxLength(256))
  })
  return (req, res, next) => {
    try {
      const data = readBody(req.body)
      res.json(data)
      next()
    }
    catch (err) {
      next(err)
    }
  }
}

Miscellaneous

identity() provides a simple identity function, which can be useful for e.g. dereferencing arrays:

import { identity } from '@edge/misc-utils'

const a = [1, 2, 3]
const b = a.map(identity)
a.push(4)
console.log(a, b) // [ 1, 2, 3, 4 ] [ 1, 2, 3 ]

unique() provides a simple way to isolate unique values.

import { unique } from '@edge/misc-utils'

const ids = ['abc', 'def', 'def', 'ghi'].filter(unique)
console.log(ids) // [ 'abc', 'def', 'ghi' ]

Contributing

Interested in contributing to the project? Amazing! Before you do, please have a quick look at our Contributor Guidelines where we've got a few tips to help you get started.

License

Edge is the infrastructure of Web3. A peer-to-peer network and blockchain providing high performance decentralised web services, powered by the spare capacity all around us.

Copyright notice (C) 2023 Edge Network Technologies Limited [email protected] All rights reserved

This product is part of Edge. Edge is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version ("the GPL").

If you wish to use Edge outside the scope of the GPL, please contact us at [email protected] for details of alternative license arrangements.

This product may be distributed alongside other components available under different licenses (which may not be GPL). See those components themselves, or the documentation accompanying them, to determine what licenses are applicable.

Edge is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

The GNU General Public License (GPL) is available at: https://www.gnu.org/licenses/gpl-3.0.en.html A copy can be found in the file GPL.md distributed with these files.

This copyright notice MUST APPEAR in all copies of the product!