From e525456d88341bb2199d0da61507950165a7484a Mon Sep 17 00:00:00 2001 From: foxdonut Date: Tue, 31 Jul 2018 07:54:36 -0400 Subject: [PATCH] Further fix for #3 --- dist/seview.js | 15 +++++++++++---- dist/seview.min.js | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/dist/seview.js b/dist/seview.js index 0ebc110..aeba92b 100644 --- a/dist/seview.js +++ b/dist/seview.js @@ -8,7 +8,8 @@ var isNumber = function (x) { return typeof x === "number"; }; var isBoolean = function (x) { return typeof x === "boolean"; }; var isArray = function (x) { return Array.isArray(x); }; - var isObject = function (x) { return typeof x === "object" && !isArray(x) && x !== null && x !== undefined; }; + var isIterable = function (x) { return x != null && typeof x[Symbol.iterator] === "function" && !isString(x); }; + var isObject = function (x) { return x != null && typeof x === "object" && !isArray(x) && !isIterable(x); }; var getString = function (value) { var result = undefined; @@ -52,7 +53,7 @@ // Credit: JSnoX https://github.com/af/JSnoX/blob/master/jsnox.js // matches "input", "input:text" - var tagTypeRegex = /^([a-z1-6]+)(?::([a-z]+))?/; + var tagTypeRegex = /^([A-Za-z0-9-]+)(?::([a-z]+))?/; // matches "#id", ".class", "[name=value]", "[required]" var propsRegex = /((?:#|\.|@)[\w-]+)|(\[.*?\])/g; @@ -127,13 +128,16 @@ if ( result === void 0 ) result = []; rest.forEach(function (child) { + if (isIterable(child)) { + child = Array.from(child); + } // Text node if (getString(child)) { result.push(getString(child)); } else if (isArray(child)) { // Nested array - if (isArray(child[0])) { + if (isArray(child[0]) || isIterable(child[0])) { processChildren(child, result); } // Regular node @@ -214,6 +218,9 @@ result.children = [ getString(rest) ]; } + if (isIterable(rest)) { + rest = Array.from(rest); + } if (isArray(rest)) { // Array of children vs One child node result.children = processChildren( isArray(rest[0]) ? rest : [ rest ] ); @@ -223,7 +230,7 @@ }; var transformNodeDef = function (transform, def) { - if (isArray(def.children)) { + if (isArray(def.children) || isIterable(def.children)) { var result = []; def.children.forEach(function (child) { result.push(isString(child) ? transform(child) : transformNodeDef(transform, child)); diff --git a/dist/seview.min.js b/dist/seview.min.js index 30fe587..64dbf17 100644 --- a/dist/seview.min.js +++ b/dist/seview.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.seview={})}(this,function(t){"use strict";var f=function(t){return"string"==typeof t},l=function(t){return Array.isArray(t)},h=function(t){return"object"==typeof t&&!l(t)&&null!=t},d=function(t){var e=void 0;return f(t)&&0r?i.children=b(t.slice(r-1)):(d(n)&&(i.children=[d(n)]),l(n)&&(i.children=b(l(n[0])?n:[n]))),i},a=function(e,t){if(l(t.children)){var n=[];t.children.forEach(function(t){n.push(f(t)?e(t):a(e,t))}),t.children=n}return e(t)};t.sv=function(n,r){return function(t){var e=i(t,r);return a(n,e)}},Object.defineProperty(t,"__esModule",{value:!0})}); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.seview={})}(this,function(t){"use strict";var f=function(t){return"string"==typeof t},l=function(t){return Array.isArray(t)},h=function(t){return null!=t&&"function"==typeof t[Symbol.iterator]&&!f(t)},d=function(t){return null!=t&&"object"==typeof t&&!l(t)&&!h(t)},v=function(t){var e=void 0;return f(t)&&0r?i.children=j(t.slice(r-1)):(v(n)&&(i.children=[v(n)]),h(n)&&(n=Array.from(n)),l(n)&&(i.children=j(l(n[0])?n:[n]))),i},a=function(e,t){if(l(t.children)||h(t.children)){var n=[];t.children.forEach(function(t){n.push(f(t)?e(t):a(e,t))}),t.children=n}return e(t)};t.sv=function(n,r){return function(t){var e=i(t,r);return a(n,e)}},Object.defineProperty(t,"__esModule",{value:!0})});