Socket
Socket
Sign inDemoInstall

packetier

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    packetier

A tiny util for making simple structured JSON packets for REST or Websockets


Version published
Weekly downloads
7
increased by40%
Maintainers
1
Install size
44.5 kB
Created
Weekly downloads
 

Readme

Source

Packetier

Installation

npm i --save packetier

Usage

const { packetier } = require("packetier")
// import Packetier from "packetier" // ES6


const success = true;
const payload = { someFancyData: "yeet" }
const meta = { level: 2 }

// Make a new packet
const packet = packetier(success, payload, meta)

// Pack it into a nice JSON String
const packedPacket = packet.pack();
// '{ "success": true, "payload": { "someFancyData": "yeet" }, "meta": { "level": 2 } }'

Example: ExpressJS

// Imports
const express = require("express")
const { packetier } = require("packetier")

// Server setup
const server = express()
  // Use JSON bodies
  .use(express.json())
  // setup a POST route
  .post("/", (req, res) => {  

    const payload = { youSent: req.body }
    const meta = { time: Date.now() }

    res.json(packetier(true, payload, meta))
  })

About

I made Packetier because I was constantly copying the same little makePacket function to every web project. I hope you can find it useful!

Keywords

FAQs

Last updated on 17 Apr 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc