.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / remark-parse / lib / unescape.js
1 'use strict';
2
3 module.exports = factory;
4
5 /* Factory to de-escape a value, based on a list at `key`
6  * in `ctx`. */
7 function factory(ctx, key) {
8   return unescape;
9
10   /* De-escape a string using the expression at `key`
11    * in `ctx`. */
12   function unescape(value) {
13     var prev = 0;
14     var index = value.indexOf('\\');
15     var escape = ctx[key];
16     var queue = [];
17     var character;
18
19     while (index !== -1) {
20       queue.push(value.slice(prev, index));
21       prev = index + 1;
22       character = value.charAt(prev);
23
24       /* If the following character is not a valid escape,
25        * add the slash. */
26       if (!character || escape.indexOf(character) === -1) {
27         queue.push('\\');
28       }
29
30       index = value.indexOf('\\', prev);
31     }
32
33     queue.push(value.slice(prev));
34
35     return queue.join('');
36   }
37 }