Skip to content

Parse string representations of objects into JavaScript objects.

License

Notifications You must be signed in to change notification settings

ambiere/to-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

to-object ci

Lightweight utility package designed to simplify—
the process of parsing string representations of objects into JavaScript objects.

As implemented in next-clsx

contents
1. Installattion
2. Use case
3. License

Installattion

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.

const configs = {
  config1: "first",
  config2: "second",
  //other configs
}
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

About

Parse string representations of objects into JavaScript objects.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published