From 03ba3f83dc48b248c0e86e8fdbb35e21ba2c1b75 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Wed, 30 Mar 2016 14:24:22 +0100 Subject: [PATCH] added newObjectFrom --- index.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index dd7784d..da7c595 100644 --- a/index.js +++ b/index.js @@ -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>/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); } }