added newObjectFrom

This commit is contained in:
Martin Donnelly 2016-03-30 14:24:22 +01:00
parent ba475dc668
commit 03ba3f83dc

View File

@ -9,18 +9,25 @@
module.exports = { module.exports = {
reDashObject(source) { newObjectFrom(source, fields) {
var rObj = {}; var rObj = {};
for (var item in source) { for (var item in fields) {
if (source.hasOwnProperty(item)) { if (source.hasOwnProperty(fields[item])) {
let newName = item.replace('_', '-'); rObj[fields[item]] = source[fields[item]];
rObj[newName] = source[item];
}
} }
}
return rObj;
}, reDashObject(source) {
var rObj = {};
for (var item in source) {
if (source.hasOwnProperty(item)) {
let newName = item.replace('_', '-');
rObj[newName] = source[item];
}
}
return rObj; return rObj;
}, }, unDashObject(source) {
unDashObject(source) {
var rObj = {}; var rObj = {};
for (var item in source) { for (var item in source) {
if (source.hasOwnProperty(item)) { if (source.hasOwnProperty(item)) {
@ -55,8 +62,8 @@ module.exports = {
var SCRIPT_REGEX = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi; var SCRIPT_REGEX = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;
var CHECKCHARS = "0123456789" + // Numeric var CHECKCHARS = "0123456789" + // Numeric
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
"abcdefghijklmnopqrstuvwxyz-'" + (_loose === false ? '' : "_,.!~*()@:+/\\"); "abcdefghijklmnopqrstuvwxyz-'" + (_loose === false ? '' : "_,.!~*()@:+/\\");
if (typeof text === 'string') { if (typeof text === 'string') {
while (SCRIPT_REGEX.test(text)) { while (SCRIPT_REGEX.test(text)) {
@ -67,7 +74,8 @@ module.exports = {
ch = text.charAt(i); ch = text.charAt(i);
if (ch === ' ') { if (ch === ' ') {
s.push(' '); s.push(' ');
} else if (ch.charCodeAt(0) < 255 && CHECKCHARS.indexOf(ch) !== -1) { }
else if (ch.charCodeAt(0) < 255 && CHECKCHARS.indexOf(ch) !== -1) {
s.push(ch); s.push(ch);
} }
} }