0.1.0 • Published 8 months ago
pocketbase-stringify v0.1.0
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 detectionparse<T>(str)
- Safe JSON.parse with type supporttoObject<T>(input)
- Convert to plain object