package/.editorconfig000644 0000000440 3560116604 011733 0ustar00000000 000000 # EditorConfig is awesome: http://EditorConfig.org # top-most EditorConfig file root = true [*] charset = utf-8 end_of_line = lf insert_final_newline = true indent_style = tab trim_trailing_whitespace = true [*.md] indent_size = 2 indent_style = space trim_trailing_whitespace = false package/LICENSE000644 0000001405 3560116604 010265 0ustar00000000 000000 ISC License Copyright (c) 2011-2019, Mariusz Nowak, @medikoo, medikoo.com Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. package/test/object/entries/_tests.js000644 0000001352 3560116604 015016 0ustar00000000 000000 "use strict"; var assert = require("chai").assert; module.exports = function (entries) { it("Should resolve entries array for an object", function () { assert.deepEqual(entries({ foo: "bar" }), [["foo", "bar"]]); }); if (Object.defineProperty) { it("Should not resolve non-enumerable properties", function () { var obj = { visible: true }; Object.defineProperty(obj, "hidden", { value: "elo" }); assert.deepEqual(entries(obj), [["visible", true]]); }); } it("Should resolve entries array for a primitive", function () { assert.deepEqual(entries("raz"), [ ["0", "r"], ["1", "a"], ["2", "z"] ]); }); it("Should throw on non-value", function () { assert["throws"](function () { entries(null); }, TypeError); }); }; package/test/string_/includes/_tests.js000644 0000003147 3560116604 015356 0ustar00000000 000000 "use strict"; var assert = require("chai").assert; module.exports = function (includes) { it("Should return true when context contains search string", function () { assert.equal(includes.call("razdwatrzy", "dwa"), true); }); it("Should return true when context starts with search string", function () { assert.equal(includes.call("razdwa", "raz"), true); }); it("Should return true when context ends with search string", function () { assert.equal(includes.call("razdwa", "dwa"), true); }); it("Should return false when string doesn't contain search string", function () { assert.equal(includes.call("razdwa", "trzy"), false); }); it("Should return false when context is empty and search string is not", function () { assert.equal(includes.call("", "a"), false); }); it("Should return false when search string is longer than context", function () { assert.equal(includes.call("raz", "razdwa"), false); }); it("Should return true when search string is same as context ", function () { assert.equal(includes.call("raz", "raz"), true); }); it("Should return true when context starts with search string", function () { assert.equal(includes.call("razdwa", "raz"), true); }); it("Should return true when search string is empty", function () { assert.equal(includes.call("raz", ""), true); }); it("Should return true when both context and search string are empty", function () { assert.equal(includes.call("", ""), true); }); it("Should support position argument", function () { assert.equal(includes.call("razdwa", "raz", 1), false); assert.equal(includes.call("razdwa", "dwa", 1), true); }); }; package/math/ceil-10.js000644 0000000122 3560116604 011674 0ustar00000000 000000 "use strict"; module.exports = require("../lib/private/decimal-adjust")("ceil"); package/test/math/ceil-10.js000644 0000000515 3560116604 012661 0ustar00000000 000000 "use strict"; var assert = require("chai").assert , ceil10 = require("../../math/ceil-10"); describe("math/ceil-10", function () { it("Should ceil", function () { assert.equal(ceil10(55.51, -1), 55.6); assert.equal(ceil10(51, 1), 60); assert.equal(ceil10(-55.59, -1), -55.5); assert.equal(ceil10(-59, 1), -50); }); }); package/object/clear.js000644 0000000605 3560116604 012153 0ustar00000000 000000 "use strict"; var ensureObject = require("type/object/ensure") , ensure = require("type/ensure"); var objPropertyIsEnumerable = Object.prototype.propertyIsEnumerable; module.exports = function (object) { ensure(["object", object, ensureObject]); for (var key in object) { if (!objPropertyIsEnumerable.call(object, key)) continue; delete object[key]; } return object; }; package/test/object/clear.js000644 0000001412 3560116604 013127 0ustar00000000 000000 "use strict"; var assert = require("chai").assert , clear = require("../../object/clear"); describe("object/clear", function () { it("Should clear enumerable properties", function () { var obj = { foo: "bar", elo: "sfds" }; clear(obj); // eslint-disable-next-line no-unreachable-loop for (var key in obj) throw new Error("Unexpected" + key); }); it("Should return input object", function () { var obj = {}; assert.equal(clear(obj), obj); }); if (Object.defineProperty && Object.keys) { it("Should keep non enumerable properties", function () { var obj = { foo: "bar", elo: "sfds" }; Object.defineProperty(obj, "hidden", { value: "some" }); clear(obj); assert.deepEqual(Object.keys(obj), []); assert.equal(obj.hidden, "some"); }); } }); package/lib/private/decimal-adjust.js000644 0000001437 3560116604 014731 0ustar00000000 000000 // Credit: // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round // #Decimal_rounding "use strict"; var isValue = require("type/object/is") , ensureInteger = require("type/integer/ensure"); var split = String.prototype.split; module.exports = function (type) { return function (value/*, exp*/) { value = Number(value); var exp = arguments[1]; if (isValue(exp)) exp = ensureInteger(exp); if (!value) return value; if (!exp) return Math[type](value); if (!isFinite(value)) return value; // Shift var tokens = split.call(value, "e"); value = Math[type](tokens[0] + "e" + ((tokens[1] || 0) - exp)); // Shift back tokens = value.toString().split("e"); return Number(tokens[0] + "e" + (Number(tokens[1] || 0) + exp)); }; }; package/lib/private/define-function-length.js000644 0000002761 3560116604 016400 0ustar00000000 000000 "use strict"; var test = function (arg1, arg2) { return arg2; }; try { Object.defineProperty(test, "length", { configurable: true, writable: false, enumerable: false, value: 1 }); } catch (ignore) {} if (test.length === 1) { // ES2015+ var desc = { configurable: true, writable: false, enumerable: false }; module.exports = function (length, fn) { if (fn.length === length) return fn; desc.value = length; return Object.defineProperty(fn, "length", desc); }; return; } module.exports = function (length, fn) { if (fn.length === length) return fn; switch (length) { case 0: return function () { return fn.apply(this, arguments); }; case 1: return function (ignored1) { return fn.apply(this, arguments); }; case 2: return function (ignored1, ignored2) { return fn.apply(this, arguments); }; case 3: return function (ignored1, ignored2, ignored3) { return fn.apply(this, arguments); }; case 4: return function (ignored1, ignored2, ignored3, ignored4) { return fn.apply(this, arguments); }; case 5: return function (ignored1, ignored2, ignored3, ignored4, ignored5) { return fn.apply(this, arguments); }; case 6: return function (ignored1, ignored2, ignored3, ignored4, ignored5, ignored6) { return fn.apply(this, arguments); }; case 7: return function (ignored1, ignored2, ignored3, ignored4, ignored5, ignored6, ignored7) { return fn.apply(this, arguments); }; default: throw new Error("Usupported function length"); } }; package/test/thenable_/finally.js000644 0000005517 3560116604 014164 0ustar00000000 000000 "use strict"; var assert = require("chai").assert , sinon = require("sinon") , identity = require("../../function/identity") , finallyMethod = require("../../thenable_/finally"); var throwUnexpected = function () { throw new Error("Unexpected"); }; describe("thenable_/finally", function () { describe("Successful on fulfilled", function () { var callback, input, result; before(function () { callback = sinon.fake(); input = Promise.resolve("foo"); result = finallyMethod.call(input, callback); return result; }); it("Should invoke finally callback", function () { assert(callback.calledOnce); }); it("Return promise should fulfill with original result", function () { return Promise.all([input, result]).then(function (results) { assert.equal(results[0], results[1]); }); }); }); describe("Successful on rejected", function () { var callback, input, result; before(function () { var inputError = new Error("Rejected"); callback = sinon.fake(); input = Promise.reject(inputError); result = finallyMethod.call(input, callback); return result["catch"](function (error) { if (error !== inputError) throw error; }); }); it("Should invoke finally callback", function () { assert(callback.calledOnce); }); it("Return promise should fulfill with original result", function () { return Promise.all([input["catch"](identity), result["catch"](identity)]).then( function (results) { assert.equal(results[0], results[1]); } ); }); }); describe("Failed on fulfilled", function () { var callback, result, finallyError; before(function () { finallyError = new Error("Finally Rejected"); callback = sinon.fake["throws"](finallyError); var input = Promise.resolve("foo"); result = finallyMethod.call(input, callback); return result["catch"](function (error) { if (error !== finallyError) throw error; }); }); it("Should invoke finally callback", function () { assert(callback.calledOnce); }); it("Return promise should be rejected with finally error", function () { return result.then(throwUnexpected, function (error) { assert.equal(finallyError, error); }); }); }); describe("Failed on rejected", function () { var callback, result, finallyError; before(function () { finallyError = new Error("Finally Rejected"); callback = sinon.fake["throws"](finallyError); var input = Promise.reject(new Error("Rejected")); result = finallyMethod.call(input, callback); return result["catch"](function (error) { if (error !== finallyError) throw error; }); }); it("Should invoke finally callback", function () { assert(callback.calledOnce); }); it("Return promise should be rejected with finally error", function () { return result.then(throwUnexpected, function (error) { assert.equal(finallyError, error); }); }); }); }); package/thenable_/finally.js000644 0000001241 3560116604 013173 0ustar00000000 000000 "use strict"; var ensurePlainFunction = require("type/plain-function/ensure") , isThenable = require("type/thenable/is") , ensureThenable = require("type/thenable/ensure"); var resolveCallback = function (callback, next) { var callbackResult = callback(); if (!isThenable(callbackResult)) return next(); return callbackResult.then(next); }; module.exports = function (callback) { ensureThenable(this); ensurePlainFunction(callback); return this.then( function (result) { return resolveCallback(callback, function () { return result; }); }, function (error) { return resolveCallback(callback, function () { throw error; }); } ); }; package/math/floor-10.js000644 0000000123 3560116604 012102 0ustar00000000 000000 "use strict"; module.exports = require("../lib/private/decimal-adjust")("floor"); package/test/math/floor-10.js000644 0000000526 3560116604 013070 0ustar00000000 000000 "use strict"; var assert = require("chai").assert , floor10 = require("../../math/floor-10"); describe("math/floor-10", function () { it("Should floor", function () { assert.equal(floor10(55.59, -1), 55.5); assert.equal(floor10(59, 1), 50); assert.equal(floor10(-55.51, -1), -55.6); assert.equal(floor10(-51, 1), -60); }); }); package/function/identity.js000644 0000000104 3560116604 013267 0ustar00000000 000000 "use strict"; module.exports = function (value) { return value; }; package/test/function/identity.js000644 0000000602 3560116604 014251 0ustar00000000 000000 "use strict"; var assert = require("chai").assert , identity = require("../../function/identity"); describe("function/identity", function () { it("Should return first argument", function () { assert.equal(identity("foo"), "foo"); var object = {}; assert.equal(identity(object), object); assert.equal(identity(), undefined); assert.equal(identity(1, 2, 3), 1); }); }); package/object/entries/implement.js000644 0000000312 3560116604 014523 0ustar00000000 000000 "use strict"; if (!require("./is-implemented")()) { Object.defineProperty(Object, "entries", { value: require("./implementation"), configurable: true, enumerable: false, writable: true }); } package/global-this/implementation.js000644 0000002001 3560116604 015041 0ustar00000000 000000 var naiveFallback = function () { if (typeof self === "object" && self) return self; if (typeof window === "object" && window) return window; throw new Error("Unable to resolve global `this`"); }; module.exports = (function () { if (this) return this; // Unexpected strict mode (may happen if e.g. bundled into ESM module) // Thanks @mathiasbynens -> https://mathiasbynens.be/notes/globalthis // In all ES5+ engines global object inherits from Object.prototype // (if you approached one that doesn't please report) try { Object.defineProperty(Object.prototype, "__global__", { get: function () { return this; }, configurable: true }); } catch (error) { // Unfortunate case of Object.prototype being sealed (via preventExtensions, seal or freeze) return naiveFallback(); } try { // Safari case (window.__global__ is resolved with global context, but __global__ does not) if (!__global__) return naiveFallback(); return __global__; } finally { delete Object.prototype.__global__; } })(); package/object/entries/implementation.js000644 0000000564 3560116604 015567 0ustar00000000 000000 "use strict"; var ensureValue = require("type/value/ensure"); var objPropertyIsEnumerable = Object.prototype.propertyIsEnumerable; module.exports = function (object) { object = Object(ensureValue(object)); var result = []; for (var key in object) { if (!objPropertyIsEnumerable.call(object, key)) continue; result.push([key, object[key]]); } return result; }; package/string_/includes/implementation.js000644 0000000261 3560116604 016115 0ustar00000000 000000 "use strict"; var indexOf = String.prototype.indexOf; module.exports = function (searchString/*, position*/) { return indexOf.call(this, searchString, arguments[1]) > -1; }; package/test/global-this/implementation.js000644 0000000776 3560116604 016041 0ustar00000000 000000 "use strict"; var isObject = require("type/object/is") , assert = require("chai").assert , globalThis = require("../../global-this/implementation"); describe("global-this/implementation", function () { it("Should be an object", function () { assert(isObject(globalThis)); }); it("Should be a global object", function () { assert.equal(globalThis.Array, Array); }); it("Internal resolution should not introduce side-effects", function () { assert(!("__global__" in Object.prototype)); }); }); package/test/object/entries/implementation.js000644 0000000277 3560116604 016547 0ustar00000000 000000 "use strict"; var entries = require("../../../object/entries/implementation") , tests = require("./_tests"); describe("object/entries/implementation", function () { tests(entries); }); package/test/string_/includes/implementation.js000644 0000000230 3560116604 017070 0ustar00000000 000000 "use strict"; describe("string_/includes/implementation", function () { require("./_tests")(require("../../../string_/includes/implementation")); }); package/global-this/index.js000644 0000000152 3560116604 013130 0ustar00000000 000000 "use strict"; module.exports = require("./is-implemented")() ? globalThis : require("./implementation"); package/object/entries/index.js000644 0000000156 3560116604 013646 0ustar00000000 000000 "use strict"; module.exports = require("./is-implemented")() ? Object.entries : require("./implementation"); package/string_/includes/index.js000644 0000000173 3560116604 014201 0ustar00000000 000000 "use strict"; module.exports = require("./is-implemented")() ? String.prototype.includes : require("./implementation"); package/test/global-this/index.js000644 0000000541 3560116604 014111 0ustar00000000 000000 "use strict"; var isObject = require("type/object/is") , assert = require("chai").assert , globalThis = require("../../global-this"); describe("global-this", function () { it("Should be an object", function () { assert(isObject(globalThis)); }); it("Should be a global object", function () { assert.equal(globalThis.Array, Array); }); }); package/test/object/entries/index.js000644 0000000247 3560116604 014626 0ustar00000000 000000 "use strict"; var entries = require("../../../object/entries") , tests = require("./_tests"); describe("object/entries/index", function () { tests(entries); }); package/test/string_/includes/index.js000644 0000000211 3560116604 015151 0ustar00000000 000000 "use strict"; describe("string_/includes/implementation", function () { require("./_tests")(require("../../../string_/includes")); }); package/global-this/is-implemented.js000644 0000000250 3560116604 014734 0ustar00000000 000000 "use strict"; module.exports = function () { if (typeof globalThis !== "object") return false; if (!globalThis) return false; return globalThis.Array === Array; }; package/object/entries/is-implemented.js000644 0000000213 3560116604 015445 0ustar00000000 000000 "use strict"; module.exports = function () { try { return Object.entries({ foo: 12 })[0][0] === "foo"; } catch (e) { return false; } }; package/string_/includes/is-implemented.js000644 0000000310 3560116604 015777 0ustar00000000 000000 "use strict"; var str = "razdwatrzy"; module.exports = function () { if (typeof str.includes !== "function") return false; return str.includes("dwa") === true && str.includes("foo") === false; }; package/test/global-this/is-implemented.js000644 0000000425 3560116604 015717 0ustar00000000 000000 "use strict"; var assert = require("chai").assert , isImplemented = require("../../global-this/is-implemented"); describe("global-this/is-implemented", function () { it("Should return boolean", function () { assert.equal(typeof isImplemented(), "boolean"); }); }); package/test/object/entries/is-implemented.js000644 0000000360 3560116604 016427 0ustar00000000 000000 "use strict"; var assert = require("chai").assert , isImplemented = require("../../../object/entries/is-implemented"); describe("object/entries/is-implemented", function () { assert.equal(typeof isImplemented(), "boolean"); }); package/test/string_/includes/is-implemented.js000644 0000000442 3560116604 016764 0ustar00000000 000000 "use strict"; var assert = require("chai").assert , isImplemented = require("../../../string_/includes/is-implemented"); describe("string_/includes/is-implemented", function () { it("Should return boolean", function () { assert.equal(typeof isImplemented(), "boolean"); }); }); package/promise/limit.js000644 0000002746 3560116604 012423 0ustar00000000 000000 "use strict"; var ensureNaturalNumber = require("type/natural-number/ensure") , ensurePlainFunction = require("type/plain-function/ensure") , ensure = require("type/ensure") , defineFunctionLength = require("../lib/private/define-function-length"); module.exports = function (limit, callback) { limit = ensure( ["limit", limit, ensureNaturalNumber, { min: 1 }], ["callback", callback, ensurePlainFunction] )[0]; var Promise = this, ongoingCount = 0, pending = []; var onSuccess, onFailure; var release = function () { --ongoingCount; if (ongoingCount >= limit) return; var next = pending.shift(); if (!next) return; ++ongoingCount; try { next.resolve( Promise.resolve(callback.apply(next.context, next.arguments)).then( onSuccess, onFailure ) ); } catch (exception) { release(); next.reject(exception); } }; onSuccess = function (value) { release(); return value; }; onFailure = function (exception) { release(); throw exception; }; return defineFunctionLength(callback.length, function () { if (ongoingCount >= limit) { var context = this, args = arguments; return new Promise(function (resolve, reject) { pending.push({ context: context, arguments: args, resolve: resolve, reject: reject }); }); } ++ongoingCount; try { return Promise.resolve(callback.apply(this, arguments)).then(onSuccess, onFailure); } catch (exception) { return onFailure(exception); } }); }; package/test/promise/limit.js000644 0000002643 3560116604 013376 0ustar00000000 000000 "use strict"; var assert = require("chai").assert , wait = require("timers-ext/promise/sleep") , limit = require("../../promise/limit").bind(Promise); describe("promise/limit", function () { it("Should limit executions", function () { var count = 0; var callCount = 0; var limited = limit(2, function (arg1) { var id = ++count; assert.equal(arg1, "foo"); assert.equal(arguments[1], id); return wait(10).then(function () { return id; }); }); limited("foo", ++callCount); assert.equal(count, 1); limited("foo", ++callCount); assert.equal(count, 2); limited("foo", ++callCount); assert.equal(count, 2); limited("foo", ++callCount); assert.equal(count, 2); return wait(25).then(function () { assert.equal(count, 4); limited("foo", ++callCount); assert.equal(count, 5); limited("foo", ++callCount); assert.equal(count, 6); limited("foo", ++callCount); assert.equal(count, 6); return wait(25).then(function () { assert.equal(count, 7); }); }); }); it("Should resolve with expected result", function () { var count = 0; var limited = limit(2, function () { var id = ++count; return wait(10).then(function () { return id; }); }); limited(); assert.equal(count, 1); limited(); assert.equal(count, 2); return limited().then(function (result) { assert.equal(result, 3); limited().then(function (result) { assert.equal(result, 4); }); }); }); }); package/string/random.js000644 0000002573 3560116604 012413 0ustar00000000 000000 "use strict"; var isObject = require("type/object/is") , ensureNaturalNumber = require("type/natural-number/ensure") , ensureString = require("type/string/ensure"); var generated = Object.create(null), random = Math.random, uniqTryLimit = 100; var getChunk = function () { return random().toString(36).slice(2); }; var getString = function (length, charset) { var str; if (charset) { var charsetLength = charset.length; str = ""; for (var i = 0; i < length; ++i) { str += charset.charAt(Math.floor(Math.random() * charsetLength)); } return str; } str = getChunk(); if (length === null) return str; while (str.length < length) str += getChunk(); return str.slice(0, length); }; module.exports = function (/* options */) { var options = arguments[0]; if (!isObject(options)) options = {}; var length = ensureNaturalNumber(options.length, { "default": 10 }) , isUnique = options.isUnique , charset = ensureString(options.charset, { isOptional: true }); var str = getString(length, charset); if (isUnique) { var count = 0; while (generated[str]) { if (++count === uniqTryLimit) { throw new Error( "Cannot generate random string.\n" + "String.random is not designed to effectively generate many short and " + "unique random strings" ); } str = getString(length); } generated[str] = true; } return str; }; package/test/string/random.js000644 0000002530 3560116604 013363 0ustar00000000 000000 "use strict"; var assert = require("chai").assert , random = require("../../string/random"); var isValidFormat = RegExp.prototype.test.bind(/^[a-z0-9]+$/); describe("string/random", function () { it("Should return string", function () { assert.equal(typeof random(), "string"); }); it("Should return by default string of length 10", function () { assert.equal(random().length, 10); }); it("Should support custom charset", function () { var charset = "abc"; var result = random({ charset: charset }); assert.equal(result.length, 10); for (var i = 0; i < result.length; ++i) { assert.isAtLeast(charset.indexOf(result.charAt(i)), 0); } }); it("Should ensure unique string with `isUnique` option", function () { assert.notEqual(random({ isUnique: true }), random({ isUnique: true })); }); it("Should contain only ascii chars", function () { assert(isValidFormat(random())); }); it("Should support `length` option", function () { assert.equal(random({ length: 4 }).length, 4); assert.equal(random({ length: 100 }).length, 100); assert.equal(random({ length: 0 }).length, 0); }); it("Should crash if unable to generate unique string with `isUnique` optin", function () { random({ length: 0, isUnique: true }); assert["throws"](function () { random({ length: 0, isUnique: true }); }, "Cannot generate random string"); }); }); package/math/round-10.js000644 0000000123 3560116604 012110 0ustar00000000 000000 "use strict"; module.exports = require("../lib/private/decimal-adjust")("round"); package/test/math/round-10.js000644 0000001121 3560116604 013066 0ustar00000000 000000 "use strict"; var assert = require("chai").assert , round10 = require("../../math/round-10"); describe("math/round-10", function () { it("Should round", function () { assert.equal(round10(55.55, -1), 55.6); assert.equal(round10(55.549, -1), 55.5); assert.equal(round10(55, 1), 60); assert.equal(round10(54.9, 1), 50); assert.equal(round10(-55.55, -1), -55.5); assert.equal(round10(-55.551, -1), -55.6); assert.equal(round10(-55, 1), -50); assert.equal(round10(-55.1, 1), -60); assert.equal(round10(1.005, -2), 1.01); assert.equal(round10(-1.005, -2), -1.0); }); }); package/package.json000644 0000004361 3560116604 011552 0ustar00000000 000000 { "name": "ext", "version": "1.6.0", "description": "JavaScript utilities with respect to emerging standard", "author": "Mariusz Nowak (http://www.medikoo.com/)", "keywords": [ "ecmascript", "es", "es6", "extensions", "ext", "addons", "lodash", "extras", "harmony", "javascript", "polyfill", "shim", "util", "utils", "utilities" ], "repository": { "type": "git", "url": "https://github.com/medikoo/es5-ext#ext" }, "dependencies": { "type": "^2.5.0" }, "devDependencies": { "chai": "^4.3.4", "eslint": "^7.32.0", "eslint-config-medikoo": "^4.1.0", "git-list-updated": "^1.2.1", "husky": "^4.3.8", "lint-staged": "^11.1.2", "mocha": "^6.2.3", "prettier-elastic": "^2.2.1", "sinon": "^8.1.1", "timers-ext": "^0.1.7" }, "husky": { "hooks": { "pre-commit": "lint-staged" } }, "lint-staged": { "*.js": [ "eslint" ], "*.{css,html,js,json,md,yaml,yml}": [ "prettier -c" ] }, "eslintIgnore": [ "_es5-ext" ], "eslintConfig": { "extends": "medikoo/es3", "root": true, "overrides": [ { "files": "global-this/implementation.js", "globals": { "__global__": true, "self": true, "window": true }, "rules": { "no-extend-native": "off", "strict": "off" } }, { "files": [ "global-this/is-implemented.js", "global-this/index.js" ], "globals": { "globalThis": true } }, { "files": "test/**/*.js", "env": { "mocha": true } }, { "files": [ "test/promise/limit.js", "test/thenable_/finally.js" ], "globals": { "Promise": true } } ] }, "prettier": { "printWidth": 100, "tabWidth": 4, "quoteProps": "preserve", "overrides": [ { "files": "*.md", "options": { "tabWidth": 2 } } ] }, "mocha": { "recursive": true }, "scripts": { "lint": "eslint .", "lint-updated": "pipe-git-updated --ext=js -- eslint --ignore-pattern '!*'", "prettier-check-updated": "pipe-git-updated --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier -c", "prettify": "prettier --write --ignore-path .gitignore '**/*.{css,html,js,json,md,yaml,yml}'", "test": "mocha" }, "license": "ISC" } package/docs/math/ceil-10.md000644 0000000246 3560116604 012617 0ustar00000000 000000 # `Math.ceil10` _(ext/math/ceil-10)_ Decimal ceil ```javascript const ceil10 = require("ext/math/ceil-10"); ceil10(55.51, -1); // 55.6 ceil10(-59, 1); // -50; ``` package/CHANGELOG.md000644 0000006334 3560116604 011077 0ustar00000000 000000 # Changelog All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. ## [1.6.0](https://github.com/medikoo/es5-ext/compare/v1.5.0...v1.6.0) (2021-09-24) ### Features - `Object.clear` util ([a955da4](https://github.com/medikoo/es5-ext/commit/a955da41e65a25ad87a46234bae065f096abd1d2)) ### Bug Fixes - Fix `Object.entries` to not return non enumerable properties ([44fb872](https://github.com/medikoo/es5-ext/commit/44fb87266617378d2f47a1a5baad6280bf6298a8)) ## [1.5.0](https://github.com/medikoo/es5-ext/compare/v1.3.0...v1.5.0) (2021-08-23) ### Features - `Promise.limit` ([060a05d](https://github.com/medikoo/es5-ext/commit/060a05d4751cd291c6dd7641f5a73ba9338ea7ab)) - `String.prototype.includes` ([ceebe8d](https://github.com/medikoo/es5-ext/commit/ceebe8dfd6f479d6a7e7b6cd79369291869ee2dd)) - `charset` option for `String.random` ([2a20eeb](https://github.com/medikoo/es5-ext/commit/2a20eebc5ae784e5c1aacd2c54433fe92a9464c9)) ## [1.4.0](https://github.com///compare/v1.3.0...v1.4.0) (2019-11-29) ### Features - `charset` option for `String.random` ([2a20eeb](https://github.com///commit/2a20eebc5ae784e5c1aacd2c54433fe92a9464c9)) - `String.prototype.includes` implementation ([ceebe8d](https://github.com///commit/ceebe8dfd6f479d6a7e7b6cd79369291869ee2dd)) ## [1.3.0](https://github.com///compare/v1.2.1...v1.3.0) (2019-11-28) ### Features - `String.random` util ([5b5860a](https://github.com///commit/5b5860ac545b05f00527e00295fdb4f97e4a4e5b)) ### [1.2.1](https://github.com///compare/v1.2.0...v1.2.1) (2019-11-26) ## [1.2.0](https://github.com/medikoo/ext/compare/v1.1.2...v1.2.0) (2019-11-07) ### Features - ceil10, floor10 and round10 for Math ([6a2bc4b](https://github.com/medikoo/ext/commit/6a2bc4b)) ### [1.1.2](https://github.com/medikoo/ext/compare/v1.1.1...v1.1.2) (2019-10-29) ### Bug Fixes - Improve globalThis detection ([470862d](https://github.com/medikoo/ext/commit/470862d)) ### [1.1.1](https://github.com/medikoo/ext/compare/v1.1.0...v1.1.1) (2019-10-29) ### Bug Fixes - Provide naive fallback for sealed Object.prototype case ([a8d528b](https://github.com/medikoo/ext/commit/a8d528b)) - Workaournd Safari incompatibility case ([0b051e6](https://github.com/medikoo/ext/commit/0b051e6)) ## [1.1.0](https://github.com/medikoo/ext/compare/v1.0.3...v1.1.0) (2019-10-21) ### Features - Object.entries implementation ([cf51e45](https://github.com/medikoo/ext/commit/cf51e45)) ### [1.0.3](https://github.com/medikoo/ext/compare/v1.0.1...v1.0.3) (2019-07-03) Remove obsolete files from publication ### [1.0.2](https://github.com/medikoo/ext/compare/v1.0.1...v1.0.2) (2019-07-03) (no changes) ### [1.0.1](https://github.com/medikoo/ext/compare/v1.0.0...v1.0.1) (2019-07-03) Prettify ## 1.0.0 (2019-07-03) ### Features - `function/identity` (adapted from `es5-ext`) ([f0102af](https://github.com/medikoo/ext/commit/f0102af)) - `thenable/finally` (adapted from `es5-ext`) ([a8494ac](https://github.com/medikoo/ext/commit/a8494ac)) - `global-this/is-implemented` ([3a80904](https://github.com/medikoo/ext/commit/3a80904)) - `globalThis` (mostly adapted from `es5-ext`) ([6559bd3](https://github.com/medikoo/ext/commit/6559bd3)) package/docs/object/clear.md000644 0000000350 3560116604 013064 0ustar00000000 000000 # `Object.clear` _(ext/object/clear)_ Deletes all own, enumerable, non-symbol properties in the object ```javascript const clear = require("ext/object/clear"); const obj = { foo: "bar" }; clear(obj); Object.keys(obj); // [] ``` package/docs/object/entries.md000644 0000000600 3560116604 013445 0ustar00000000 000000 # `Object.entries` _(ext/object/entries)_ [Object.entries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries) implementation. Returns native `Object.entries` if it's implemented, otherwise library implementation is returned ```javascript const entries = require("ext/object/entries"); entries({ foo: "bar" }); // [["foo", "bar"]] ``` package/docs/thenable_/finally.md000644 0000000341 3560116604 014107 0ustar00000000 000000 # `thenable.finally` _(ext/thenable\_/finally)_ `finally` method for any _thenable_ input ```javascript const finally = require("ext/thenable_/finally"); finally.call(thenable, () => console.log("Thenable resolved")); ``` package/docs/math/floor-10.md000644 0000000252 3560116604 013021 0ustar00000000 000000 # `Math.floor10` _(ext/math/floor-10)_ Decimal floor ```javascript const floor10 = require("ext/math/floor-10"); floor10(55.59, -1); // 55.5 floor10(59, 1); // 50 ``` package/docs/global-this.md000644 0000000465 3560116604 012744 0ustar00000000 000000 # `globalThis` _(ext/global-this)_ Returns global object. Resolve native [globalThis](https://github.com/tc39/proposal-global) if implemented, otherwise fallback to internal resolution of a global object. ```javascript const globalThis = require("ext/global-this"); globalThis.Array === Array; // true ``` package/docs/function/identity.md000644 0000000252 3560116604 014207 0ustar00000000 000000 # `Function.identity` _(ext/function/identity)_ Returns input argument. ```javascript const identity = require("ext/function/identity"); identity("foo"); // "foo" ``` package/docs/string_/includes.md000644 0000000653 3560116604 014011 0ustar00000000 000000 # `string.includes(position = 0)` _(ext/string\_/includes)_ `includes` method for strings. Resolve native [includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes) if implemented, otherwise fallback to shim implementation. ```javascript const includes = require("ext/string_/includes"); includes.call("razdwa", "raz"); // true includes.call("razdwa", "trzy"); // false ``` package/docs/promise/limit.md000644 0000000631 3560116604 013326 0ustar00000000 000000 # `Promise.limit` _(ext/promise/limit)_ Helps to limit concurrency of asynchronous operations. ```javascript const limit = require("ext/promise/limit").bind(Promise); const limittedAsyncFunction = limit(2, asyncFunction); imittedAsyncFunction(); // Async operation started imittedAsyncFunction(); // Async operation started imittedAsyncFunction(); // On hold until one of previously started finalizes ``` package/docs/string/random.md000644 0000001447 3560116604 013326 0ustar00000000 000000 # `String.random(options = { ... })` _(ext/string/random)_ Returns generated random string, contained only of ascii cars `a-z` and `0-1`. By default returns string of length `10`. ```javascript const random = require("ext/string/random"); random(); // "upcfns0i4t" random({ length: 3 }); // "5tw" ``` ## Supported options: ### `isUnique: false` Ensures generated string is unique among ones already returned. _Note: When not applying this setting, accidental generation of same string is still highly unlikely. Provided option is just to provide a mean to eliminate possibility of an edge case of duplicate string being returned_ ### `length: 10` Desired length of result string ### `charset: null` Fixed list of possible characters ```javascript random({ charset: "abc" }); // "bacbccbbac" ``` package/README.md000644 0000001640 3560116604 010540 0ustar00000000 000000 # ext _(Previously known as `es5-ext`)_ ## JavaScript language extensions (with respect to evolving standard) Non-standard or soon to be standard language utilities in a future proof, non-invasive form. Doesn't enforce transpilation step. Where it's applicable utilities/extensions are safe to use in all ES3+ implementations. ### Installation ```bash npm install ext ``` ### Utilities - [`globalThis`](docs/global-this.md) - `Function` - [`identity`](docs/function/identity.md) - `Math` - [`ceil10`](docs/math/ceil-10.md) - [`floor10`](docs/math/floor-10.md) - [`round10`](docs/math/round-10.md) - `Object` - [`clear`](docs/object/clear.md) - [`entries`](docs/object/entries.md) - `Promise` - [`limit`](docs/promise/limit.md) - `String` - [`random`](docs/string/random.md) - `String.prototype` - [`includes`](docs/string_/includes.md) - `Thenable.prototype` - [`finally`](docs/thenable_/finally.md) package/docs/math/round-10.md000644 0000000261 3560116604 013027 0ustar00000000 000000 # `Math.round10` _(ext/math/round-10)_ Decimal round ```javascript const round10 = require("ext/math/round-10"); round10(55.549, -1); // 55.5 round10(1.005, -2); // 1.01 ``` package/.github/FUNDING.yml000644 0000000020 3560116604 012425 0ustar00000000 000000 github: medikoo