.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / node_modules / camelcase-keys / index.js
1 'use strict';
2 const mapObj = require('map-obj');
3 const camelCase = require('camelcase');
4 const QuickLru = require('quick-lru');
5
6 const has = (arr, key) => arr.some(x => typeof x === 'string' ? x === key : x.test(key));
7 const cache = new QuickLru({maxSize: 100000});
8
9 const camelCaseConvert = (input, opts) => {
10         opts = Object.assign({
11                 deep: false
12         }, opts);
13
14         const exclude = opts.exclude;
15
16         return mapObj(input, (key, val) => {
17                 if (!(exclude && has(exclude, key))) {
18                         if (cache.has(key)) {
19                                 key = cache.get(key);
20                         } else {
21                                 const ret = camelCase(key);
22
23                                 if (key.length < 100) { // Prevent abuse
24                                         cache.set(key, ret);
25                                 }
26
27                                 key = ret;
28                         }
29                 }
30
31                 return [key, val];
32         }, {deep: opts.deep});
33 };
34
35 module.exports = (input, opts) => {
36         if (Array.isArray(input)) {
37                 return Object.keys(input).map(key => camelCaseConvert(input[key], opts));
38         }
39         return camelCaseConvert(input, opts);
40 };
41