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

cfw-easy-utils

v1.0.3

Published

An utils library for common tasks with CloudFlare Workers.

Downloads

65

Readme

🦄 CF Workers: easy-utils

A library designed to make writing workers so much cleaner and easier!

Welcome to easy-utils, this library is designed to make writing Workers easy as heck. Included in this package is a bunch of helpers for responses, profiling, handling cookies, and serving any static assets. Now with full Websocket support!

Turn your Worker code from spaghetti hell to majestic artwork today with easy-utils.

Documentation:

https://easy-utils.docs.ceru.dev/docs/

🔧 Install

npm i cfw-easy-utils

Note: this lib has tree-shaking enabled by default. Only import what you need and you will keep your package size low!

✨ Examples

🔨 No more JSON.stringify!

Stuck having to copy paste the same 4 lines of code just to return a simple JSON object? Now you can easily return any JSON-compatible object/array without having to worry about your code getting complex.

return response.json({ 'hello': 'world!' })

🎨 Cache S3 buckets & more!

Want to save money on your bill? Cache your assets on the edge and speed up your images. All of Cloudflare's caching power in a single line of code.

return response.static(request, { baseUrl: 'https://yourbucket.net' })

🔌 Go realtime with Websockets!

Support Websockets at the edge with our util library. Get access to a full Websocket client and server for your every need.

import { response, Websocket, WebsocketResponse } from 'cfw-easy-utils'

var ws = new Websocket('ws://echo.websocket.org') // Client
var resp = new WebsocketResponse() // Server

ws.on('message', (msg) => {
    resp.send(msg)
})

resp.on('message', (msg) => {
    ws.send(msg)
})

return response.websocket(resp)

🍃 Handle CORS with a breeze!

CORS can be so cumbersome and annoying. Let easy-utils handle it for you so you can focus on your Worker's real purpose.

if (request.method == 'OPTIONS') {
    return response.cors()
}

// autoCors is true by default, but we want to show it off.
return response.json({ hello: 'World' }, { autoCors: true })

⏱ Time your I/O to reduce slowdowns.

Record your times to watch for any slow I/O events. Will only count I/O as Workers cannot count CPU time internally. All you need to do is mark some times, then set the Stopwatch option on any of easy-utils response handler and it will set the Server-Timing header for you. Look in the Timing header of your modern browser to view the timings.

import { Stopwatch } from 'cfw-easy-utils'

const watch = new Stopwatch()
const value = await KVNAMESPACE.get('somekey')
watch.mark('Got KV response')
return response.json({ kv: value }, { stopwatch: watch })

😄 Generate user accounts on the edge

Want to take your user experience to the next level? You can generate password hashes and UUID's direct in your Worker.

import { response, secrets } from 'cfw-easy-utils'

// Later, use secrets.verifyPassword to verify someone's identity.
return response.json({
    id: secrets.uuidv4(),
    passwordHash: await secrets.hashPassword('passw0rd01')
})

🦄 This is only some of the examples of what you can do with cfw-easy-utils.

Made by Connor Vince with the help and love from the Cloudflare Worker's community. Thank you everyone!