0.1.0 • Published 8 months ago

pocketbase-stringify v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

pocketbase-stringify

A cycle-safe, PocketBase-compatible JSON stringifier.

Installation

npm install pocketbase-stringify

Usage

import { stringify, parse, toObject } from 'pocketbase-stringify'

// Safely stringify objects with circular references
const circular = { a: 1 }
circular.self = circular

stringify(circular) // Handles circular references

// Special types are handled automatically
stringify({
  error: new Error('oops'),
  regex: /test/,
  fn: () => console.log('hello'),
})

// Parse JSON strings
const obj = parse(jsonString)

// Parse JSON strings with type support
const obj = parse<MyType>(jsonString)

// Convert complex objects to plain objects
const plainObj = toObject(complexObj)

// Convert complex objects to plain objects of a specific type
const plainObj = toObject<MyType>(complexObj)

API

  • stringify(obj, replacer?, space?) - Stringify with circular reference detection
  • parse<T>(str) - Safe JSON.parse with type support
  • toObject<T>(input) - Convert to plain object
0.1.0

8 months ago

0.0.2

10 months ago