https://github.com/benallfree/pocketbase-stringify
https://github.com/benallfree/pocketbase-stringify
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/benallfree/pocketbase-stringify
- Owner: benallfree
- License: mit
- Created: 2024-09-09T07:14:49.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-01T13:30:24.000Z (11 months ago)
- Last Synced: 2025-04-15T07:08:49.006Z (6 months ago)
- Language: TypeScript
- Size: 102 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 = circularstringify(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