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