deep-string-to-object
v1.0.0
Published
Convert a dot-separated string chain into a deeply nested object.
Maintainers
Readme
deep-string-to-object
A lightweight, zero-dependency utility that converts a dot-separated string chain into a deeply nested object
Features
- Dot notation to object: converts
"a.b.c"into{ a: { b: { c: value } } } - DoS protection: enforces a maximum chain depth (default: 32) to prevent stack abuse
- Secure: blocks prototype pollution
- Immutable: always returns a new object
- Dual format: ships both CJS and ESM builds
- Zero dependencies
Installation
npm install deep-string-to-objectyarn add deep-string-to-objectpnpm add deep-string-to-objectUsage
ESM
import deepConvert from 'deep-string-to-object';
const result = deepConvert('server.database.host', 'localhost');
// { server: { database: { host: 'localhost' } } }CJS
const deepConvert = require('deep-string-to-object');
const result = deepConvert('a.b.c.d.e', 12);
// { a: { b: { c: { d: { e: 12 } } } } }Testing
git clone [email protected]:work-state/deep-string-to-object.git
cd deep-string-to-object
npm install
npm testCompatibility
- Node.js >= 14
- Browsers: all modern browsers (ES2015+). If you need to support older browsers, configure yout bundler (Babel, SWC) to transpile
node_modules/deep-string-to-object
