https://github.com/ambiere/to-object
Parse string representations of objects into JavaScript objects.
https://github.com/ambiere/to-object
javascript json objects parser strings
Last synced: 5 months ago
JSON representation
Parse string representations of objects into JavaScript objects.
- Host: GitHub
- URL: https://github.com/ambiere/to-object
- Owner: ambiere
- Created: 2024-04-08T18:52:03.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-12T14:14:38.000Z (over 1 year ago)
- Last Synced: 2025-10-22T00:52:34.735Z (8 months ago)
- Topics: javascript, json, objects, parser, strings
- Language: JavaScript
- Homepage:
- Size: 63.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# to-object [](https://github.com/ambiere/to-object/actions/workflows/main.yml)
>Lightweight utility package designed to simplify—
the process of parsing string representations of objects into JavaScript objects.
As implemented in [next-clsx](https://github.com/ambiere/clsx)
>contents
1. [Installattion](#Installattion)
2. [Use case](#Use-case)
3. [License](#License)
## Installattion
```bash
npm install @ambiere/to-object
```
## Use case
In configuration files when import specifier string/path to the configuration module
can only be constructed dynamically, hence static imports become impractical, `require`
not supported in esmodule environment and dynamic imports, `import()` are not feasible
due to their asynchronous nature.
```js
const configs = {
config1: "first",
config2: "second",
//other configs
}
```
```js
import toObject from "@ambiere/to-object"
function configure() {
// ...
/*
* In your code where
* you need to import the configs
* */
const configs = fs.readFileSync("/dynamically/constructed/import/specifier", "utf8")
const parsedConfigs = toObject(configs)
console.log(parsedConfigs.config1) // "first"
// ...
}
```
Note: The content of the configuration module/file to be read,
should be a valid JavaScript object
## License
[MIT license][MIT]
[MIT]: https://github.com/ambiere/project-root/blob/main/license