javascript-from-string
v1.0.3
Published
A javascript package to extract valid javascript from a string
Downloads
11
Maintainers
Readme
Getting Started
Step 1
Install the dependency
npm i --save javascript-from-string
Or if you prefer yarn
yarn add javascript-from-string
Step 2
Import it in your script
const jsConvert = require('javascript-from-string');
Step 3
Call the Conversion promise
const jsString = '{ prop: "value" }';
jsConvert.convert(jsString)
.then(jsObject => {
console.log(jsObject);
})
.catch(err => {
console.log(err);
})
Or if you prefer to use Async Await
const jsString = '{ prop: "value" }';
async function getObject(jsString) {
const jsObject = await jsConvert.convert(jsString);
return jsObject;
}
getObject(jsString).then(obj => console.log(obj));