underscore-99xp
Advanced tools
Comparing version 1.8.2 to 1.9.0
@@ -246,2 +246,11 @@ import _ from 'underscore'; | ||
return _.isOnlyObject(o) && o.__proto__.__proto__ === null; | ||
}; // Transforms an array on an indexed object | ||
_.toObject = function (a) { | ||
var o = {}; | ||
_.isArray(a) && _.each(a, function (i, x) { | ||
return o[x] = i; | ||
}); | ||
return o; | ||
}; // String Helpers | ||
@@ -248,0 +257,0 @@ // -------------- |
@@ -5,3 +5,3 @@ /** | ||
* ---------------------------------- | ||
* v1.8.1 | ||
* v1.8.2 | ||
* | ||
@@ -266,2 +266,11 @@ * Copyright (c)2021 Bruno Foggia, 99xp. | ||
return _.isOnlyObject(o) && o.__proto__.__proto__ === null; | ||
}; // Transforms an array on an indexed object | ||
_.toObject = function (a) { | ||
var o = {}; | ||
_.isArray(a) && _.each(a, function (i, x) { | ||
return o[x] = i; | ||
}); | ||
return o; | ||
}; // String Helpers | ||
@@ -268,0 +277,0 @@ // -------------- |
@@ -5,3 +5,3 @@ /** | ||
* ---------------------------------- | ||
* v1.8.1 | ||
* v1.8.2 | ||
* | ||
@@ -13,3 +13,3 @@ * Copyright (c)2021 Bruno Foggia, 99xp. | ||
*/ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("underscore"),require("underscore.string")):"function"==typeof define&&define.amd?define(["exports","underscore","underscore.string"],r):r((e=e||self)._x={},e._,e._s)}(this,function(e,r,t){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}r=r&&r.hasOwnProperty("default")?r.default:r,t=t&&t.hasOwnProperty("default")?t.default:t,r.templateSettings={interpolate:/\{\{(.+?)\}\}/g,evaluate:/\{\%(.+?)\%\}/g,escape:/\{-([\s\S]+?)-\}/g},r.result2=function(e,t,n,i,o){var a;if(e&&r.isObject(e)&&(i||o)&&"function"==typeof e[t]){var s=e[t];o&&(s=r.bind(s,o)),i&&(s=r.partial(r.partial,s).apply(null,i)),a=s()||n}else a=r.result(e,t,n);return a},r.defaults2=function(e,t){var n=[],i=[],o=[],a=[];r.map(e,function(e,o){return(r.isJSON(e)||r.isArray(e))&&(r.isJSON(t[o])||r.isArray(t[o]))?i.push(o):n.push(o)}),r.map(t,function(t,n){return(r.isJSON(t)||r.isArray(t))&&(r.isJSON(e[n])||r.isArray(e[n]))?a.push(n):o.push(n)});var s=r.partial(r.pick,e).apply(null,n),u=r.partial(r.pick,e).apply(null,i),l=r.partial(r.pick,t).apply(null,o),c=r.partial(r.pick,t).apply(null,a);s=r.defaults(s,l);var f=[],p=r.clone(u);return r.size(c)&&r.map(c,function(e,t){if(!(-1!==r.indexOf(f,t)||r.isArray(u[t])&&r.isObject(c[t])||r.isObject(u[t])&&r.isArray(c[t]))){f.push(t);var n=r.isArray(c[t])?[]:{},i=r.defaults2(u[t]||n,c[t]);p[t]=r.isArray(n)?r.toArray(i):i}}),r.size(u)&&r.map(u,function(e,t){if(!(-1!==r.indexOf(f,t)||r.isArray(u[t])&&r.isObject(c[t])||r.isObject(u[t])&&r.isArray(c[t]))){f.push(t);var n=r.isArray(u[t])?[]:{},i=r.defaults2(u[t],c[t]||n);p[t]=r.isArray(n)?r.toArray(i):i}}),s=r.extend(s,p)},r.deepValueSearch=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i="string"==typeof e&&e?e.split(/\[/):e instanceof Array?e:[];if(!i.length)return t;var o=i.shift();if(/^(\w|\_|\-)+$/.test(o))return this.deepValueSearch(i,t[o],n);if("]"===o){if(!i.length)return t;if(t instanceof Array||r.isJSON(t)){var a=r.isJSON(t)||n?{}:[];for(var s in t)r.isJSON(a)?a[s]=this.deepValueSearch(r.clone(i),r.clone(t[s]),n):a.push(this.deepValueSearch(r.clone(i),r.clone(t[s]),n));return a}}return/(\w|\_|\-)+\]$/.test(o)?(o=o.replace("]",""),i.length?t?this.deepValueSearch(i,t[o],n):t:t?t[o]:void 0):void 0};var i=function e(r,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t&&"object"===n(t))for(var o in t){var a=r+"["+o+"]";"object"===n(t[o])?e(a,t[o],i):i[a]=t[o]}else i[r]=t;return i};r.jsonToHTMLForm=function(e){if(!r.isJSON(e))return!1;var t={};if(r.size(e))for(var n in e)t=i(n,e[n],t);return t},r.deepKeySearch=function(e,t){var n=r.jsonToHTMLForm(t),i=[];return n&&(i=r.filter(r.keys(n),function(r){return new RegExp("^"+e.replace(/\[\]/,"[\\d+]").replace(/(\[|\])/g,"\\$1"),"g").test(r)})),i},r.isOnlyObject=function(e){return r.isObject(e)&&!r.isArray(e)},r.isJSON=function(e){return r.isOnlyObject(e)&&null===e.__proto__.__proto__},r.matchAll=function(e,r){var t=[];return e.replace(r,function(){var e=[].slice.call(arguments,0),r=e.splice(-2);e.index=r[0],e.input=r[1],t.push(e)}),t.length?t:null},r.regexIndexOf=function(e,r,t){var n=e.substring(t||0).search(r);return n>=0?n+(t||0):n},r.regexLastIndexOf=function(e,r,t){r=r.global?r:new RegExp(r.source,"g"+(r.ignoreCase?"i":"")+(r.multiLine?"m":"")),void 0===t?t=e.length:t<0&&(t=0);for(var n,i=e.substring(0,t+1),o=-1,a=0;null!=(n=r.exec(i));)o=n.index,r.lastIndex=++a;return o},r.toDate=function(e){if(!/^\d{4}\-\d{2}/.test(e))return!1;var t=e.toString().split(r.regexIndexOf(e.toString(),/T/)>0?"T":" "),n=t[0].split("-"),i=t[1]?t[1].split(":"):[0,0,0];return new Date(n[0],parseInt(n[1]||0,10)-1,parseInt(n[2]||1,10),i[0]||0,i[1]||0,i[2]||0)},r.defaultPorts={http:80,https:443,ftp:21},r.parseUrl=function(e){var t=/^((http[s]?|ftp):\/)?\/?([^:\/\s]+)(:([^\/]*))?(((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(\?([^#]*))?(#(.*))?)$/gm.exec(e);if(t)return{schema:t[2],hostname:t[3],port:t[5]||r.defaultPorts[t[2]],path:t[6]||""}},r.promiseSequence=function(e){return new Promise(function(t,n){e.reduce(function(e,t){return e.then(function(e){return r.size(e)&&e[e.length-1]instanceof Error?e:t().then(Array.prototype.concat.bind(e)).catch(Array.prototype.concat.bind(e))})},Promise.resolve([])).then(function(e){e[e.length-1]instanceof Error&&n(e[e.length-1]),t(e)})})},r.mixin(t.exports()),e.default=r,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("underscore"),require("underscore.string")):"function"==typeof define&&define.amd?define(["exports","underscore","underscore.string"],r):r((e=e||self)._x={},e._,e._s)}(this,function(e,r,t){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}r=r&&r.hasOwnProperty("default")?r.default:r,t=t&&t.hasOwnProperty("default")?t.default:t,r.templateSettings={interpolate:/\{\{(.+?)\}\}/g,evaluate:/\{\%(.+?)\%\}/g,escape:/\{-([\s\S]+?)-\}/g},r.result2=function(e,t,n,i,o){var a;if(e&&r.isObject(e)&&(i||o)&&"function"==typeof e[t]){var s=e[t];o&&(s=r.bind(s,o)),i&&(s=r.partial(r.partial,s).apply(null,i)),a=s()||n}else a=r.result(e,t,n);return a},r.defaults2=function(e,t){var n=[],i=[],o=[],a=[];r.map(e,function(e,o){return(r.isJSON(e)||r.isArray(e))&&(r.isJSON(t[o])||r.isArray(t[o]))?i.push(o):n.push(o)}),r.map(t,function(t,n){return(r.isJSON(t)||r.isArray(t))&&(r.isJSON(e[n])||r.isArray(e[n]))?a.push(n):o.push(n)});var s=r.partial(r.pick,e).apply(null,n),u=r.partial(r.pick,e).apply(null,i),l=r.partial(r.pick,t).apply(null,o),c=r.partial(r.pick,t).apply(null,a);s=r.defaults(s,l);var f=[],p=r.clone(u);return r.size(c)&&r.map(c,function(e,t){if(!(-1!==r.indexOf(f,t)||r.isArray(u[t])&&r.isObject(c[t])||r.isObject(u[t])&&r.isArray(c[t]))){f.push(t);var n=r.isArray(c[t])?[]:{},i=r.defaults2(u[t]||n,c[t]);p[t]=r.isArray(n)?r.toArray(i):i}}),r.size(u)&&r.map(u,function(e,t){if(!(-1!==r.indexOf(f,t)||r.isArray(u[t])&&r.isObject(c[t])||r.isObject(u[t])&&r.isArray(c[t]))){f.push(t);var n=r.isArray(u[t])?[]:{},i=r.defaults2(u[t],c[t]||n);p[t]=r.isArray(n)?r.toArray(i):i}}),s=r.extend(s,p)},r.deepValueSearch=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i="string"==typeof e&&e?e.split(/\[/):e instanceof Array?e:[];if(!i.length)return t;var o=i.shift();if(/^(\w|\_|\-)+$/.test(o))return this.deepValueSearch(i,t[o],n);if("]"===o){if(!i.length)return t;if(t instanceof Array||r.isJSON(t)){var a=r.isJSON(t)||n?{}:[];for(var s in t)r.isJSON(a)?a[s]=this.deepValueSearch(r.clone(i),r.clone(t[s]),n):a.push(this.deepValueSearch(r.clone(i),r.clone(t[s]),n));return a}}return/(\w|\_|\-)+\]$/.test(o)?(o=o.replace("]",""),i.length?t?this.deepValueSearch(i,t[o],n):t:t?t[o]:void 0):void 0};var i=function e(r,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(t&&"object"===n(t))for(var o in t){var a=r+"["+o+"]";"object"===n(t[o])?e(a,t[o],i):i[a]=t[o]}else i[r]=t;return i};r.jsonToHTMLForm=function(e){if(!r.isJSON(e))return!1;var t={};if(r.size(e))for(var n in e)t=i(n,e[n],t);return t},r.deepKeySearch=function(e,t){var n=r.jsonToHTMLForm(t),i=[];return n&&(i=r.filter(r.keys(n),function(r){return new RegExp("^"+e.replace(/\[\]/,"[\\d+]").replace(/(\[|\])/g,"\\$1"),"g").test(r)})),i},r.isOnlyObject=function(e){return r.isObject(e)&&!r.isArray(e)},r.isJSON=function(e){return r.isOnlyObject(e)&&null===e.__proto__.__proto__},r.toObject=function(e){var t={};return r.isArray(e)&&r.each(e,function(e,r){return t[r]=e}),t},r.matchAll=function(e,r){var t=[];return e.replace(r,function(){var e=[].slice.call(arguments,0),r=e.splice(-2);e.index=r[0],e.input=r[1],t.push(e)}),t.length?t:null},r.regexIndexOf=function(e,r,t){var n=e.substring(t||0).search(r);return n>=0?n+(t||0):n},r.regexLastIndexOf=function(e,r,t){r=r.global?r:new RegExp(r.source,"g"+(r.ignoreCase?"i":"")+(r.multiLine?"m":"")),void 0===t?t=e.length:t<0&&(t=0);for(var n,i=e.substring(0,t+1),o=-1,a=0;null!=(n=r.exec(i));)o=n.index,r.lastIndex=++a;return o},r.toDate=function(e){if(!/^\d{4}\-\d{2}/.test(e))return!1;var t=e.toString().split(r.regexIndexOf(e.toString(),/T/)>0?"T":" "),n=t[0].split("-"),i=t[1]?t[1].split(":"):[0,0,0];return new Date(n[0],parseInt(n[1]||0,10)-1,parseInt(n[2]||1,10),i[0]||0,i[1]||0,i[2]||0)},r.defaultPorts={http:80,https:443,ftp:21},r.parseUrl=function(e){var t=/^((http[s]?|ftp):\/)?\/?([^:\/\s]+)(:([^\/]*))?(((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(\?([^#]*))?(#(.*))?)$/gm.exec(e);if(t)return{schema:t[2],hostname:t[3],port:t[5]||r.defaultPorts[t[2]],path:t[6]||""}},r.promiseSequence=function(e){return new Promise(function(t,n){e.reduce(function(e,t){return e.then(function(e){return r.size(e)&&e[e.length-1]instanceof Error?e:t().then(Array.prototype.concat.bind(e)).catch(Array.prototype.concat.bind(e))})},Promise.resolve([])).then(function(e){e[e.length-1]instanceof Error&&n(e[e.length-1]),t(e)})})},r.mixin(t.exports()),e.default=r,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=underscore-99xp.min.js.map |
{ | ||
"name": "underscore-99xp", | ||
"version": "1.8.2", | ||
"version": "1.9.0", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "util", |
@@ -272,2 +272,9 @@ // [Underscore-99xp](https://github.com/brunnofoggia/underscore-99xp) is an | ||
// Transforms an array on an indexed object | ||
_.toObject = function (a) { | ||
var o = {}; | ||
_.isArray(a) && _.each(a, (i, x) => (o[x] = i)); | ||
return o; | ||
}; | ||
// String Helpers | ||
@@ -274,0 +281,0 @@ // -------------- |
@@ -93,3 +93,2 @@ import _ from '../lib/underscore-99xp.esm.js'; | ||
var r = _.defaults2(o, defaults); | ||
console.log(r); | ||
@@ -185,2 +184,12 @@ expect( | ||
// to object | ||
test('toObject > testing convert', () => { | ||
var a = [4, 5], | ||
o = _.toObject(a); | ||
expect(_.isJSON(o) && _.size(o) === 2 && o['0'] === 4 && o['1'] === 5).toBe( | ||
true, | ||
); | ||
}); | ||
// matchAll | ||
@@ -187,0 +196,0 @@ test('matchAll > locating every *na* or *no*', () => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
673714
1847