H
H
hckn2018-09-16 01:56:05
JavaScript
hckn, 2018-09-16 01:56:05

How to parse stylus to JSON?

There is a file with several hundred variables of the form

$deep-orange-base = #ff5722
$deep-orange-lighten-5 = #fbe9e7
$deep-orange-lighten-4 = #ffccbc
$deep-orange-lighten-3 = #ffab91
$deep-orange-lighten-2 = #ff8a65
$deep-orange-lighten-1 = #ff7043
$deep-orange-darken-1 = #f4511e
$deep-orange-darken-2 = #e64a19
$deep-orange-darken-3 = #d84315
$deep-orange-darken-4 = #bf360c
$deep-orange-accent-1 = #ff9e80
$deep-orange-accent-2 = #ff6e40
$deep-orange-accent-3 = #ff3d00
$deep-orange-accent-4 = #dd2c00

How would you parse this into a JSON or JS object?
[
  { "deep-orange-darken-1": "#f4511e" }
]

Answer the question

In order to leave comments, you need to log in

3 answer(s)
0
0xD34F, 2018-09-16
@hckn

fetch(filename)
  .then(r => r.text())
  .then(r => r.split('\n').map(n => {
    const [ key, val ] = n.split(' = ');
    return { [key]: val };
  }))
  .then(arr => {
    // ну вот вам ваши объекты
  });

UPD. If suddenly there is something else in the file, besides the lines of the type you specified, you can get them using regular expressions, you will need to replace them with , for example. r.split('\n')r.match(/\$[a-z0-9-]+ = #[0-9a-f]{6}/g)

L
lnked, 2015-04-06
@lnked

You had 1 path to the site files on the server, and other paths on the local machine, you need to correct the paths in the scripts on the local machine

S
ShamblerR, 2015-04-06
@ShamblerR

here's the plus of the "correct code";))
1. change the permissions on the files relative to your system, including the user and the group.
2. Rewrite all paths in all configs relative to the new system.
3. In general, these files should be there on what you raised at home not on a windows demon?
THOUGH I'm not lying /usr/share/pear what? You don't have sape on your site at once? so if it is, can you first turn it off and then try to run the site on a different domain?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question