From 4362931117050d4b8e2129f7e45fcf62a01479fe Mon Sep 17 00:00:00 2001 From: taoqf Date: Thu, 20 Feb 2020 10:15:24 +0800 Subject: [PATCH] rm tmp file --- t.js | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 t.js diff --git a/t.js b/t.js deleted file mode 100644 index df42ae4..0000000 --- a/t.js +++ /dev/null @@ -1,49 +0,0 @@ -function rawAttributes(rawAttrs) { - const attrs = {}; - if (rawAttrs) { - // const re = /\b([a-z][a-z0-9\-]*)(?:\s*=\s*(?:("[^"]*")|('[^']*')|(\S+)))?/ig; - const re = /\b([a-z][a-z0-9\-]*)(?:\s*=\s*("(?:[^"]*)"|'(?:[^']*)'|(?:\S+)))?/ig; - let match; - console.debug('0000', rawAttrs); - while (match = re.exec(rawAttrs)) { - console.debug('1111', match[1]); - const v = match[2] || ''; - console.debug('2222', v.replace(/^['"]/, '').replace(/['"]$/, '')); - attrs[match[1]] = v.replace(/^['"]/, '').replace(/['"]$/, ''); - } - } - return attrs; -} - -function attr2str(attrs) { - return Object.keys(attrs).map((name) => { - const val = attrs[name]; - if (val === undefined || val === null) { - return name; - } else { - return name + '=' + val - } - }).join(' ') -} - -function main() { - let r; - // r = rawAttributes('a="1"'); - // r = rawAttributes('a=\'1\''); - // r = rawAttributes('a='); - // r = rawAttributes('a'); - // r = rawAttributes('a=1'); - // r = rawAttributes('a=aa b="bb" c= \'cc\' d="\'dd\'" e=e\'e\"e f'); - r = attr2str({ - a: 'aa', - b: '"bb"', - c: "'cc'", - d: "'dd'", - e: `e'e"e`, - f: null - }); - console.debug(r); -} - -main(); -