renames.js
791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
var camelCase = require("camelcase");
function renames(result, config)
{
// Avoid hitting same key twice when making changes
var keys = Object.keys(result);
for (var i=keys.length-1; i>=0; i--)
{
var key = keys[i];
if (key != "argv")
{
// If not unknown option
if (config.options[key])
{
var newName = config.options[key].rename;
if (newName !== false)
{
if (newName===true || newName==undefined)
{
newName = camelCase(key);
}
if (newName != key)
{
if (result[newName] != undefined)
{
throw new Error('New name for "'+key+'" already exists');
}
result[newName] = result[key];
delete result[key];
}
}
}
}
}
}
module.exports = renames;