An open API service indexing awesome lists of open source software.

https://github.com/benallfree/pocketbase-stringify


https://github.com/benallfree/pocketbase-stringify

Last synced: 6 months ago
JSON representation

Awesome Lists containing this project

README

          

# pocketbase-stringify

A cycle-safe, PocketBase-compatible JSON stringifier.

## Installation

```bash
npm install pocketbase-stringify
```

## Usage

```typescript
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(jsonString)

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

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

## API

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