source: trip-planner-front/node_modules/loader-utils/lib/parseString.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 436 bytes
Line 
1'use strict';
2
3function 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
23module.exports = parseString;
Note: See TracBrowser for help on using the repository browser.