From 2463b08b367e485da5172080d66d8c271809bdca Mon Sep 17 00:00:00 2001 From: Charlie Fish Date: Sat, 31 Mar 2018 21:48:55 -0600 Subject: [PATCH] 1.6.0 --- dist/browser/index.js | 2 +- dist/node/array/index.js | 57 +++++++++++++++++++++++++++++++++++++- dist/node/index.js | 3 +- dist/node/other/timeout.js | 13 +++++++++ package-lock.json | 2 +- package.json | 4 +-- 6 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 dist/node/other/timeout.js diff --git a/dist/browser/index.js b/dist/browser/index.js index 6675d01..bcc2599 100644 --- a/dist/browser/index.js +++ b/dist/browser/index.js @@ -1 +1 @@ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).scriptutils=t()}}(function(){return function t(r,n,e){function o(u,s){if(!n[u]){if(!r[u]){var f="function"==typeof require&&require;if(!s&&f)return f(u,!0);if(i)return i(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var h=n[u]={exports:{}};r[u][0].call(h.exports,function(t){var n=r[u][1][t];return o(n||t)},h,h.exports,t,r,n,e)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u1&&this.splice.apply(this,[t,0].concat([].pop.call(arguments)))&&this.insert.apply(this,arguments),this},Array.prototype.remove=function(){var t=arguments,r=this;if(arguments.length<=0)return this;delete arguments.length;return Object.keys(arguments).map(function(r){return t[r]}).sort(function(t,r){return r-t}).forEach(function(t){void 0!=r[t]&&null!=r[t]&&t>=0&&tr}).map(function(r){return t[r]}).reduce(function(t,r){return t+r})),t}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};String.prototype.removeAfter=function(t){var r=this;return Array.isArray(t)||(t=[t]),t.forEach(function(t){r=r.substring(0,r.indexOf(t)>=0&&t.length>0?r.indexOf(t):r.length)}),r=e(r)},String.prototype.removeBefore=function(t){var r=this;Array.isArray(t)||(t=[t]);var n=t.map(function(t){return{index:r.lastIndexOf(t),data:t}}).sort(function(t,r){return r.index-t.index}).filter(function(t){return t.index>=0&&t.data})[0];return n&&(r=r.substring(n.index+1+(n.data.length-1))),r=e(r)}},{}]},{},[3])(3)}); \ No newline at end of file +!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).scriptutils=t()}}(function(){return function t(r,n,e){function o(u,s){if(!n[u]){if(!r[u]){var a="function"==typeof require&&require;if(!s&&a)return a(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var h=n[u]={exports:{}};r[u][0].call(h.exports,function(t){var n=r[u][1][t];return o(n||t)},h,h.exports,t,r,n,e)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u1&&this.splice.apply(this,[t,0].concat([].pop.call(arguments)))&&this.insert.apply(this,arguments),this},Array.prototype.remove=function(){var t=arguments,r=this;if(arguments.length<=0)return this;delete arguments.length;return Object.keys(arguments).map(function(r){return t[r]}).sort(function(t,r){return r-t}).forEach(function(t){void 0!=r[t]&&null!=r[t]&&t>=0&&t>>0,e=arguments[1]>>0,o=e<0?Math.max(n+e,0):Math.min(e,n),i=arguments[2],u=void 0===i?n:i>>0,s=u<0?Math.max(n+u,0):Math.min(u,n);othis.length?r-this.length:0).fill(t)),e(this))},Array.prototype.backPad=function(t,r){return isNaN(r)?this:[].concat(e(this),e(Array(r-this.length>this.length?r-this.length:0).fill(t)))}},{}],3:[function(t,r,n){"use strict";var e=Object.assign||function(t){for(var r=1;rr}).map(function(r){return t[r]}).reduce(function(t,r){return t+r})),t}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};String.prototype.removeAfter=function(t){var r=this;return Array.isArray(t)||(t=[t]),t.forEach(function(t){r=r.substring(0,r.indexOf(t)>=0&&t.length>0?r.indexOf(t):r.length)}),r=e(r)},String.prototype.removeBefore=function(t){var r=this;Array.isArray(t)||(t=[t]);var n=t.map(function(t){return{index:r.lastIndexOf(t),data:t}}).sort(function(t,r){return r.index-t.index}).filter(function(t){return t.index>=0&&t.data})[0];return n&&(r=r.substring(n.index+1+(n.data.length-1))),r=e(r)}},{}]},{},[3])(3)}); \ No newline at end of file diff --git a/dist/node/array/index.js b/dist/node/array/index.js index 4b6aac2..b25b036 100644 --- a/dist/node/array/index.js +++ b/dist/node/array/index.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } @@ -76,4 +76,59 @@ Array.prototype.first = function () { Array.prototype.last = function () { return this[this.length - 1]; +}; + +/* istanbul ignore if */ +if (!Array.prototype.fill) { + Object.defineProperty(Array.prototype, 'fill', { + value: function value(_value) { + + // Steps 1-2. + if (this == null) { + throw new TypeError('this is null or not defined'); + } + + var O = Object(this); + + // Steps 3-5. + var len = O.length >>> 0; + + // Steps 6-7. + var start = arguments[1]; + var relativeStart = start >> 0; + + // Step 8. + var k = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len); + + // Steps 9-10. + var end = arguments[2]; + var relativeEnd = end === undefined ? len : end >> 0; + + // Step 11. + var final = relativeEnd < 0 ? Math.max(len + relativeEnd, 0) : Math.min(relativeEnd, len); + + // Step 12. + while (k < final) { + O[k] = _value; + k++; + } + + // Step 13. + return O; + } + }); +} + +Array.prototype.frontPad = function (item, length) { + if (isNaN(length)) { + return this; + } + return [].concat(_toConsumableArray(Array(length - this.length > this.length ? length - this.length : 0).fill(item)), _toConsumableArray(this)); +}; + +Array.prototype.backPad = function (item, length) { + if (isNaN(length)) { + return this; + } + return [].concat(_toConsumableArray(this), _toConsumableArray(Array(length - this.length > this.length ? length - this.length : 0).fill(item))); }; \ No newline at end of file diff --git a/dist/node/index.js b/dist/node/index.js index 2f67c96..de08d62 100644 --- a/dist/node/index.js +++ b/dist/node/index.js @@ -7,5 +7,6 @@ require('./string/index.js'); require('./promise/index.js'); var otherNumber = require('./other/number.js'); +var timeout = require('./other/timeout.js'); var hash = require('./hash/index.js'); -module.exports = _extends({}, otherNumber, hash); \ No newline at end of file +module.exports = _extends({}, otherNumber, hash, timeout); \ No newline at end of file diff --git a/dist/node/other/timeout.js b/dist/node/other/timeout.js new file mode 100644 index 0000000..672147d --- /dev/null +++ b/dist/node/other/timeout.js @@ -0,0 +1,13 @@ +"use strict"; + +module.exports.timeout = function (ms) { + ms = parseInt(ms); + return new Promise(function (resolve, reject) { + if (isNaN(ms)) { + reject("Invalid miliseconds passed in: " + ms); + } + setTimeout(function () { + return resolve(); + }, ms); + }); +}; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d5e891b..41aa2db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "scriptutils", - "version": "1.5.0", + "version": "1.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0f2326d..f88b173 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scriptutils", - "version": "1.5.0", + "version": "1.6.0", "description": "Utilities to make Javascript Easy", "main": "dist/node/index.js", "scripts": { @@ -66,4 +66,4 @@ "engines": { "node": ">=4.0" } -} \ No newline at end of file +}