aswi2020vldc-gitlab/templetes/node_modules/loader-utils/lib/parseString.js @ 143404cb
1 | 3a515b92 | cagy | 'use strict'; |
---|---|---|---|
2 | |||
3 | function parseString(str) { |
||
4 | try { |
||
5 | if (str[0] === '"') { |
||
6 | return JSON.parse(str); |
||
7 | }
|
||
8 | |||
9 | if (str[0] === "'" && str.substr(str.length - 1) === "'") { |
||
10 | return parseString( |
||
11 | str
|
||
12 | .replace(/\\.|"/g, (x) => (x === '"' ? '\\"' : x)) |
||
13 | .replace(/^'|'$/g, '"') |
||
14 | );
|
||
15 | }
|
||
16 | |||
17 | return JSON.parse('"' + str + '"'); |
||
18 | } catch (e) { |
||
19 | return str; |
||
20 | }
|
||
21 | }
|
||
22 | |||
23 | module.exports = parseString; |