New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

qpacker

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

qpacker

A lightweight compact data packer/unpacker with base64url encoding

latest
Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

qpacker

npm version build status license downloads

A minimal versioned field-based data packer for token-like use cases.
Light. Safe. Typed.

English Version

✨ Features

  • ✅ Deterministic field-based encoding/decoding
  • ✅ Compact versioned format
  • ✅ Custom field order
  • ✅ Mutation support (change field values)
  • ✅ ESM & CJS support
  • ✅ Full TypeScript typings

📥 Installation

npm install qpacker

🚀 Quick Start

import { QPacker, QPackerError } from 'QPacker';
const fields = ['userId', 'username', 'role'];
const packer = new QPacker(fields);

try {
  // 1. pack
  const token = packer.pack({ userId: '123', username: 'alice', role: 'admin' });
  console.log('Packed token:', token);

  // 2. unpack
  const data = packer.unpack(token);
  console.log('Unpacked data:', data);

  // 3. mutate token 中某字段
  const newToken = packer.mutate(token, { role: 'superadmin' });
  console.log('Mutated token:', newToken);

  // 4. unpack token
  const newData = packer.unpack(newToken);
  console.log('Unpacked mutated data:', newData);

} catch (error) {
  if (error instanceof QPackerError) {
    console.error('QPacker error:', error.message);
  } else {
    console.error('Unexpected error:', error);
  }
}

// 5. test error token
try {
  packer.unpack('invalid.token.string');
} catch (error) {
  if (error instanceof QPackerError) {
    console.error('Expected QPacker error on invalid token:', error.message);
  }
}

🧩 API Reference

  • new QPacker(fields: string[]) - define field order

  • pack(data: Record<string, string>): string - pack object to token

  • unpack(token: string): Record<string, string> - unpack token to object

  • mutate(token: string, patch: Record<string, string>): string - update token fields

🧪 Run Tests

npm test

📄 License

MIT

Keywords

compact

FAQs

Package last updated on 02 Jun 2025

Did you know?

Socket

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