JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q31098F
  • License MIT

Extract environment variables

Package Exports

  • json-env-extract

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-env-extract) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

json-env-extract

Extract environment variables from json

const inputText = `
{
    "abc": process.env.ABC,
    "abc2": process.env.ABC,
    'a1': process.env.A1,
    b1: process.env.B1,
    "bcd": 'process.env.BCD',
    'a2': "process.env.A2",
    b2: '\'process.env.B2'
    b3: "\"process.env.B3",
    b4: "\"process.env.B4\""
}
`;

let { text, envs } = jsonEnvExtract(inputText);

let result = text;

for (const group in envs) {
    const regex = new RegExp(`"${group}"`, "ig");
    result = result.replace(regex, envs[group]);
}

expect(Object.values(envs)).toEqual([
    "process.env.ABC",
    "process.env.A1",
    "process.env.B1"
]);
expect(result).toEqual(inputText);