Giter VIP home page Giter VIP logo

cfw-easy-utils's Introduction

๐Ÿฆ„ 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:

๐Ÿ”ง 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!

cfw-easy-utils's People

Contributors

aggressivelymeows avatar justinnoel avatar kalepail avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cfw-easy-utils's Issues

Password functionality

Having the password hashing/checking functionality was really helpful for me!

Quick thought/question... Wouldn't saving the salt phrase along with the hash in the database essentially negate the purpose of hashing? I'm definitely no cryptographer, but that's what it seems like to me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.