diff --git a/CHANGELOG.md b/CHANGELOG.md index 66d7d8f..ae80888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,65 @@ # Celestra version history +## Celestra v5.6.0 Razorback + +1. Documentation and pdf fixes. +```` +HTML - minmax(,,); - This is an alias of the minmax(,,);. +HTML - REMOVED polyfills in v3.1.0 - String.prototype.codePointAt();7 +```` + +2. Remove these aliases: `domToTop();`, `domToBottom();` + +3. Remove these functions: `randomString();`, `randomID();` + +4. Add these polyfills: +```` +Object.groupBy(); +Map.groupBy(); +```` + +5. Fix the function `group(,[,map=false]);` with the new, standard function calls. + +6. Deprecate this function: `group(,[,map=false]);` + +7. Add the 4th page in the __celestra-cheatsheet.odt__ and __celestra-cheatsheet.pdf__ with the removed polyfills. + +8. Move these polyfills in the **celestra-polyfills.dev.js** and **celestra-polyfills.min.js** +```` +Array.prototype.at(); +Array.prototype.findLast(); +Array.prototype.findLastIndex(); +Array.prototype.flat(); +Array.prototype.flatMap(); +Array.prototype.group(); +Array.prototype.groupToMap(); + +Number.MIN_SAFE_INTEGER; +Number.MAX_SAFE_INTEGER; + +Object.fromEntries(); +Object.is(); + +String.prototype.at(); +String.prototype.matchAll(); +String.prototype.padStart(); +String.prototype.padEnd(); +String.prototype.replaceAll(); +String.prototype.trimStart(); +String.prototype.trimLeft(); +String.prototype.trimEnd(); +String.prototype.trimRight(); + +Typedarray.prototype.at(); +TypedArray.prototype.findLast(); +TypedArray.prototype.findLastIndex(); +```` + +9. Close the milestone __5.6.0 Razorback__. + + + ## Celestra v5.5.5 1. Documentation and pdf fixes. diff --git a/README.md b/README.md index f5cf906..a0a7216 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ __A helper JavaScript library with useful functions and polyfills and zero depen Tested on desktop browsers (latest Firefox, latest Chrome, latest stable Chromium based Edge) and mobile devices (iOS Safari, Chrome, Firefox and Android Chrome, Samsung Internet, Firefox, Edge). This library isn't compatible with the Node.js. -Latest version: 5.5.5 +Latest version: 5.6.0 -Date: 2023-07-20T19:38:41.746Z +Date: 2023-10-22T19:41:13.967Z The functions are available in the `celestra` and/or `CEL` object. @@ -34,7 +34,7 @@ DEV and MIN editions: If the `CEL` global variable is used before the loading of ### Removed polyfills -Some polyfills have been removed in v3.1.0 and v3.8.0. With these files can be reusued the old polyfills if needed. +Some polyfills have been removed in v3.1.0 and v3.8.0 and v5.6.0. With these files can be reusued the old polyfills if needed. edition|filename -------|-------- @@ -120,6 +120,7 @@ window.CEL = defaultExport; - The Math functions are available in the main code files (dev, min, esm) instead of the Math plugins. + ----- ## Functions @@ -141,12 +142,12 @@ Name | Description `BASE58;`|`"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"`
Can be used with the ID generator functions.| `BASE62;`|`"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"`
Can be used with the ID generator functions. `WORDSAFEALPHABET;`|`"23456789CFGHJMPQRVWXcfghjmpqvwx"`
Can be used with the ID generator functions. -`randomID([hyphens=true][,usedate=false]);` | __DEPRECATED in v5.5.4__
__Can be replaced with the __`crypto.randomUUID();`,__ which is polyfilled in this library.__
Generate a GUID/UUID v4 random ID. The hyphens and useDate parameters are optional and can be a boolean. The return value is a string.
Example:
`randomID(false);`
->
`"0e0f739a306b4faad62e3e8080826c9c"`
`randomID(true, true);`
->
`"17c3d79b-d413-4443-b4cd-5426c7299726"`
`randomID();`
->
`"bc897cdf-da26-42de-83e2-d1fd458e079f"` +`randomID([hyphens=true][,usedate=false]);` | __DEPRECATED in v5.5.4__
__REMOVED in v5.6.0__
__Can be replaced with the __`crypto.randomUUID();`,__ which is polyfilled in this library.__
Generate a GUID/UUID v4 random ID. The hyphens and useDate parameters are optional and can be a boolean. The return value is a string. `delay().then();` | A promise based delay function. The ms (milliseconds) parameter is mandatory and have to be an integer.
__Sample:__
`CEL.sleep(5000).then(() => alert("5 seconds")).catch(console.log.bind(console)).finally(() => alert("done"));` `sleep().then();` | This is an alias of the `delay().then();`. `inherit(,);` | Prototype inheritance. `randomBoolean();` | Get a random boolean value. The return value is `true` or `false`. -`randomString([length[,specialCharactersEnabled=false]]);` | __DEPRECATED in v5.5.2__
__Can be replaced with the __`CEL.nanoid();`__.__
Generate a random string. The length parameter is optional and can be a number and the default value is 100. The specialCharactersEnabled parameter is optional and can be a boolean and the default value is false. Return the generated string.
Example ID: `"QsZA2VVTgFIF3D-qFk5oc"` +`randomString([length[,specialCharactersEnabled=false]]);` | __DEPRECATED in v5.5.2__
__REMOVED in v5.6.0__
__Can be replaced with the __`CEL.nanoid();`__.__
Generate a random string. The length parameter is optional and can be a number and the default value is 100. The specialCharactersEnabled parameter is optional and can be a boolean and the default value is false. Return the generated string.
Example ID: `"QsZA2VVTgFIF3D-qFk5oc"` `b64Encode();` | Unicode compatible string to base64 converter. Return the encoded string. `b64Decode();` | Unicode compatible base64 to string converter. Return the original string. `javaHash([,hexa=false]);` | Java `String.hashCode()` implementation in Javascript - this is a non-cryptographic hash function. The data parameter is mandatory and can be any type. The hexa parameter is optional and can be a boolean and sets the hexadecimal conversion of the return value and the default value is false. Return the generated integer hash. @@ -237,8 +238,8 @@ Name | Description `setFullscreenOff();` | Set off the fullscreen. `domGetCSSVar();` | This function returns a value of a CSS variable or an empty string, if the variable is unset. The name parameter is mandatory and has to be a string. If the "--" characters are missing at the begin of the variable name, then the function will add these. `domSetCSSVar(,);` | This function set a value of a CSS variable. Both of the parameters are mandatory and have to be a string. If the "--" characters are missing at the begin of the variable name, then the function will add these. -`domScrollToTop();` | __Old name before v5.4.0:__ `domToTop`.
This function is scrolling to the top of the page. -`domScrollToBottom();` | __Old name before v5.4.0:__ `domToBottom`.
This function is scrolling to the bottom of the page. +`domScrollToTop();` | __Old name before v5.5.4:__ `domToTop`.
This function is scrolling to the top of the page. +`domScrollToBottom();` | __Old name before v5.5.4:__ `domToBottom`.
This function is scrolling to the bottom of the page. `domScrollToElement([,top=true]);` | This function is scrolling to top or the bottom of element. The element parameter is mandatory and the top parameter is optional and can be boolean. @@ -361,7 +362,7 @@ Name | Description `shuffle();` | Returns an array with the values of the given collection, but in shuffled order.
__Example:__
`CEL.shuffle(["first",4,5,6,7,8,9,"last"]);`
->
`[4,8,5,6,"last",9,7,"first"]` `withOut(,);` | Returns an array with the values of the first collection, but without the values of the filterCollection. All of the parameters are mandatory and can be any type of JavaScript collections.
__Example:__
`CEL.withOut(["a","b","c","d"], ["b","d"]);`
->
`["a","c"]` `partition(,);` | Returns an array, with filtered and negative filtered groups of the elements of the original collection. All of the parameters are mandatory.
__Example:__
`CEL.partition([-5, 2, -9, 7, 34], (e) => (e > 0) );`
->
`[[2, 7, 34], [-5, -9]]]` -`group(,[,map=false]);` | __Old name before v5.4.4:__ `groupBy`.
Returns an Object or Map with array properties. The keys are the returned values of the given function. The collection parameter is mandatory. The callback parameter is mandatory and has to be a function. The map parameter is optional and has to be a boolean and if it is true, then the return value is a Map instead of Object.
__Example:__
`CEL.group([1,2,3,4,5], (i) => (i % 2 === 0 ? "even" : "odd");`
->
`{ "even": [ 2, 4 ], "odd": [ 1, 3, 5 ] }` +`group(,[,map=false]);` | __Deprecated in v5.6.0. Will be removed in 5.7.0.__
__Can be replaced with the `Object.groupBy();` and `Map.groupBy();`.__
__Old name before v5.4.4:__ `groupBy`.
Returns an Object or Map with array properties. The keys are the returned values of the given function. The collection parameter is mandatory. The callback parameter is mandatory and has to be a function. The map parameter is optional and has to be a boolean and if it is true, then the return value is a Map instead of Object.
__Example:__
`CEL.group([1,2,3,4,5], (i) => (i % 2 === 0 ? "even" : "odd");`
->
`{ "even": [ 2, 4 ], "odd": [ 1, 3, 5 ] }` `arrayUnion([,collectionN]);` | Returns the array of unique values including all values from the given collections. The first parameter is mandatory and all parameters can be any type of JavaScript collections. The return value is an Array. `arrayIntersection(,);` | Returns the array of unique values that are in both of the given collections. All of the parameters are mandatory and can be any type of JavaScript collections. The return value is an Array. `arrayDifference(,);` | Returns the array of unique values that are in the collection1, excluding the values that are also in the collection2. All of the parameters are mandatory and can be any type of JavaScript collections. The return value is an Array. @@ -498,6 +499,8 @@ Name | Description Name | Description ---- | ----------- +`Object.groupBy();` | The Object.groupBy() static method groups the elements of a given iterable according to the string values returned by a provided callback function. The returned object has separate properties for each group, containing arrays with the elements in the group. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy)! +`Map.groupBy();` | The Map.groupBy() static method groups the elements of a given iterable using the values returned by a provided callback function. The final returned Map uses the unique values from the test function as keys, which can be used to get the array of elements in each group. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/groupBy)! `Array.fromAsync();` | The Array.fromAsync() static method creates a new, shallow-copied Array instance from an async iterable, iterable, or array-like object. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fromAsync)! `Array.prototype.toReversed();` | The toReversed() method of an Array instance is the copying counterpart of the reverse() method. It returns a new array with the elements in reversed order. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed)! `Array.prototype.toSorted();` | The toSorted() method of an Array instance is the copying version of the sort() method. It returns a new array with the elements sorted in ascending order. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSorted)! @@ -506,34 +509,13 @@ Name | Description `TypedArray.prototype.toReversed();` | The toReversed() method is the copying counterpart of the reverse() method. It returns a new array with the elements in reversed order. This method has the same algorithm as Array.prototype.reverse(). For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/toReversed)! `TypedArray.prototype.toSorted();` | The toSorted() method is the copying version of the sort() method. It returns a new array with the elements sorted in ascending order. This method has the same algorithm as Array.prototype.toSorted(), except that it sorts the values numerically instead of as strings by default. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/toSorted)! `TypedArray.prototype.with();` | The with() method is the copying version of using the bracket notation to change the value of a given index. It returns a new array with the element at the given index replaced with the given value. This method has the same algorithm as Array.prototype.with(). For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/with)! -`Object.is();` | The Object.is() method determines whether two values are the same value. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)! -`Number.MIN_SAFE_INTEGER;` | The Number.MIN_SAFE_INTEGER constant represents the minimum safe integer in JavaScript (-(2^53 - 1), -9007199254740991). For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_SAFE_INTEGER)! -`Number.MAX_SAFE_INTEGER;` | The Number.MAX_SAFE_INTEGER constant represents the maximum safe integer in JavaScript (2^53 - 1, 9007199254740991). For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)! `crypto.randomUUID();` | The randomUUID() method of the Crypto interface is used to generate a v4 UUID using a cryptographically secure random number generator. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID)! `Array.prototype.group([,thisArg]);` | The group() method grouping of items in an array based on the return value (key) of the given function. The return value is a null-prototype object. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/group)! -`Array.prototype.groupToMap([,thisArg]);` | The groupToMap() method grouping of items in an array based on the return value (key) of the given function. The return value is a Map object. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/groupToMap)! -`Array.prototype.findLast();` | The findLast() method returns the value of the last element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast)! -`Array.prototype.findLastIndex();` | The findLastIndex() method returns the index of the last element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex)! -`TypedArray.prototype.findLast();` | The findLast() method returns the value of the last element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/findLast)! -`TypedArray.prototype.findLastIndex();` | The findLastIndex() method returns the index of the last element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/findLastIndex)! -`Array.prototype.at();` | The at() method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at)! -`TypedArray.prototype.at();` | The at() method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/at)! -`String.prototype.at();` | The at() method takes an integer value and returns a new String consisting of the single UTF-16 code unit located at the specified offset. This method allows for positive and negative integers. Negative integers count back from the last string character. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/at)! `Object.hasOwn();` | The Object.hasOwn() static method returns true if the specified object has the indicated property as its own property. If the property is inherited, or does not exist, the method returns false. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)! -`String.prototype.trimStart();` | The trimStart() method removes whitespace from the beginning of a string. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimStart)! -`String.prototype.trimLeft();` | Alias of the `String.prototype.trimStart();` method. -`String.prototype.trimEnd();` | The trimEnd() method removes whitespace from the end of a string. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trimEnd)! -`String.prototype.trimRight();` | Alias of the `String.prototype.trimEnd();` method. -`String.prototype.padStart();` | The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start (left) of the current string. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)! -`String.prototype.padEnd();` | The padEnd() method pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end (right) of the current string. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd)! -`Object.fromEntries();` | The Object.fromEntries() method transforms a list of key-value pairs into an object. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries)! -`Array.prototype.flat();` | The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat)! -`Array.prototype.flatMap();` | A new array with each element being the result of the callback function and flattened to a depth of 1. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap)! `globalThis;` | The "global" property of the global object, a writable, configurable, non-enumerable alias of `window`/`self`. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis)! -`String.prototype.matchAll();` | The matchAll() method returns an iterator of all results matching a string against a regular expression, including capturing groups. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll)! -`String.prototype.replaceAll();` | The replaceAll() method returns a new string with all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp. For more information please read the [MDN Article](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll)! REMOVED polyfills in v3.1.0 | `Array.from();`
`Array.of();`
`Array.prototype.fill();`
`Array.prototype.find();`
`Array.prototype.findIndex();`
`Object.create();`
`String.prototype.startsWith();`
`String.prototype.endsWith();`
`Array.prototype.copyWithin();`
`String.fromCodePoint();`
`String.prototype.codePointAt();`
`Number.EPSILON;`
`Number.isNaN();`
`isNaN();`
`Number.isInteger();`
`Number.isFinite();`
`Number.isSafeInteger();`
`Number.parseInt();`
`Number.parseFloat();`
`Math.acosh();`
`Math.asinh();`
`Math.atanh();`
`Math.cbrt();`
`Math.clz32();`
`Math.cosh();`
`Math.expm1();`
`Math.fround();`
`Math.hypot();`
`Math.imul();`
`Math.log1p();`
`Math.log10();`
`Math.log2();`
`Math.sign();`
`Math.sinh();`
`Math.tanh();`
`Math.trunc();` REMOVED polyfills in v3.8.0 | `Array.prototype.values();`
`Array.prototype.includes();`
`String.prototype.includes();`
`String.prototype.repeat();`
`String.prototype[Symbol.iterator]();`
`Object.assign();`
`Object.entries();`
`Object.values();`
`Object.getOwnPropertyDescriptors();`
`RegExp.prototype.flags;`
`NodeList.prototype.forEach();`
`ChildNode.after();`
`ChildNode.before();`
`ChildNode.remove();`
`ChildNode.replaceWith();`
`ParentNode.append();`
`ParentNode.prepend();`
`Element.prototype.matches();`
`Element.prototype.closest();`
`Element.prototype.toggleAttribute();`
`Element.prototype.getAttributeNames();`
`window.screenLeft;`
`window.screenTop;` +REMOVED polyfills in v5.6.0 | `Array.prototype.at();`
`Array.prototype.findLast();`
`Array.prototype.findLastIndex();`
`Array.prototype.flat();`
`Array.prototype.flatMap();`
`Array.prototype.group();`
`Array.prototype.groupToMap();`
`Number.MIN_SAFE_INTEGER;`
`Number.MAX_SAFE_INTEGER;`
`Object.fromEntries();`
`Object.is();`
`String.prototype.at();`
`String.prototype.matchAll();`
`String.prototype.padStart();`
`String.prototype.padEnd();`
`String.prototype.replaceAll();`
`String.prototype.trimStart();`
`String.prototype.trimLeft();`
`String.prototype.trimEnd();`
`String.prototype.trimRight();`
`Typedarray.prototype.at();`
`TypedArray.prototype.findLast();`
`TypedArray.prototype.findLastIndex();` ### Non-standard polyfills diff --git a/btc.app.html b/btc.app.html index 4f4e804..9ec4e8e 100644 --- a/btc.app.html +++ b/btc.app.html @@ -1517,36 +1517,15 @@ } diff --git a/celestra-cheatsheet.odt b/celestra-cheatsheet.odt index b6acd1d..3f648b2 100644 Binary files a/celestra-cheatsheet.odt and b/celestra-cheatsheet.odt differ diff --git a/celestra-cheatsheet.pdf b/celestra-cheatsheet.pdf index 5a8e644..5d78c0a 100644 Binary files a/celestra-cheatsheet.pdf and b/celestra-cheatsheet.pdf differ diff --git a/celestra-demo-plugin.dev.js b/celestra-demo-plugin.dev.js index 38283b2..33c7e6d 100644 --- a/celestra-demo-plugin.dev.js +++ b/celestra-demo-plugin.dev.js @@ -1,9 +1,9 @@ /** * @name Celestra demo plugin - * @version 5.5.5 dev + * @version 5.6.0 dev * @see https://github.com/Serrin/Celestra * @license MIT https://opensource.org/licenses/MIT - * Required Celestra version: 5.5.5 + * Required Celestra version: 5.6.0 */ (function(celestra){ diff --git a/celestra-demo-plugin.html b/celestra-demo-plugin.html index fe5a1d5..6404c47 100644 --- a/celestra-demo-plugin.html +++ b/celestra-demo-plugin.html @@ -33,7 +33,7 @@

Download and informations

Tested on desktop browsers (latest Chrome, latest Firefox, latest Edge) and mobile devices (iOS Safari, Chrome, Firefox and Android Chrome, Samsung Internet, Firefox, Edge).

-

Latest version: 5.5.5

+

Latest version: 5.6.0

Developer edition: celestra-demo-plugin.dev.js

Minified edition: celestra-demo-plugin.min.js

diff --git a/celestra-demo-plugin.min.js b/celestra-demo-plugin.min.js index a3ea7b7..5a83f54 100644 --- a/celestra-demo-plugin.min.js +++ b/celestra-demo-plugin.min.js @@ -1,4 +1,4 @@ -/** Celestra demo plugin * @version 5.5.5 min * @see https://github.com/Serrin/Celestra/ * @license MIT */ +/** Celestra demo plugin * @version 5.6.0 min * @see https://github.com/Serrin/Celestra/ * @license MIT */ (function(celestra){ "use strict"; function collect(it,mapFn){var r=[],i=0;for(let item of it){if(typeof mapFn!=="function"){r.push(item);}else{r.push(mapFn(item,i++));}}return r;} diff --git a/celestra-polyfills.dev.js b/celestra-polyfills.dev.js index 18f5f0f..5840d31 100644 --- a/celestra-polyfills.dev.js +++ b/celestra-polyfills.dev.js @@ -1,7 +1,7 @@ /** * @name Celestra Removed Polyfills - * @version 3.8.0 dev + * @version 5.6.0 dev * @see https://github.com/Serrin/Celestra/ * @license MIT https://opensource.org/licenses/MIT */ @@ -75,6 +75,34 @@ window.screenLeft; window.screenTop; */ +/* +Removed in v5.6.0 + +Array.prototype.at(); +Array.prototype.findLast(); +Array.prototype.findLastIndex(); +Array.prototype.flat(); +Array.prototype.flatMap(); +Array.prototype.group(); +Array.prototype.groupToMap(); +Number.MIN_SAFE_INTEGER; +Number.MAX_SAFE_INTEGER; +Object.fromEntries(); +Object.is(); +String.prototype.at(); +String.prototype.matchAll(); +String.prototype.padStart(); +String.prototype.padEnd(); +String.prototype.replaceAll(); +String.prototype.trimStart(); +String.prototype.trimLeft(); +String.prototype.trimEnd(); +String.prototype.trimRight(); +Typedarray.prototype.at(); +TypedArray.prototype.findLast(); +TypedArray.prototype.findLastIndex(); +*/ + (function(window, document){ "use strict"; @@ -595,4 +623,312 @@ if (!Element.prototype.getAttributeNames) { if (!("screenLeft" in window)) { window.screenLeft = window.screenX; } if (!("screenTop" in window)) { window.screenTop = window.screenY; } +/* Removed in v5.6.0 */ + +/* Array.prototype.at(); */ +if (!("at" in Array.prototype)) { + Object.defineProperty(Array.prototype, "at", { + writable: true, enumerable: false, configurable: true, + value: function at(n) { + n = Math.trunc(n) || 0; + if (n < 0) { n += this.length; } + if (n < 0 || n >= this.length) { return undefined; } + return this[String(n)]; + } + }); +} + +/* Array.prototype.findLast(); */ +if (!("findLast" in Array.prototype)) { + Object.defineProperty(Array.prototype, "findLast", { + writable: true, enumerable: false, configurable: true, + value: function findLast (fn) { + if (typeof fn !== "function") { + throw new TypeError(String(fn) + " is not a function"); + } + var i = this.length; + while (i--) { if (fn(this[i],i,this)) { return this[i]; } } + return undefined; + } + }); +} + +/* Array.prototype.findLastIndex(); */ +if (!("findLastIndex" in Array.prototype)) { + Object.defineProperty(Array.prototype, "findLastIndex", { + writable: true, enumerable: false, configurable: true, + value: function findLastIndex (fn) { + if (typeof fn !== "function") { + throw new TypeError(String(fn) + " is not a function"); + } + var i = this.length; + while (i--) { if (fn(this[i],i,this)) { return i; } } + return -1; + } + }); +} + +/* Array.prototype.flat(); */ +if (!("flat" in Array.prototype)) { + Object.defineProperty(Array.prototype, "flat", { + writable: true, enumerable: false, configurable: true, + value: function (depth) { + if (depth === undefined) { + depth = 1; + } else { + depth = Math.floor(Number(depth)); + if (isNaN(depth) || depth < 1) { return this; } + } + function deepFlat (a, cd) { + a.forEach(function (e) { + if (Array.isArray(e)) { + if (cd < depth) { deepFlat(e, cd+1); } else { res.push(e); } + } else { + res.push(e); + } + }); + } + var res = []; + deepFlat(this, 0); + return res; + } + }); +} + +/* Array.prototype.flatMap(); */ +if (!("flatMap" in Array.prototype)) { + Object.defineProperty(Array.prototype, "flatMap", { + writable: true, enumerable: false, configurable: true, + value: function (fn) { + var res = []; + this.map(fn).forEach(function (e) { + if (Array.isArray(e)) { res = res.concat(e); } else { res.push(e); } + }); + return res; + } + }); +} + +/* Array.prototype.group(); */ +if (!("group" in Array.prototype)) { + Object.defineProperty(Array.prototype, "group", { + "configurable": true, "writable": true, "enumerable": false, + "value": function (fn, thisArg) { + "use strict"; + function toArray (O) { return (Array.isArray(O) ? O : Array.from(O)); } + if (!(typeof fn === "function")) { throw new TypeError(); } + var a = toArray(this); + var key, r = Object.create(null), l = a.length; + for (var i = 0; i < l; i++) { + key = fn.call(thisArg, a[i], i, a); + if (!(Object.prototype.hasOwnProperty.call(r, key))) { r[key] = []; } + r[key].push(a[i]); + } + return r; + } + }); +} + +/* Array.prototype.groupToMap(); */ +if (!("groupToMap" in Array.prototype)) { + Object.defineProperty(Array.prototype, "groupToMap", { + "configurable": true, "writable": true, "enumerable": false, + "value": function (fn, thisArg) { + "use strict"; + function toArray (O) { return (Array.isArray(O) ? O : Array.from(O)); } + if (!(typeof fn === "function")) { throw new TypeError(); } + var a = toArray(this); + var key, r = new Map(), l = a.length; + for (var i = 0; i < l; i++) { + key = fn.call(thisArg, a[i], i, a); + if (!(r.has(key))) { r.set(key, []); } + r.get(key).push(a[i]); + } + return r; + } + }); +} + +/* Number.MIN_SAFE_INTEGER; */ +if(!("MIN_SAFE_INTEGER" in Number)){Number.MIN_SAFE_INTEGER=-9007199254740991;} + +/* Number.MAX_SAFE_INTEGER; */ +if(!("MAX_SAFE_INTEGER" in Number)){Number.MAX_SAFE_INTEGER=9007199254740991;} + +/* Object.fromEntries(); */ +if (!Object.fromEntries) { + Object.fromEntries = function (entries) { + var r = {}; + for (let e of entries) { r[e[0]] = e[1]; } + return r; + }; +} + +/* Object.is(); */ +if (!Object.is) { + Object.is = function (x, y) { + if (x===y) { return x!==0 || 1/x === 1/y; } else { return x!==x && y!==y; } + }; +} + +/* String.prototype.at(); */ +if (!("at" in String.prototype)) { + Object.defineProperty(String.prototype, "at", { + writable: true, enumerable: false, configurable: true, + value: function at(n) { + n = Math.trunc(n) || 0; + if (n < 0) { n += this.length; } + if (n < 0 || n >= this.length) { return undefined; } + return String(this)[String(n)]; + } + }); +} + +/* String.prototype.matchAll(); */ +if (!("matchAll" in String.prototype)) { + Object.defineProperty(String.prototype, "matchAll", { + writable: true, enumerable: false, configurable: true, + value: function* (regex) { + function ef (fls, fl) { return (fls.includes(fl) ? fls : fls + fl); } + const lc = new RegExp(regex, ef(regex.flags, "g")); + let match; + while (match = lc.exec(this)) { yield match; } + } + }); +} + +/* String.prototype.padStart(); */ +if (!("padStart" in String.prototype)) { + Object.defineProperty(String.prototype, "padStart", { + writable: true, enumerable: false, configurable: true, + value: function (len, str) { + len = Math.floor(Number(len)); + if (len <= this.length || len === NaN ) { + return String(this); + } else { + str = String(typeof str !== "undefined" ? str: " "); + if (str.length === 0) { return String(this); } + var res = "", n = Math.floor( (len - this.length) / str.length) + 1; + for (var i = 0; i < n; i++) { res += str; } + return res.slice(0, len - this.length) + String(this); + } + } + }); +} + +/* String.prototype.padEnd(); */ +if (!("padEnd" in String.prototype)) { + Object.defineProperty(String.prototype, "padEnd", { + writable: true, enumerable: false, configurable: true, + value: function (len, str) { + len = Math.floor(Number(len)); + if (len <= this.length || len === NaN ) { + return String(this); + } else { + str = String(typeof str !== "undefined" ? str: " "); + if (str.length === 0) { return String(this); } + var res = "", n = Math.floor( (len - this.length) / str.length) + 1; + for (var i = 0; i < n; i++) { res += str; } + return String(this) + res.slice(0, len - this.length); + } + } + }); +} + +/* String.prototype.replaceAll(); */ +if (!("replaceAll" in String.prototype)) { + Object.defineProperty(String.prototype, "replaceAll", { + "configurable": true, "writable": true, "enumerable": false, + "value": function (searchValue, replaceValue) { + "use strict"; + if (this == null) { + throw new TypeError("String.prototype.replaceAll requires |this| not to be null nor undefined"); + } + if (Object.prototype.toString.call(searchValue) + .replace(/^\[object (.+)\]$/, "$1").toLowerCase() === "regexp") { + if (!searchValue.global) { + throw new TypeError("String.prototype.replaceAll must be called with a global RegExp"); + } + return String(this).replace(searchValue, replaceValue); + } + return String(this).split(String(searchValue)).join(replaceValue); + } + }); +} + +/* String.prototype.trimStart(); */ +if (!("trimStart" in String.prototype)) { + Object.defineProperty(String.prototype, "trimStart", { + writable: true, enumerable: false, configurable: true, + value: function () { return String(this).replace(/^\s+/, ""); } + }); +} + +/* String.prototype.trimLeft(); */ +if (!("trimLeft" in String.prototype)) { + Object.defineProperty(String.prototype, "trimLeft", { + writable: true, enumerable: false, configurable: true, + value: function () { return String(this).replace(/^\s+/, ""); } + }); +} + +/* String.prototype.trimEnd(); */ +if (!("trimEnd" in String.prototype)) { + Object.defineProperty(String.prototype, "trimEnd", { + writable: true, enumerable: false, configurable: true, + value: function () { return String(this).replace(/\s+$/, ""); } + }); +} + +/* String.prototype.trimRight(); */ +if (!("trimRight" in String.prototype)) { + Object.defineProperty(String.prototype, "trimRight", { + writable: true, enumerable: false, configurable: true, + value: function () { return String(this).replace(/\s+$/, ""); } + }); +} + +/* TypedArray.prototype.at(); */ +if (!("at" in Uint8Array.prototype)) { + Object.defineProperty(Uint8Array.prototype, "at", { + writable: true, enumerable: false, configurable: true, + value: function at(n) { + n = Math.trunc(n) || 0; + if (n < 0) { n += this.length; } + if (n < 0 || n >= this.length) { return undefined; } + return this[String(n)]; + } + }); +} + +/* TypedArray.prototype.findLast(); */ +if (!("findLast" in Uint8Array.prototype)) { + Object.defineProperty(Uint8Array.prototype, "findLast", { + writable: true, enumerable: false, configurable: true, + value: function findLast (fn) { + if (typeof fn !== "function") { + throw new TypeError(String(fn) + " is not a function"); + } + var i = this.length; + while (i--) { if (fn(this[i],i,this)) { return this[i]; } } + return undefined; + } + }); +} + +/* TypedArray.prototype.findLastIndex(); */ +if (!("findLastIndex" in Uint8Array.prototype)) { + Object.defineProperty(Uint8Array.prototype, "findLastIndex", { + writable: true, enumerable: false, configurable: true, + value: function findLastIndex (fn) { + if (typeof fn !== "function") { + throw new TypeError(String(fn) + " is not a function"); + } + var i = this.length; + while (i--) { if (fn(this[i],i,this)) { return i; } } + return -1; + } + }); +} + }(window, document)); diff --git a/celestra-polyfills.min.js b/celestra-polyfills.min.js index a56695e..c78bcb3 100644 --- a/celestra-polyfills.min.js +++ b/celestra-polyfills.min.js @@ -1,4 +1,4 @@ -/** Celestra Removed Polyfills * @version 3.8.0 min * @see https://github.com/Serrin/Celestra/ * @license MIT */ +/** Celestra Removed Polyfills * @version 5.6.0 min * @see https://github.com/Serrin/Celestra/ * @license MIT */ (function(window,document){ "use strict"; @@ -60,4 +60,30 @@ if(!Element.prototype.getAttributeNames){Element.prototype.getAttributeNames=fun if(!("screenLeft" in window)){window.screenLeft=window.screenX;} if(!("screenTop" in window)){window.screenTop=window.screenY;} +/* Removed in v5.6.0 */ + +if(!("at" in Array.prototype)){Object.defineProperty(Array.prototype,"at",{writable:true,enumerable:false,configurable:true,value:function at(n){n=Math.trunc(n)||0;if(n<0){n+=this.length;}if(n<0||n>=this.length){return undefined;}return this[String(n)];}});} +if(!("findLast" in Array.prototype)){Object.defineProperty(Array.prototype,"findLast",{writable:true,enumerable:false,configurable:true,value:function findLast(fn){if(typeof fn!=="function"){throw new TypeError(String(fn)+" is not a function");}var i=this.length;while(i--){if(fn(this[i],i,this)){return this[i];}}return undefined;}});} +if(!("findLastIndex" in Array.prototype)){Object.defineProperty(Array.prototype,"findLastIndex",{writable:true,enumerable:false,configurable:true,value:function findLastIndex(fn){if(typeof fn!=="function"){throw new TypeError(String(fn)+" is not a function");}var i=this.length;while(i--){if(fn(this[i],i,this)){return i;}}return -1;}});} +if(!("flat" in Array.prototype)){Object.defineProperty(Array.prototype,"flat",{writable:true,enumerable:false,configurable:true,value:function(depth){if(depth===undefined){depth=1;}else{depth=Math.floor(Number(depth));if(isNaN(depth)||depth<1){return this;}}function deepFlat(a,cd){a.forEach(function(e){if(Array.isArray(e)){if(cd=this.length){return undefined;}return String(this)[String(n)];}});} +if(!("matchAll" in String.prototype)){Object.defineProperty(String.prototype,"matchAll",{writable:true,enumerable:false,configurable:true,value:function*(regex){function ef(fls,fl){return (fls.includes(fl)?fls:fls+fl);}const lc=new RegExp(regex,ef(regex.flags,"g"));let match;while(match=lc.exec(this)){yield match;}}});} +if(!("padStart" in String.prototype)){Object.defineProperty(String.prototype,"padStart",{writable:true,enumerable:false,configurable:true,value:function(len,str){len=Math.floor(Number(len));if(len<=this.length||len===NaN){return String(this);}else{str=String(typeof str!=="undefined"?str:" ");if(str.length===0){return String(this);}var res="",n=Math.floor((len-this.length)/str.length)+1;for(var i=0;i=this.length){return undefined;}return this[String(n)];}});} +if(!("findLast" in Uint8Array.prototype)){Object.defineProperty(Uint8Array.prototype,"findLast",{writable:true,enumerable:false,configurable:true,value:function findLast(fn){if(typeof fn!=="function"){throw new TypeError(String(fn)+" is not a function");}var i=this.length;while(i--){if(fn(this[i],i,this)){return this[i];}}return undefined;}});} +if(!("findLastIndex" in Uint8Array.prototype)){Object.defineProperty(Uint8Array.prototype,"findLastIndex",{writable:true,enumerable:false,configurable:true,value:function findLastIndex(fn){if(typeof fn!=="function"){throw new TypeError(String(fn)+" is not a function");}var i=this.length;while(i--){if(fn(this[i],i,this)){return i;}}return -1;}});} + }(window,document)); \ No newline at end of file diff --git a/celestra.dev.js b/celestra.dev.js index 48c116d..20ed2a7 100644 --- a/celestra.dev.js +++ b/celestra.dev.js @@ -1,6 +1,6 @@ /** * @name Celestra - * @version 5.5.5 dev + * @version 5.6.0 dev * @see https://github.com/Serrin/Celestra/ * @license MIT https://opensource.org/licenses/MIT */ @@ -9,6 +9,42 @@ /** polyfills **/ +/* Object.groupBy(); */ +if (!("groupBy" in Object)) { + Object.defineProperty(Object, "groupBy", { + "configurable": true, "writable": true, "enumerable": true, + "value": function (items, callbackFn) { + "use strict"; + if (!(typeof callbackFn === "function")) { throw new TypeError(); } + let r = Object.create(null), i = 0; + for (let item of items) { + let key = callbackFn(item, i++); + if (!(Object.prototype.hasOwnProperty.call(r, key))) { r[key] = []; } + r[key].push(item); + } + return r; + } + }); +} + +/* Map.groupBy(); */ +if (!("groupBy" in Map)) { + Object.defineProperty(Map, "groupBy", { + "configurable": true, "writable": true, "enumerable": true, + "value": function (items, callbackFn) { + "use strict"; + if (!(typeof callbackFn === "function")) { throw new TypeError(); } + let r = new Map(), i = 0; + for (let item of items) { + let key = callbackFn(item, i++); + if (!(r.has(key))) { r.set(key, []); } + r.get(key).push(item); + } + return r; + } + }); +} + /* Array.fromAsync(); */ if (!Array.fromAsync) { Array.fromAsync = async function fromAsync (arrayLike, mapfn, thisArg) { @@ -49,19 +85,6 @@ if (!Array.fromAsync) { }; } -/* Object.is(); */ -if (!Object.is) { - Object.is = function (x, y) { - if (x===y) { return x!==0 || 1/x === 1/y; } else { return x!==x && y!==y; } - }; -} - -/* Number.MIN_SAFE_INTEGER; */ -if(!("MIN_SAFE_INTEGER" in Number)){Number.MIN_SAFE_INTEGER=-9007199254740991;} - -/* Number.MAX_SAFE_INTEGER; */ -if(!("MAX_SAFE_INTEGER" in Number)){Number.MAX_SAFE_INTEGER=9007199254740991;} - /* crypto.randomUUID(); */ if (("crypto" in window) && !("randomUUID" in window.crypto)) { window.crypto.randomUUID = function randomUUID () { @@ -71,85 +94,6 @@ if (("crypto" in window) && !("randomUUID" in window.crypto)) { }; } -/* Array.prototype.group([,thisArg]); */ -if (!("group" in Array.prototype)) { - Object.defineProperty(Array.prototype, "group", { - "configurable": true, "writable": true, "enumerable": false, - "value": function (fn, thisArg) { - "use strict"; - function toArray (O) { return (Array.isArray(O) ? O : Array.from(O)); } - if (!(typeof fn === "function")) { throw new TypeError(); } - var a = toArray(this); - var key, r = Object.create(null), l = a.length; - for (var i = 0; i < l; i++) { - key = fn.call(thisArg, a[i], i, a); - if (!(Object.prototype.hasOwnProperty.call(r, key))) { r[key] = []; } - r[key].push(a[i]); - } - return r; - } - }); -} - -/* Array.prototype.groupToMap([,thisArg]); */ -if (!("groupToMap" in Array.prototype)) { - Object.defineProperty(Array.prototype, "groupToMap", { - "configurable": true, "writable": true, "enumerable": false, - "value": function (fn, thisArg) { - "use strict"; - function toArray (O) { return (Array.isArray(O) ? O : Array.from(O)); } - if (!(typeof fn === "function")) { throw new TypeError(); } - var a = toArray(this); - var key, r = new Map(), l = a.length; - for (var i = 0; i < l; i++) { - key = fn.call(thisArg, a[i], i, a); - if (!(r.has(key))) { r.set(key, []); } - r.get(key).push(a[i]); - } - return r; - } - }); -} - -/* Array.prototype.at(); */ -if (!("at" in Array.prototype)) { - Object.defineProperty(Array.prototype, "at", { - writable: true, enumerable: false, configurable: true, - value: function at(n) { - n = Math.trunc(n) || 0; - if (n < 0) { n += this.length; } - if (n < 0 || n >= this.length) { return undefined; } - return this[String(n)]; - } - }); -} - -/* TypedArray.prototype.at(); */ -if (!("at" in Uint8Array.prototype)) { - Object.defineProperty(Uint8Array.prototype, "at", { - writable: true, enumerable: false, configurable: true, - value: function at(n) { - n = Math.trunc(n) || 0; - if (n < 0) { n += this.length; } - if (n < 0 || n >= this.length) { return undefined; } - return this[String(n)]; - } - }); -} - -/* String.prototype.at(); */ -if (!("at" in String.prototype)) { - Object.defineProperty(String.prototype, "at", { - writable: true, enumerable: false, configurable: true, - value: function at(n) { - n = Math.trunc(n) || 0; - if (n < 0) { n += this.length; } - if (n < 0 || n >= this.length) { return undefined; } - return String(this)[String(n)]; - } - }); -} - /* Object.hasOwn(); */ if (!Object.hasOwn) { Object.defineProperty(Object, "hasOwn", { @@ -163,147 +107,6 @@ if (!Object.hasOwn) { }); } -/* String.prototype.trimStart(); */ -if (!("trimStart" in String.prototype)) { - Object.defineProperty(String.prototype, "trimStart", { - writable: true, enumerable: false, configurable: true, - value: function () { return String(this).replace(/^\s+/, ""); } - }); -} - -/* String.prototype.trimLeft(); */ -if (!("trimLeft" in String.prototype)) { - Object.defineProperty(String.prototype, "trimLeft", { - writable: true, enumerable: false, configurable: true, - value: function () { return String(this).replace(/^\s+/, ""); } - }); -} - -/* String.prototype.trimEnd(); */ -if (!("trimEnd" in String.prototype)) { - Object.defineProperty(String.prototype, "trimEnd", { - writable: true, enumerable: false, configurable: true, - value: function () { return String(this).replace(/\s+$/, ""); } - }); -} - -/* String.prototype.trimRight(); */ -if (!("trimRight" in String.prototype)) { - Object.defineProperty(String.prototype, "trimRight", { - writable: true, enumerable: false, configurable: true, - value: function () { return String(this).replace(/\s+$/, ""); } - }); -} - -/* String.prototype.padStart(); */ -if (!("padStart" in String.prototype)) { - Object.defineProperty(String.prototype, "padStart", { - writable: true, enumerable: false, configurable: true, - value: function (len, str) { - len = Math.floor(Number(len)); - if (len <= this.length || len === NaN ) { - return String(this); - } else { - str = String(typeof str !== "undefined" ? str: " "); - if (str.length === 0) { return String(this); } - var res = "", n = Math.floor( (len - this.length) / str.length) + 1; - for (var i = 0; i < n; i++) { res += str; } - return res.slice(0, len - this.length) + String(this); - } - } - }); -} - -/* String.prototype.padEnd(); */ -if (!("padEnd" in String.prototype)) { - Object.defineProperty(String.prototype, "padEnd", { - writable: true, enumerable: false, configurable: true, - value: function (len, str) { - len = Math.floor(Number(len)); - if (len <= this.length || len === NaN ) { - return String(this); - } else { - str = String(typeof str !== "undefined" ? str: " "); - if (str.length === 0) { return String(this); } - var res = "", n = Math.floor( (len - this.length) / str.length) + 1; - for (var i = 0; i < n; i++) { res += str; } - return String(this) + res.slice(0, len - this.length); - } - } - }); -} - -/* String.prototype.replaceAll(); */ -if (!("replaceAll" in String.prototype)) { - Object.defineProperty(String.prototype, "replaceAll", { - "configurable": true, "writable": true, "enumerable": false, - "value": function (searchValue, replaceValue) { - "use strict"; - if (this == null) { - throw new TypeError("String.prototype.replaceAll requires |this| not to be null nor undefined"); - } - if (Object.prototype.toString.call(searchValue) - .replace(/^\[object (.+)\]$/, "$1").toLowerCase() === "regexp") { - if (!searchValue.global) { - throw new TypeError("String.prototype.replaceAll must be called with a global RegExp"); - } - return String(this).replace(searchValue, replaceValue); - } - return String(this).split(String(searchValue)).join(replaceValue); - } - }); -} - -/* Array.prototype.flat(); */ -if (!("flat" in Array.prototype)) { - Object.defineProperty(Array.prototype, "flat", { - writable: true, enumerable: false, configurable: true, - value: function (depth) { - if (depth === undefined) { - depth = 1; - } else { - depth = Math.floor(Number(depth)); - if (isNaN(depth) || depth < 1) { return this; } - } - function deepFlat (a, cd) { - a.forEach(function (e) { - if (Array.isArray(e)) { - if (cd < depth) { deepFlat(e, cd+1); } else { res.push(e); } - } else { - res.push(e); - } - }); - } - var res = []; - deepFlat(this, 0); - return res; - } - }); -} - -/* Array.prototype.flatMap(); */ -if (!("flatMap" in Array.prototype)) { - Object.defineProperty(Array.prototype, "flatMap", { - writable: true, enumerable: false, configurable: true, - value: function (fn) { - var res = []; - this.map(fn).forEach(function (e) { - if (Array.isArray(e)) { res = res.concat(e); } else { res.push(e); } - }); - return res; - } - }); -} - -/* Object.fromEntries(); */ -if (!Object.fromEntries) { - Object.fromEntries = function (entries) { - var r = {}; - for (let e of entries) { r[e[0]] = e[1]; } - return r; - }; -} - /* globalThis; */ (function (global) { if (!global.globalThis) { @@ -315,79 +118,6 @@ if (!Object.fromEntries) { } })(typeof this === "object" ? this : Function("return this")()); -/* String.prototype.matchAll(); */ -if (!("matchAll" in String.prototype)) { - Object.defineProperty(String.prototype, "matchAll", { - writable: true, enumerable: false, configurable: true, - value: function* (regex) { - function ef (fls, fl) { return (fls.includes(fl) ? fls : fls + fl); } - const lc = new RegExp(regex, ef(regex.flags, "g")); - let match; - while (match = lc.exec(this)) { yield match; } - } - }); -} - -/* Array.prototype.findLast(); */ -if (!("findLast" in Array.prototype)) { - Object.defineProperty(Array.prototype, "findLast", { - writable: true, enumerable: false, configurable: true, - value: function findLast (fn) { - if (typeof fn !== "function") { - throw new TypeError(String(fn) + " is not a function"); - } - var i = this.length; - while (i--) { if (fn(this[i],i,this)) { return this[i]; } } - return undefined; - } - }); -} - -/* Array.prototype.findLastIndex(); */ -if (!("findLastIndex" in Array.prototype)) { - Object.defineProperty(Array.prototype, "findLastIndex", { - writable: true, enumerable: false, configurable: true, - value: function findLastIndex (fn) { - if (typeof fn !== "function") { - throw new TypeError(String(fn) + " is not a function"); - } - var i = this.length; - while (i--) { if (fn(this[i],i,this)) { return i; } } - return -1; - } - }); -} - -/* TypedArray.prototype.findLast(); */ -if (!("findLast" in Uint8Array.prototype)) { - Object.defineProperty(Uint8Array.prototype, "findLast", { - writable: true, enumerable: false, configurable: true, - value: function findLast (fn) { - if (typeof fn !== "function") { - throw new TypeError(String(fn) + " is not a function"); - } - var i = this.length; - while (i--) { if (fn(this[i],i,this)) { return this[i]; } } - return undefined; - } - }); -} - -/* TypedArray.prototype.findLastIndex(); */ -if (!("findLastIndex" in Uint8Array.prototype)) { - Object.defineProperty(Uint8Array.prototype, "findLastIndex", { - writable: true, enumerable: false, configurable: true, - value: function findLastIndex (fn) { - if (typeof fn !== "function") { - throw new TypeError(String(fn) + " is not a function"); - } - var i = this.length; - while (i--) { if (fn(this[i],i,this)) { return i; } } - return -1; - } - }); -} - /* Array.prototype.toReversed(); */ if (!("toReversed" in Array.prototype)) { Object.defineProperty(Array.prototype, "toReversed", { @@ -479,22 +209,6 @@ const BASE58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; const BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; const WORDSAFEALPHABET= "23456789CFGHJMPQRVWXcfghjmpqvwx"; -/* randomID([hyphens = true][,usedate = false]) : string */ -function randomID (hyphens = true, useDate = false) { - let r = ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, - (c)=>(c^crypto.getRandomValues(new Uint8Array(1))[0]&15>>c/4).toString(16) - ); - if (!useDate) { return hyphens ? r : r.replaceAll("-", ""); } - if (useDate) { - let rA = [...r.replaceAll("-","")], d = (new Date()).getTime().toString(16); - for (let i = 0; i < d.length; i++) { rA[i] = d[i]; } - rA[12] = "4"; - r = rA.join(""); - return !hyphens ? r : r.slice(0, 8) - +"-"+r.slice(8,12)+"-"+r.slice(12,16) +"-"+r.slice(16,20)+"-"+r.slice(20); - } -} - /* delay().then(): promise */ const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); /* sleep().then(): promise */ @@ -503,15 +217,6 @@ const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms)); /* randomBoolean(): boolean */ const randomBoolean = () => (Math.random() >= 0.5); -/* randomString([length:integer[,specialCharactersEnabled=false]]): string */ -function randomString (pl = 100, sc = false) { - var chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - if (sc) { chars += ",?,.:-_*$ߤŁł÷׸¨˝´˙`˛°˘^ˇ~§'+!%/=()[]#<>&@{}\"\\/| éáűőúöüóíÉÁŰŐÚÖÜÓÍß"; } - var s = "", l = chars.length; - for (var i = 0; i < pl; i++) { s += chars[Math.floor(Math.random()*l)]; } - return s; -} - /* b64Encode(): string */ function b64Encode (s) { return btoa(encodeURIComponent(String(s)).replace(/%([0-9A-F]{2})/g, @@ -1080,11 +785,9 @@ const domSetCSSVar = (n, v) => /* domScrollToTop(): undefined */ const domScrollToTop = () => window.scrollTo(0,0); -const domToTop = () => window.scrollTo(0,0); /* domScrollToBottom(): undefined */ const domScrollToBottom = () => window.scrollTo(0, document.body.scrollHeight); -const domToBottom = () => window.scrollTo(0, document.body.scrollHeight); /* domScrollToElement([,top=true]): undefined */ const domScrollToElement = (e, top = true) => e.scrollIntoView(top); @@ -1521,7 +1224,7 @@ function shuffle([...a]) { const partition = ([...a],fn) => [a.filter(fn),a.filter((e,i,a)=>!(fn(e,i,a)))]; /* group(,[,map=false]): object */ -const group =([...a], fn, map=false) => a[(map?"groupToMap":"group")](fn); +const group =(items, fn, map=false)=> (map ? Map : Object)["groupBy"](items,fn); /* arrayUnion([,collectionN]): array */ const arrayUnion = (...a) => [...new Set(a.map(([...e]) => e).flat())]; @@ -2060,7 +1763,7 @@ const inRange = (v, i, a) => (v >= i && v <= a); /** object header **/ -const VERSION = "Celestra v5.5.5 dev"; +const VERSION = "Celestra v5.6.0 dev"; /* celestra.noConflict(): celestra object */ function noConflict () { window.CEL = celestra.__prevCEL__; return celestra; } @@ -2076,11 +1779,9 @@ var celestra = { BASE58: BASE58, BASE62: BASE62, WORDSAFEALPHABET: WORDSAFEALPHABET, - randomID: randomID, delay: delay, sleep: sleep, randomBoolean: randomBoolean, - randomString: randomString, b64Encode: b64Encode, b64Decode: b64Decode, javaHash: javaHash, @@ -2153,9 +1854,7 @@ var celestra = { domGetCSSVar: domGetCSSVar, domSetCSSVar: domSetCSSVar, domScrollToTop: domScrollToTop, - domToTop: domToTop, domScrollToBottom: domScrollToBottom, - domToBottom: domToBottom, domScrollToElement: domScrollToElement, /** AJAX API **/ getText: getText, diff --git a/celestra.esm.js b/celestra.esm.js index 966079c..de301df 100644 --- a/celestra.esm.js +++ b/celestra.esm.js @@ -1,32 +1,11 @@ "use strict"; -/** Celestra * @version 5.5.5 esm * @see https://github.com/Serrin/Celestra/ * @license MIT */ +/** Celestra * @version 5.6.0 esm * @see https://github.com/Serrin/Celestra/ * @license MIT */ +if(!("groupBy" in Object)){Object.defineProperty(Object,"groupBy",{"configurable":true,"writable":true,"enumerable":true,"value":function(items,callbackFn){"use strict";if(!(typeof callbackFn==="function")){throw new TypeError();}let r=Object.create(null),i=0;for(let item of items){let key=callbackFn(item,i++);if(!(Object.prototype.hasOwnProperty.call(r,key))){r[key]=[];}r[key].push(item);}return r;}});} +if(!("groupBy" in Map)){Object.defineProperty(Map,"groupBy",{"configurable":true,"writable":true,"enumerable":true,"value":function(items,callbackFn){"use strict";if(!(typeof callbackFn==="function")){throw new TypeError();}let r=new Map(),i=0;for(let item of items){let key=callbackFn(item,i++);if(!(r.has(key))){r.set(key,[]);}r.get(key).push(item);}return r;}});} if(!Array.fromAsync){Array.fromAsync=async function fromAsync(arrayLike,mapfn,thisArg){const isConstructor=(v)=>(typeof v==="function"&&typeof v.prototype==="object");const errorMsg="Input length exceed the Number.MAX_SAFE_INTEGER.";if(Symbol.asyncIterator in arrayLike||Symbol.iterator in arrayLike){var r=isConstructor(this)?new this:Array(0),i=0;for await(const item of arrayLike){if(i>Number.MAX_SAFE_INTEGER){throw TypeError(errorMsg);}else{if(!mapfn){r[i]=item;}else{r[i]=await mapfn.call(thisArg,item,i);}}i++;}r.length=i;return r;}else{var l=arrayLike.length,r=isConstructor(this)?new this(l):Array(l),i=0;while(iNumber.MAX_SAFE_INTEGER){throw TypeError(errorMsg);}var item=await arrayLike[i];if(!mapfn){r[i]=item;}else{r[i]=await mapfn.call(thisArg,item,i);}i++;}r.length=i;return r;}};} -if(!Object.is){Object.is=function(x,y){if(x===y){return x!==0||1/x===1/y;}else{return x!==x&&y!==y;}};} -if(!("MIN_SAFE_INTEGER" in Number)){Number.MIN_SAFE_INTEGER=-9007199254740991;} -if(!("MAX_SAFE_INTEGER" in Number)){Number.MAX_SAFE_INTEGER=9007199254740991;} if(("crypto" in window)&&!("randomUUID" in window.crypto)){window.crypto.randomUUID=function randomUUID(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(c)=>(c^crypto.getRandomValues(new Uint8Array(1))[0]&15>>c/4).toString(16));};} -if(!("group" in Array.prototype)){Object.defineProperty(Array.prototype,"group",{"configurable":true,"writable":true,"enumerable":false,"value":function(fn,thisArg){"use strict";function toArray(O){return (Array.isArray(O)?O:Array.from(O));}if(!(typeof fn==="function")){throw new TypeError();}var a=toArray(this);var key,r=Object.create(null),l=a.length;for(var i=0;i=this.length){return undefined;}return this[String(n)];}});} -if(!("at" in Uint8Array.prototype)){Object.defineProperty(Uint8Array.prototype,"at",{writable:true,enumerable:false,configurable:true,value:function at(n){n=Math.trunc(n)||0;if(n<0){n+=this.length;}if(n<0||n>=this.length){return undefined;}return this[String(n)];}});} -if(!("at" in String.prototype)){Object.defineProperty(String.prototype,"at",{writable:true,enumerable:false,configurable:true,value:function at(n){n=Math.trunc(n)||0;if(n<0){n+=this.length;}if(n<0||n>=this.length){return undefined;}return String(this)[String(n)];}});} if(!Object.hasOwn){Object.defineProperty(Object,"hasOwn",{value:function(object,property){if(object==null){throw new TypeError("Cannot convert undefined or null to object");}return Object.prototype.hasOwnProperty.call(Object(object),property);},configurable:true,enumerable:false,writable:true});} -if(!("trimStart" in String.prototype)){Object.defineProperty(String.prototype,"trimStart",{writable:true,enumerable:false,configurable:true,value:function(){return String(this).replace(/^\s+/,"");}});} -if(!("trimLeft" in String.prototype)){Object.defineProperty(String.prototype, "trimLeft",{writable:true,enumerable:false,configurable:true,value:function(){return String(this).replace(/^\s+/,"");}});} -if(!("trimEnd" in String.prototype)){Object.defineProperty(String.prototype,"trimEnd",{writable:true,enumerable:false,configurable:true,value:function(){return String(this).replace(/\s+$/,"");}});} -if(!("trimRight" in String.prototype)){Object.defineProperty(String.prototype,"trimRight",{writable:true,enumerable:false,configurable:true,value:function(){return String(this).replace(/\s+$/,"");}});} -if(!("padStart" in String.prototype)){Object.defineProperty(String.prototype,"padStart",{writable:true,enumerable:false,configurable:true,value:function(len,str){len=Math.floor(Number(len));if(len<=this.length||len===NaN){return String(this);}else{str=String(typeof str!=="undefined"?str:" ");if(str.length===0){return String(this);}var res="",n=Math.floor((len-this.length)/str.length)+1;for(var i=0;i(c^crypto.getRandomValues(new Uint8Array(1))[0]&15>>c/4).toString(16));if(!useDate){return hyphens?r:r.replaceAll("-","");}if(useDate){let rA=[...r.replaceAll("-","")],d=(new Date()).getTime().toString(16);for(let i=0;inew Promise(resolve=>setTimeout(resolve,ms)); const sleep=(ms)=>new Promise(resolve=>setTimeout(resolve,ms)); const randomBoolean=()=>(Math.random()>=0.5); -function randomString(pl=100,sc=false){var chars="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";if(sc){chars+=",?,.:-_*$ߤŁł÷׸¨˝´˙`˛°˘^ˇ~§'+!%/=()[]#<>&@{}\"\\/| éáűőúöüóíÉÁŰŐÚÖÜÓÍß";}var s="",l=chars.length;for(var i=0;igetComputedStyle(document.documentElement).getPropertyValue(n[0]==="-"?n:"--"+n); const domSetCSSVar=(n,v)=>document.documentElement.style.setProperty((n[0]==="-"?n:"--"+n),v); const domScrollToTop=()=>window.scrollTo(0,0); -const domToTop=()=>window.scrollTo(0,0); const domScrollToBottom=()=>window.scrollTo(0,document.body.scrollHeight); -const domToBottom=()=>window.scrollTo(0,document.body.scrollHeight); const domScrollToElement=(e,top=true)=>e.scrollIntoView(top); function getText(u,s){celestra.ajax({url:u,success:s});} function getJson(u,s){celestra.ajax({url:u,format:"json",success:s});} @@ -183,7 +158,7 @@ const arrayCreate=(length=0)=>Array((1/+length===1/-0)?0:+length); const initial=([...a])=>a.slice(0,-1); function shuffle([...a]){for(let i=a.length-1;i>0;i--){let j=Math.floor(Math.random()*(i+1));[a[i],a[j]]=[a[j],a[i]];}return a;} const partition=([...a],fn)=>[a.filter(fn),a.filter((e,i,a)=>!(fn(e,i,a)))]; -const group=([...a],fn,map=false)=>a[(map?"groupToMap":"group")](fn); +const group=(items,fn,map=false)=>(map?Map:Object)["groupBy"](items,fn); const arrayUnion=(...a)=>[...new Set(a.map(([...e])=>e).flat())]; const arrayIntersection=([...a],[...b])=>a.filter((v)=>b.indexOf(v)>-1).filter((e,i,arr)=>arr.indexOf(e)===i); const arrayDifference=([...a],[...b])=>a.filter((v)=>b.indexOf(v)===-1).filter((e,i,arr)=>arr.indexOf(e)===i); @@ -292,9 +267,9 @@ const signbit=(v)=>(((v=+v)!==v)?!1:((v<0)||Object.is(v,-0))); function randomInt(i=100,a){if(a==null){a=i;i=0;}i=Math.ceil(+i);return Math.floor(Math.random()*(Math.floor(+a)-i+1)+i);} function randomFloat(i=100,a){if(a==null){a=i;i=0;}var r=(Math.random()*(a-i+1))+i;return r>a?a:r;} const inRange=(v,i,a)=>(v>=i&&v<=a); -const VERSION="Celestra v5.5.5 esm"; +const VERSION="Celestra v5.6.0 esm"; function noConflict(){return celestra;} -var celestra = {VERSION:VERSION, noConflict:noConflict, BASE16:BASE16, BASE32:BASE32, BASE36:BASE36, BASE58:BASE58, BASE62:BASE62, WORDSAFEALPHABET:WORDSAFEALPHABET, randomID:randomID, delay:delay, sleep:sleep, randomBoolean:randomBoolean, randomString:randomString, b64Encode:b64Encode, b64Decode:b64Decode, javaHash:javaHash, inherit:inherit, getUrlVars:getUrlVars, obj2string:obj2string, classof:classof, extend:extend, sizeIn:sizeIn, forIn:forIn, filterIn:filterIn, popIn:popIn, unBind:unBind, bind:bind, constant:constant, identity:identity, noop:noop, T:T, F:F, assertEq:assertEq, assertNotEq:assertNotEq, assertTrue:assertTrue, assertFalse:assertFalse, nanoid:nanoid, timestampID:timestampID, strPropercase:strPropercase, strTitlecase:strTitlecase, strCapitalize:strCapitalize, strUpFirst:strUpFirst, strDownFirst:strDownFirst, strReverse:strReverse, strCodePoints:strCodePoints, strFromCodePoints:strFromCodePoints, strAt:strAt, strSplice:strSplice, strHTMLRemoveTags:strHTMLRemoveTags, strHTMLEscape:strHTMLEscape, strHTMLUnEscape:strHTMLUnEscape, qsa:qsa, qs:qs, domReady:domReady, domCreate:domCreate, domToElement:domToElement, domGetCSS:domGetCSS, domSetCSS:domSetCSS, domFadeIn:domFadeIn, domFadeOut:domFadeOut, domFadeToggle:domFadeToggle, domHide:domHide, domShow:domShow, domToggle:domToggle, domIsHidden:domIsHidden, domSiblings:domSiblings, domSiblingsPrev:domSiblingsPrev, domSiblingsLeft:domSiblingsLeft, domSiblingsNext:domSiblingsNext, domSiblingsRight:domSiblingsRight, importScript:importScript, importStyle:importStyle, form2array:form2array, form2string:form2string, getDoNotTrack:getDoNotTrack, getLocation:getLocation, createFile:createFile, getFullscreen:getFullscreen, setFullscreenOn:setFullscreenOn, setFullscreenOff:setFullscreenOff, domGetCSSVar:domGetCSSVar, domSetCSSVar:domSetCSSVar, domScrollToTop:domScrollToTop, domToTop:domToTop, domScrollToBottom:domScrollToBottom, domToBottom:domToBottom, domScrollToElement:domScrollToElement, getText:getText, getJson:getJson, ajax:ajax, isTruthy:isTruthy, isFalsy:isFalsy, isAsyncGeneratorFn:isAsyncGeneratorFn, isConstructorFn:isConstructorFn, isPlainObject:isPlainObject, isEmptyMap:isEmptyMap, isEmptySet:isEmptySet, isEmptyIterator:isEmptyIterator, isDataView:isDataView, isError:isError, isPromise:isPromise, isSameObject:isSameObject, isSameArray:isSameArray, isSameMap:isSameMap, isSameSet:isSameSet, isSameIterator:isSameIterator, isString:isString, isChar:isChar, isNumber:isNumber, isFloat:isFloat, isNumeric:isNumeric, isBoolean:isBoolean, isObject:isObject, isEmptyObject:isEmptyObject, isFunction:isFunction, isCallable:isCallable, isEmptyArray:isEmptyArray, isArraylike:isArraylike, isNull:isNull, isUndefined:isUndefined, isNullOrUndefined:isNullOrUndefined, isNil:isNil, isPrimitive:isPrimitive, isSymbol:isSymbol, isMap:isMap, isSet:isSet, isWeakMap:isWeakMap, isWeakSet:isWeakSet, isIterator:isIterator, isDate:isDate, isRegexp:isRegexp, isElement:isElement, isIterable:isIterable, isBigInt:isBigInt, isArrayBuffer:isArrayBuffer, isTypedArray:isTypedArray, isGeneratorFn:isGeneratorFn, isAsyncFn:isAsyncFn, setCookie:setCookie, getCookie:getCookie, hasCookie:hasCookie, removeCookie:removeCookie, clearCookies:clearCookies, arrayDeepClone:arrayDeepClone, arrayCreate:arrayCreate, initial:initial, shuffle:shuffle, partition:partition, group:group, arrayUnion:arrayUnion, arrayIntersection:arrayIntersection, arrayDifference:arrayDifference, arraySymmetricDifference:arraySymmetricDifference, setUnion:setUnion, setIntersection:setIntersection, setDifference:setDifference, setSymmetricDifference:setSymmetricDifference, isSuperset:isSuperset, min:min, max:max, arrayRepeat:arrayRepeat, arrayCycle:arrayCycle, arrayRange:arrayRange, zip:zip, unzip:unzip, zipObj:zipObj, arrayUnique:arrayUnique, arrayAdd:arrayAdd, arrayClear:arrayClear, arrayRemove:arrayRemove, arrayRemoveBy:arrayRemoveBy, arrayMerge:arrayMerge, iterRange:iterRange, iterCycle:iterCycle, iterRepeat:iterRepeat, takeWhile:takeWhile, dropWhile:dropWhile, take:take, drop:drop, forEach:forEach, forEachRight:forEachRight, map:map, filter:filter, reject:reject, slice:slice, tail:tail, item:item, nth:nth, size:size, first:first, head:head, last:last, reverse:reverse, sort:sort, includes:includes, contains:contains, find:find, findLast:findLast, every:every, some:some, none:none, takeRight:takeRight, takeRightWhile:takeRightWhile, dropRight:dropRight, dropRightWhile:dropRightWhile, concat:concat, reduce:reduce, enumerate:enumerate, entries:entries, flat:flat, join:join, withOut:withOut, getInV:getInV, getIn:getIn, setIn:setIn, hasIn:hasIn, isPropertyKey:isPropertyKey, toPropertyKey:toPropertyKey, toObject:toObject, isSameValue:isSameValue, isSameValueZero:isSameValueZero, isSameValueNonNumber:isSameValueNonNumber, createMethodProperty:createMethodProperty, type:type, isIndex:isIndex, toIndex:toIndex, toInteger:toInteger, createDataProperty:createDataProperty, toArray:toArray, sum:sum, avg:avg, product:product, clamp:clamp, minmax:minmax, isEven:isEven, isOdd:isOdd, toInt8:toInt8, toUInt8:toUInt8, toInt16:toInt16, toUInt16:toUInt16, toInt32:toInt32, toUInt32:toUInt32, toBigInt64:toBigInt64, toBigUInt64:toBigUInt64, toFloat32:toFloat32, isInt8:isInt8, isUInt8:isUInt8, isInt16:isInt16, isUInt16:isUInt16, isInt32:isInt32, isUInt32:isUInt32, isBigInt64:isBigInt64, isBigUInt64:isBigUInt64, signbit:signbit, randomInt:randomInt, randomFloat:randomFloat, inRange:inRange}; +var celestra = {VERSION:VERSION, noConflict:noConflict, BASE16:BASE16, BASE32:BASE32, BASE36:BASE36, BASE58:BASE58, BASE62:BASE62, WORDSAFEALPHABET:WORDSAFEALPHABET, delay:delay, sleep:sleep, randomBoolean:randomBoolean, b64Encode:b64Encode, b64Decode:b64Decode, javaHash:javaHash, inherit:inherit, getUrlVars:getUrlVars, obj2string:obj2string, classof:classof, extend:extend, sizeIn:sizeIn, forIn:forIn, filterIn:filterIn, popIn:popIn, unBind:unBind, bind:bind, constant:constant, identity:identity, noop:noop, T:T, F:F, assertEq:assertEq, assertNotEq:assertNotEq, assertTrue:assertTrue, assertFalse:assertFalse, nanoid:nanoid, timestampID:timestampID, strPropercase:strPropercase, strTitlecase:strTitlecase, strCapitalize:strCapitalize, strUpFirst:strUpFirst, strDownFirst:strDownFirst, strReverse:strReverse, strCodePoints:strCodePoints, strFromCodePoints:strFromCodePoints, strAt:strAt, strSplice:strSplice, strHTMLRemoveTags:strHTMLRemoveTags, strHTMLEscape:strHTMLEscape, strHTMLUnEscape:strHTMLUnEscape, qsa:qsa, qs:qs, domReady:domReady, domCreate:domCreate, domToElement:domToElement, domGetCSS:domGetCSS, domSetCSS:domSetCSS, domFadeIn:domFadeIn, domFadeOut:domFadeOut, domFadeToggle:domFadeToggle, domHide:domHide, domShow:domShow, domToggle:domToggle, domIsHidden:domIsHidden, domSiblings:domSiblings, domSiblingsPrev:domSiblingsPrev, domSiblingsLeft:domSiblingsLeft, domSiblingsNext:domSiblingsNext, domSiblingsRight:domSiblingsRight, importScript:importScript, importStyle:importStyle, form2array:form2array, form2string:form2string, getDoNotTrack:getDoNotTrack, getLocation:getLocation, createFile:createFile, getFullscreen:getFullscreen, setFullscreenOn:setFullscreenOn, setFullscreenOff:setFullscreenOff, domGetCSSVar:domGetCSSVar, domSetCSSVar:domSetCSSVar, domScrollToTop:domScrollToTop, domScrollToBottom:domScrollToBottom, domScrollToElement:domScrollToElement, getText:getText, getJson:getJson, ajax:ajax, isTruthy:isTruthy, isFalsy:isFalsy, isAsyncGeneratorFn:isAsyncGeneratorFn, isConstructorFn:isConstructorFn, isPlainObject:isPlainObject, isEmptyMap:isEmptyMap, isEmptySet:isEmptySet, isEmptyIterator:isEmptyIterator, isDataView:isDataView, isError:isError, isPromise:isPromise, isSameObject:isSameObject, isSameArray:isSameArray, isSameMap:isSameMap, isSameSet:isSameSet, isSameIterator:isSameIterator, isString:isString, isChar:isChar, isNumber:isNumber, isFloat:isFloat, isNumeric:isNumeric, isBoolean:isBoolean, isObject:isObject, isEmptyObject:isEmptyObject, isFunction:isFunction, isCallable:isCallable, isEmptyArray:isEmptyArray, isArraylike:isArraylike, isNull:isNull, isUndefined:isUndefined, isNullOrUndefined:isNullOrUndefined, isNil:isNil, isPrimitive:isPrimitive, isSymbol:isSymbol, isMap:isMap, isSet:isSet, isWeakMap:isWeakMap, isWeakSet:isWeakSet, isIterator:isIterator, isDate:isDate, isRegexp:isRegexp, isElement:isElement, isIterable:isIterable, isBigInt:isBigInt, isArrayBuffer:isArrayBuffer, isTypedArray:isTypedArray, isGeneratorFn:isGeneratorFn, isAsyncFn:isAsyncFn, setCookie:setCookie, getCookie:getCookie, hasCookie:hasCookie, removeCookie:removeCookie, clearCookies:clearCookies, arrayDeepClone:arrayDeepClone, arrayCreate:arrayCreate, initial:initial, shuffle:shuffle, partition:partition, group:group, arrayUnion:arrayUnion, arrayIntersection:arrayIntersection, arrayDifference:arrayDifference, arraySymmetricDifference:arraySymmetricDifference, setUnion:setUnion, setIntersection:setIntersection, setDifference:setDifference, setSymmetricDifference:setSymmetricDifference, isSuperset:isSuperset, min:min, max:max, arrayRepeat:arrayRepeat, arrayCycle:arrayCycle, arrayRange:arrayRange, zip:zip, unzip:unzip, zipObj:zipObj, arrayUnique:arrayUnique, arrayAdd:arrayAdd, arrayClear:arrayClear, arrayRemove:arrayRemove, arrayRemoveBy:arrayRemoveBy, arrayMerge:arrayMerge, iterRange:iterRange, iterCycle:iterCycle, iterRepeat:iterRepeat, takeWhile:takeWhile, dropWhile:dropWhile, take:take, drop:drop, forEach:forEach, forEachRight:forEachRight, map:map, filter:filter, reject:reject, slice:slice, tail:tail, item:item, nth:nth, size:size, first:first, head:head, last:last, reverse:reverse, sort:sort, includes:includes, contains:contains, find:find, findLast:findLast, every:every, some:some, none:none, takeRight:takeRight, takeRightWhile:takeRightWhile, dropRight:dropRight, dropRightWhile:dropRightWhile, concat:concat, reduce:reduce, enumerate:enumerate, entries:entries, flat:flat, join:join, withOut:withOut, getInV:getInV, getIn:getIn, setIn:setIn, hasIn:hasIn, isPropertyKey:isPropertyKey, toPropertyKey:toPropertyKey, toObject:toObject, isSameValue:isSameValue, isSameValueZero:isSameValueZero, isSameValueNonNumber:isSameValueNonNumber, createMethodProperty:createMethodProperty, type:type, isIndex:isIndex, toIndex:toIndex, toInteger:toInteger, createDataProperty:createDataProperty, toArray:toArray, sum:sum, avg:avg, product:product, clamp:clamp, minmax:minmax, isEven:isEven, isOdd:isOdd, toInt8:toInt8, toUInt8:toUInt8, toInt16:toInt16, toUInt16:toUInt16, toInt32:toInt32, toUInt32:toUInt32, toBigInt64:toBigInt64, toBigUInt64:toBigUInt64, toFloat32:toFloat32, isInt8:isInt8, isUInt8:isUInt8, isInt16:isInt16, isUInt16:isUInt16, isInt32:isInt32, isUInt32:isUInt32, isBigInt64:isBigInt64, isBigUInt64:isBigUInt64, signbit:signbit, randomInt:randomInt, randomFloat:randomFloat, inRange:inRange}; /* ESM */ export default celestra; export {celestra}; \ No newline at end of file diff --git a/celestra.html b/celestra.html index 648a95f..c0b8261 100644 --- a/celestra.html +++ b/celestra.html @@ -75,8 +75,8 @@

Download

Tested on desktop browsers (latest Firefox, latest Chrome, latest stable Chromium based Edge) and mobile devices (iOS Safari, Chrome, Firefox and Android Chrome, Samsung Internet, Firefox, Edge). This library isn't compatible with the Node.js.

-

Latest version: 5.5.5

-

Date: 2023-07-20T19:38:41.746Z

+

Latest version: 5.6.0

+

Date: 2023-10-22T19:41:13.967Z

The functions are available in the celestra and/or CEL object.

@@ -112,7 +112,7 @@

Download

Removed polyfills

-

Some polyfills have been removed in v3.1.0 and v3.8.0. With these files can be reusued the old polyfills if needed.

+

Some polyfills have been removed in v3.1.0 and v3.8.0 and v5.6.0. With these files can be reusued the old polyfills if needed.

@@ -254,18 +254,9 @@

Core API

@@ -297,6 +288,7 @@

Core API

@@ -646,11 +638,11 @@

DOM API

- + - + @@ -1075,6 +1067,8 @@ - + @@ -1585,6 +1579,14 @@

Polyfills

+ + + + + + + + @@ -1616,10 +1618,6 @@

Polyfills

- - - - @@ -1635,120 +1633,28 @@

Polyfills

The randomUUID() method of the Crypto interface is used to generate a v4 UUID using a cryptographically secure random number generator. For more information please read the MDN Article! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + +
randomID([hyphens=true][,usedate=false]); DEPRECATED in v5.5.4 +
REMOVED in v5.6.0
Can be replaced with the crypto.randomUUID();, which is polyfilled in this library.
Generate a GUID/UUID v4 random ID. The hyphens and useDate parameters are optional and can be a boolean. The return value is a string. -
Example: -
randomID(false); -
-> -
"0e0f739a306b4faad62e3e8080826c9c" -
randomID(true, true); -
-> -
"17c3d79b-d413-4443-b4cd-5426c7299726" -
randomID(); -
-> -
"bc897cdf-da26-42de-83e2-d1fd458e079f"
randomString([length[,specialCharactersEnabled=false]]); DEPRECATED in v5.5.2 +
REMOVED in v5.6.0
Can be replaced with with the CEL.nanoid();.
Generate a random string. The length parameter is optional and can be a number and the default value is 100. The specialCharactersEnabled parameter is optional and can be a boolean and the default value is false. Return the generated string.
domScrollToTop();Old name before v5.4.4: domToTop.
This function is scrolling to the top of the page.
Old name before v5.5.4: domToTop.
This function is scrolling to the top of the page.
domScrollToTop();Old name before v5.4.4: domToBottom.
This function is scrolling to the bottom of the page.
Old name before v5.5.4: domToBottom.
This function is scrolling to the bottom of the page.
domScrollToElement(<element>[,top=true]);
group(<collection>,<callback>[,map=false]); +

Deprecated in v5.6.0. Will be removed in 5.7.0.

+

Can be replaced with the Object.groupBy(); and Map.groupBy();.

Old name before v5.4.4: groupBy.
Returns an Object or Map with array properties. The keys are the returned values of the given function. The collection parameter is mandatory. The callback parameter is mandatory and has to be a function. The map parameter is optional and has to be a boolean and if it is true, then the return value is a Map instead of Object.

Example: @@ -1461,7 +1455,7 @@

Math API

minmax(<value>,<min>,<max>);This is an alias of the minmax(<value>,<min>,<max>);.This is an alias of the clamp(<value>,<min>,<max>);.
isEven(<value>); Name Description
Object.groupBy();The Object.groupBy() static method groups the elements of a given iterable according to the string values returned by a provided callback function. The returned object has separate properties for each group, containing arrays with the elements in the group. For more information please read the MDN Article!
Map.groupBy();The Map.groupBy() static method groups the elements of a given iterable using the values returned by a provided callback function. The final returned Map uses the unique values from the test function as keys, which can be used to get the array of elements in each group. For more information please read the MDN Article!
Array.fromAsync(); The Array.fromAsync() static method creates a new, shallow-copied Array instance from an async iterable, iterable, or array-like object. For more information please read the MDN Article!
TypedArray.prototype.with(); The with() method is the copying version of using the bracket notation to change the value of a given index. It returns a new array with the element at the given index replaced with the given value. This method has the same algorithm as Array.prototype.with(). For more information please read the MDN Article!
Object.is();The Object.is() method determines whether two values are the same value. For more information please read the MDN Article!
Number.MIN_SAFE_INTEGER
Array.prototype.group(<fn>[,thisArg]);The group() method grouping of items in an array based on the return value (key) of the given function. The return value is a null-prototype object. For more information please read the MDN Article!
Array.prototype.groupToMap(<fn>[,thisArg]);The groupToMap() method grouping of items in an array based on the return value (key) of the given function. The return value is a Map object. For more information please read the MDN Article!
Array.prototype.findLast(); - The findLast() method returns the value of the last element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned. For more information please read the MDN Article! -
Array.prototype.findLastIndex(); - The findLastIndex() method returns the index of the last element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test. For more information please read the MDN Article! -
TypedArray.prototype.findLast(); - The findLast() method returns the value of the last element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned. For more information please read the MDN Article! -
TypedArray.prototype.findLastIndex(); - The findLastIndex() method returns the index of the last element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test. For more information please read the MDN Article! -
Array.prototype.at(); - The at() method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array. - For more information please read the MDN Article! -
TypedArray.prototype.at(); - The at() method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array. - For more information please read the MDN Article! -
String.prototype.at(); - The at() method takes an integer value and returns a new String consisting of the single UTF-16 code unit located at the specified offset. This method allows for positive and negative integers. Negative integers count back from the last string character. For more information please read the MDN Article! -
Object.hasOwn(); The Object.hasOwn() static method returns true if the specified object has the indicated property as its own property. If the property is inherited, or does not exist, the method returns false. For more information please read the MDN Article!
String.prototype.trimStart();The trimStart() method removes whitespace from the beginning of a string. For more information please read the MDN Article!
String.prototype.trimLeft();Alias of the String.prototype.trimStart(); method.
String.prototype.trimEnd();The trimEnd() method removes whitespace from the end of a string. For more information please read the MDN Article!
String.prototype.trimRight();Alias of the String.prototype.trimEnd(); method.
String.prototype.padStart();The padStart() method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start (left) of the current string. For more information please read the MDN Article!
String.prototype.padEnd();The padEnd() method pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end (right) of the current string. For more information please read the MDN Article!
Object.fromEntries();The Object.fromEntries() method transforms a list of key-value pairs into an object. For more information please read the MDN Article!
Array.prototype.flat();The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. For more information please read the MDN Article!
Array.prototype.flatMap();A new array with each element being the result of the callback function and flattened to a depth of 1. For more information please read the MDN Article!
globalThis; The "global" property of the global object, a writable, configurable, non-enumerable alias of window/self. For more information please read the MDN Article!
String.prototype.matchAll();The matchAll() method returns an iterator of all results matching a string against a regular expression, including capturing groups. For more information please read the MDN Article!
String.prototype.replaceAll();The replaceAll() method returns a new string with all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp. For more information please read the MDN Article!
REMOVED polyfills in v3.1.0Array.from();
Array.of();
Array.prototype.fill();
Array.prototype.find();
Array.prototype.findIndex();
Object.create();
String.prototype.startsWith();
String.prototype.endsWith();
Array.prototype.copyWithin();
String.fromCodePoint();
String.prototype.codePointAt();7
Number.EPSILON;
Number.isNaN();
isNaN();
Number.isInteger();
Number.isFinite();
Number.isSafeInteger();
Number.parseInt();
Number.parseFloat();
Math.acosh();
Math.asinh();
Math.atanh();
Math.cbrt();
Math.clz32();
Math.cosh();
Math.expm1();
Math.fround();
Math.hypot();
Math.imul();
Math.log1p();
Math.log10();
Math.log2();
Math.sign();
Math.sinh();
Math.tanh();
Math.trunc();
Array.from();
Array.of();
Array.prototype.fill();
Array.prototype.find();
Array.prototype.findIndex();
Object.create();
String.prototype.startsWith();
String.prototype.endsWith();
Array.prototype.copyWithin();
String.fromCodePoint();
String.prototype.codePointAt();
Number.EPSILON;
Number.isNaN();
isNaN();
Number.isInteger();
Number.isFinite();
Number.isSafeInteger();
Number.parseInt();
Number.parseFloat();
Math.acosh();
Math.asinh();
Math.atanh();
Math.cbrt();
Math.clz32();
Math.cosh();
Math.expm1();
Math.fround();
Math.hypot();
Math.imul();
Math.log1p();
Math.log10();
Math.log2();
Math.sign();
Math.sinh();
Math.tanh();
Math.trunc();
REMOVED polyfills in v3.8.0 Array.prototype.values();
Array.prototype.includes();
String.prototype.includes();
String.prototype.repeat();
String.prototype[Symbol.iterator]();
Object.assign();
Object.entries();
Object.values();
Object.getOwnPropertyDescriptors();
RegExp.prototype.flags;
NodeList.prototype.forEach();
ChildNode.after();
ChildNode.before();
ChildNode.remove();
ChildNode.replaceWith();
ParentNode.append();
ParentNode.prepend();
Element.prototype.matches();
Element.prototype.closest();
Element.prototype.toggleAttribute();
Element.prototype.getAttributeNames();
window.screenLeft;
window.screenTop;
REMOVED polyfills in v5.6.0Array.prototype.at();
Array.prototype.findLast();
Array.prototype.findLastIndex();
Array.prototype.flat();
Array.prototype.flatMap();
Array.prototype.group();
Array.prototype.groupToMap();
Number.MIN_SAFE_INTEGER;
Number.MAX_SAFE_INTEGER;
Object.fromEntries();
Object.is();
String.prototype.at();
String.prototype.matchAll();
String.prototype.padStart();
String.prototype.padEnd();
String.prototype.replaceAll();
String.prototype.trimStart();
String.prototype.trimLeft();
String.prototype.trimEnd();
String.prototype.trimRight();
Typedarray.prototype.at();
TypedArray.prototype.findLast();
TypedArray.prototype.findLastIndex();
diff --git a/celestra.min.js b/celestra.min.js index 4924791..9217c2b 100644 --- a/celestra.min.js +++ b/celestra.min.js @@ -1,33 +1,12 @@ -/** Celestra * @version 5.5.5 min * @see https://github.com/Serrin/Celestra/ * @license MIT */ +/** Celestra * @version 5.6.0 min * @see https://github.com/Serrin/Celestra/ * @license MIT */ (function(window,document){ "use strict"; +if(!("groupBy" in Object)){Object.defineProperty(Object,"groupBy",{"configurable":true,"writable":true,"enumerable":true,"value":function(items,callbackFn){"use strict";if(!(typeof callbackFn==="function")){throw new TypeError();}let r=Object.create(null),i=0;for(let item of items){let key=callbackFn(item,i++);if(!(Object.prototype.hasOwnProperty.call(r,key))){r[key]=[];}r[key].push(item);}return r;}});} +if(!("groupBy" in Map)){Object.defineProperty(Map,"groupBy",{"configurable":true,"writable":true,"enumerable":true,"value":function(items,callbackFn){"use strict";if(!(typeof callbackFn==="function")){throw new TypeError();}let r=new Map(),i=0;for(let item of items){let key=callbackFn(item,i++);if(!(r.has(key))){r.set(key,[]);}r.get(key).push(item);}return r;}});} if(!Array.fromAsync){Array.fromAsync=async function fromAsync(arrayLike,mapfn,thisArg){const isConstructor=(v)=>(typeof v==="function"&&typeof v.prototype==="object");const errorMsg="Input length exceed the Number.MAX_SAFE_INTEGER.";if(Symbol.asyncIterator in arrayLike||Symbol.iterator in arrayLike){var r=isConstructor(this)?new this:Array(0),i=0;for await(const item of arrayLike){if(i>Number.MAX_SAFE_INTEGER){throw TypeError(errorMsg);}else{if(!mapfn){r[i]=item;}else{r[i]=await mapfn.call(thisArg,item,i);}}i++;}r.length=i;return r;}else{var l=arrayLike.length,r=isConstructor(this)?new this(l):Array(l),i=0;while(iNumber.MAX_SAFE_INTEGER){throw TypeError(errorMsg);}var item=await arrayLike[i];if(!mapfn){r[i]=item;}else{r[i]=await mapfn.call(thisArg,item,i);}i++;}r.length=i;return r;}};} -if(!Object.is){Object.is=function(x,y){if(x===y){return x!==0||1/x===1/y;}else{return x!==x&&y!==y;}};} -if(!("MIN_SAFE_INTEGER" in Number)){Number.MIN_SAFE_INTEGER=-9007199254740991;} -if(!("MAX_SAFE_INTEGER" in Number)){Number.MAX_SAFE_INTEGER=9007199254740991;} if(("crypto" in window)&&!("randomUUID" in window.crypto)){window.crypto.randomUUID=function randomUUID(){return([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(c)=>(c^crypto.getRandomValues(new Uint8Array(1))[0]&15>>c/4).toString(16));};} -if(!("group" in Array.prototype)){Object.defineProperty(Array.prototype,"group",{"configurable":true,"writable":true,"enumerable":false,"value":function(fn,thisArg){"use strict";function toArray(O){return (Array.isArray(O)?O:Array.from(O));}if(!(typeof fn==="function")){throw new TypeError();}var a=toArray(this);var key,r=Object.create(null),l=a.length;for(var i=0;i=this.length){return undefined;}return this[String(n)];}});} -if(!("at" in Uint8Array.prototype)){Object.defineProperty(Uint8Array.prototype,"at",{writable:true,enumerable:false,configurable:true,value:function at(n){n=Math.trunc(n)||0;if(n<0){n+=this.length;}if(n<0||n>=this.length){return undefined;}return this[String(n)];}});} -if(!("at" in String.prototype)){Object.defineProperty(String.prototype,"at",{writable:true,enumerable:false,configurable:true,value:function at(n){n=Math.trunc(n)||0;if(n<0){n+=this.length;}if(n<0||n>=this.length){return undefined;}return String(this)[String(n)];}});} if(!Object.hasOwn){Object.defineProperty(Object,"hasOwn",{value:function(object,property){if(object==null){throw new TypeError("Cannot convert undefined or null to object");}return Object.prototype.hasOwnProperty.call(Object(object),property);},configurable:true,enumerable:false,writable:true});} -if(!("trimStart" in String.prototype)){Object.defineProperty(String.prototype,"trimStart",{writable:true,enumerable:false,configurable:true,value:function(){return String(this).replace(/^\s+/,"");}});} -if(!("trimLeft" in String.prototype)){Object.defineProperty(String.prototype, "trimLeft",{writable:true,enumerable:false,configurable:true,value:function(){return String(this).replace(/^\s+/,"");}});} -if(!("trimEnd" in String.prototype)){Object.defineProperty(String.prototype,"trimEnd",{writable:true,enumerable:false,configurable:true,value:function(){return String(this).replace(/\s+$/,"");}});} -if(!("trimRight" in String.prototype)){Object.defineProperty(String.prototype,"trimRight",{writable:true,enumerable:false,configurable:true,value:function(){return String(this).replace(/\s+$/,"");}});} -if(!("padStart" in String.prototype)){Object.defineProperty(String.prototype,"padStart",{writable:true,enumerable:false,configurable:true,value:function(len,str){len=Math.floor(Number(len));if(len<=this.length||len===NaN){return String(this);}else{str=String(typeof str!=="undefined"?str:" ");if(str.length===0){return String(this);}var res="",n=Math.floor((len-this.length)/str.length)+1;for(var i=0;i(c^crypto.getRandomValues(new Uint8Array(1))[0]&15>>c/4).toString(16));if(!useDate){return hyphens?r:r.replaceAll("-","");}if(useDate){let rA=[...r.replaceAll("-","")],d=(new Date()).getTime().toString(16);for(let i=0;inew Promise(resolve=>setTimeout(resolve,ms)); const sleep=(ms)=>new Promise(resolve=>setTimeout(resolve,ms)); const randomBoolean=()=>(Math.random()>=0.5); -function randomString(pl=100,sc=false){var chars="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";if(sc){chars+=",?,.:-_*$ߤŁł÷׸¨˝´˙`˛°˘^ˇ~§'+!%/=()[]#<>&@{}\"\\/| éáűőúöüóíÉÁŰŐÚÖÜÓÍß";}var s="",l=chars.length;for(var i=0;igetComputedStyle(document.documentElement).getPropertyValue(n[0]==="-"?n:"--"+n); const domSetCSSVar=(n,v)=>document.documentElement.style.setProperty((n[0]==="-"?n:"--"+n),v); const domScrollToTop=()=>window.scrollTo(0,0); -const domToTop=()=>window.scrollTo(0,0); const domScrollToBottom=()=>window.scrollTo(0,document.body.scrollHeight); -const domToBottom=()=>window.scrollTo(0,document.body.scrollHeight); const domScrollToElement=(e,top=true)=>e.scrollIntoView(top); function getText(u,s){celestra.ajax({url:u,success:s});} function getJson(u,s){celestra.ajax({url:u,format:"json",success:s});} @@ -184,7 +159,7 @@ const arrayCreate=(length=0)=>Array((1/+length===1/-0)?0:+length); const initial=([...a])=>a.slice(0,-1); function shuffle([...a]){for(let i=a.length-1;i>0;i--){let j=Math.floor(Math.random()*(i+1));[a[i],a[j]]=[a[j],a[i]];}return a;} const partition=([...a],fn)=>[a.filter(fn),a.filter((e,i,a)=>!(fn(e,i,a)))]; -const group=([...a],fn,map=false)=>a[(map?"groupToMap":"group")](fn); +const group=(items,fn,map=false)=>(map?Map:Object)["groupBy"](items,fn); const arrayUnion=(...a)=>[...new Set(a.map(([...e])=>e).flat())]; const arrayIntersection=([...a],[...b])=>a.filter((v)=>b.indexOf(v)>-1).filter((e,i,arr)=>arr.indexOf(e)===i); const arrayDifference=([...a],[...b])=>a.filter((v)=>b.indexOf(v)===-1).filter((e,i,arr)=>arr.indexOf(e)===i); @@ -293,8 +268,8 @@ const signbit=(v)=>(((v=+v)!==v)?!1:((v<0)||Object.is(v,-0))); function randomInt(i=100,a){if(a==null){a=i;i=0;}i=Math.ceil(+i);return Math.floor(Math.random()*(Math.floor(+a)-i+1)+i);} function randomFloat(i=100,a){if(a==null){a=i;i=0;}var r=(Math.random()*(a-i+1))+i;return r>a?a:r;} const inRange=(v,i,a)=>(v>=i&&v<=a); -const VERSION="Celestra v5.5.5 esm"; +const VERSION="Celestra v5.6.0 min"; function noConflict(){return celestra;} -var celestra = {VERSION:VERSION, noConflict:noConflict, BASE16:BASE16, BASE32:BASE32, BASE36:BASE36, BASE58:BASE58, BASE62:BASE62, WORDSAFEALPHABET:WORDSAFEALPHABET, randomID:randomID, delay:delay, sleep:sleep, randomBoolean:randomBoolean, randomString:randomString, b64Encode:b64Encode, b64Decode:b64Decode, javaHash:javaHash, inherit:inherit, getUrlVars:getUrlVars, obj2string:obj2string, classof:classof, extend:extend, sizeIn:sizeIn, forIn:forIn, filterIn:filterIn, popIn:popIn, unBind:unBind, bind:bind, constant:constant, identity:identity, noop:noop, T:T, F:F, assertEq:assertEq, assertNotEq:assertNotEq, assertTrue:assertTrue, assertFalse:assertFalse, nanoid:nanoid, timestampID:timestampID, strPropercase:strPropercase, strTitlecase:strTitlecase, strCapitalize:strCapitalize, strUpFirst:strUpFirst, strDownFirst:strDownFirst, strReverse:strReverse, strCodePoints:strCodePoints, strFromCodePoints:strFromCodePoints, strAt:strAt, strSplice:strSplice, strHTMLRemoveTags:strHTMLRemoveTags, strHTMLEscape:strHTMLEscape, strHTMLUnEscape:strHTMLUnEscape, qsa:qsa, qs:qs, domReady:domReady, domCreate:domCreate, domToElement:domToElement, domGetCSS:domGetCSS, domSetCSS:domSetCSS, domFadeIn:domFadeIn, domFadeOut:domFadeOut, domFadeToggle:domFadeToggle, domHide:domHide, domShow:domShow, domToggle:domToggle, domIsHidden:domIsHidden, domSiblings:domSiblings, domSiblingsPrev:domSiblingsPrev, domSiblingsLeft:domSiblingsLeft, domSiblingsNext:domSiblingsNext, domSiblingsRight:domSiblingsRight, importScript:importScript, importStyle:importStyle, form2array:form2array, form2string:form2string, getDoNotTrack:getDoNotTrack, getLocation:getLocation, createFile:createFile, getFullscreen:getFullscreen, setFullscreenOn:setFullscreenOn, setFullscreenOff:setFullscreenOff, domGetCSSVar:domGetCSSVar, domSetCSSVar:domSetCSSVar, domScrollToTop:domScrollToTop, domToTop:domToTop, domScrollToBottom:domScrollToBottom, domToBottom:domToBottom, domScrollToElement:domScrollToElement, getText:getText, getJson:getJson, ajax:ajax, isTruthy:isTruthy, isFalsy:isFalsy, isAsyncGeneratorFn:isAsyncGeneratorFn, isConstructorFn:isConstructorFn, isPlainObject:isPlainObject, isEmptyMap:isEmptyMap, isEmptySet:isEmptySet, isEmptyIterator:isEmptyIterator, isDataView:isDataView, isError:isError, isPromise:isPromise, isSameObject:isSameObject, isSameArray:isSameArray, isSameMap:isSameMap, isSameSet:isSameSet, isSameIterator:isSameIterator, isString:isString, isChar:isChar, isNumber:isNumber, isFloat:isFloat, isNumeric:isNumeric, isBoolean:isBoolean, isObject:isObject, isEmptyObject:isEmptyObject, isFunction:isFunction, isCallable:isCallable, isEmptyArray:isEmptyArray, isArraylike:isArraylike, isNull:isNull, isUndefined:isUndefined, isNullOrUndefined:isNullOrUndefined, isNil:isNil, isPrimitive:isPrimitive, isSymbol:isSymbol, isMap:isMap, isSet:isSet, isWeakMap:isWeakMap, isWeakSet:isWeakSet, isIterator:isIterator, isDate:isDate, isRegexp:isRegexp, isElement:isElement, isIterable:isIterable, isBigInt:isBigInt, isArrayBuffer:isArrayBuffer, isTypedArray:isTypedArray, isGeneratorFn:isGeneratorFn, isAsyncFn:isAsyncFn, setCookie:setCookie, getCookie:getCookie, hasCookie:hasCookie, removeCookie:removeCookie, clearCookies:clearCookies, arrayDeepClone:arrayDeepClone, arrayCreate:arrayCreate, initial:initial, shuffle:shuffle, partition:partition, group:group, arrayUnion:arrayUnion, arrayIntersection:arrayIntersection, arrayDifference:arrayDifference, arraySymmetricDifference:arraySymmetricDifference, setUnion:setUnion, setIntersection:setIntersection, setDifference:setDifference, setSymmetricDifference:setSymmetricDifference, isSuperset:isSuperset, min:min, max:max, arrayRepeat:arrayRepeat, arrayCycle:arrayCycle, arrayRange:arrayRange, zip:zip, unzip:unzip, zipObj:zipObj, arrayUnique:arrayUnique, arrayAdd:arrayAdd, arrayClear:arrayClear, arrayRemove:arrayRemove, arrayRemoveBy:arrayRemoveBy, arrayMerge:arrayMerge, iterRange:iterRange, iterCycle:iterCycle, iterRepeat:iterRepeat, takeWhile:takeWhile, dropWhile:dropWhile, take:take, drop:drop, forEach:forEach, forEachRight:forEachRight, map:map, filter:filter, reject:reject, slice:slice, tail:tail, item:item, nth:nth, size:size, first:first, head:head, last:last, reverse:reverse, sort:sort, includes:includes, contains:contains, find:find, findLast:findLast, every:every, some:some, none:none, takeRight:takeRight, takeRightWhile:takeRightWhile, dropRight:dropRight, dropRightWhile:dropRightWhile, concat:concat, reduce:reduce, enumerate:enumerate, entries:entries, flat:flat, join:join, withOut:withOut, getInV:getInV, getIn:getIn, setIn:setIn, hasIn:hasIn, isPropertyKey:isPropertyKey, toPropertyKey:toPropertyKey, toObject:toObject, isSameValue:isSameValue, isSameValueZero:isSameValueZero, isSameValueNonNumber:isSameValueNonNumber, createMethodProperty:createMethodProperty, type:type, isIndex:isIndex, toIndex:toIndex, toInteger:toInteger, createDataProperty:createDataProperty, toArray:toArray, sum:sum, avg:avg, product:product, clamp:clamp, minmax:minmax, isEven:isEven, isOdd:isOdd, toInt8:toInt8, toUInt8:toUInt8, toInt16:toInt16, toUInt16:toUInt16, toInt32:toInt32, toUInt32:toUInt32, toBigInt64:toBigInt64, toBigUInt64:toBigUInt64, toFloat32:toFloat32, isInt8:isInt8, isUInt8:isUInt8, isInt16:isInt16, isUInt16:isUInt16, isInt32:isInt32, isUInt32:isUInt32, isBigInt64:isBigInt64, isBigUInt64:isBigUInt64, signbit:signbit, randomInt:randomInt, randomFloat:randomFloat, inRange:inRange}; +var celestra = {VERSION:VERSION, noConflict:noConflict, BASE16:BASE16, BASE32:BASE32, BASE36:BASE36, BASE58:BASE58, BASE62:BASE62, WORDSAFEALPHABET:WORDSAFEALPHABET, delay:delay, sleep:sleep, randomBoolean:randomBoolean, b64Encode:b64Encode, b64Decode:b64Decode, javaHash:javaHash, inherit:inherit, getUrlVars:getUrlVars, obj2string:obj2string, classof:classof, extend:extend, sizeIn:sizeIn, forIn:forIn, filterIn:filterIn, popIn:popIn, unBind:unBind, bind:bind, constant:constant, identity:identity, noop:noop, T:T, F:F, assertEq:assertEq, assertNotEq:assertNotEq, assertTrue:assertTrue, assertFalse:assertFalse, nanoid:nanoid, timestampID:timestampID, strPropercase:strPropercase, strTitlecase:strTitlecase, strCapitalize:strCapitalize, strUpFirst:strUpFirst, strDownFirst:strDownFirst, strReverse:strReverse, strCodePoints:strCodePoints, strFromCodePoints:strFromCodePoints, strAt:strAt, strSplice:strSplice, strHTMLRemoveTags:strHTMLRemoveTags, strHTMLEscape:strHTMLEscape, strHTMLUnEscape:strHTMLUnEscape, qsa:qsa, qs:qs, domReady:domReady, domCreate:domCreate, domToElement:domToElement, domGetCSS:domGetCSS, domSetCSS:domSetCSS, domFadeIn:domFadeIn, domFadeOut:domFadeOut, domFadeToggle:domFadeToggle, domHide:domHide, domShow:domShow, domToggle:domToggle, domIsHidden:domIsHidden, domSiblings:domSiblings, domSiblingsPrev:domSiblingsPrev, domSiblingsLeft:domSiblingsLeft, domSiblingsNext:domSiblingsNext, domSiblingsRight:domSiblingsRight, importScript:importScript, importStyle:importStyle, form2array:form2array, form2string:form2string, getDoNotTrack:getDoNotTrack, getLocation:getLocation, createFile:createFile, getFullscreen:getFullscreen, setFullscreenOn:setFullscreenOn, setFullscreenOff:setFullscreenOff, domGetCSSVar:domGetCSSVar, domSetCSSVar:domSetCSSVar, domScrollToTop:domScrollToTop, domScrollToBottom:domScrollToBottom, domScrollToElement:domScrollToElement, getText:getText, getJson:getJson, ajax:ajax, isTruthy:isTruthy, isFalsy:isFalsy, isAsyncGeneratorFn:isAsyncGeneratorFn, isConstructorFn:isConstructorFn, isPlainObject:isPlainObject, isEmptyMap:isEmptyMap, isEmptySet:isEmptySet, isEmptyIterator:isEmptyIterator, isDataView:isDataView, isError:isError, isPromise:isPromise, isSameObject:isSameObject, isSameArray:isSameArray, isSameMap:isSameMap, isSameSet:isSameSet, isSameIterator:isSameIterator, isString:isString, isChar:isChar, isNumber:isNumber, isFloat:isFloat, isNumeric:isNumeric, isBoolean:isBoolean, isObject:isObject, isEmptyObject:isEmptyObject, isFunction:isFunction, isCallable:isCallable, isEmptyArray:isEmptyArray, isArraylike:isArraylike, isNull:isNull, isUndefined:isUndefined, isNullOrUndefined:isNullOrUndefined, isNil:isNil, isPrimitive:isPrimitive, isSymbol:isSymbol, isMap:isMap, isSet:isSet, isWeakMap:isWeakMap, isWeakSet:isWeakSet, isIterator:isIterator, isDate:isDate, isRegexp:isRegexp, isElement:isElement, isIterable:isIterable, isBigInt:isBigInt, isArrayBuffer:isArrayBuffer, isTypedArray:isTypedArray, isGeneratorFn:isGeneratorFn, isAsyncFn:isAsyncFn, setCookie:setCookie, getCookie:getCookie, hasCookie:hasCookie, removeCookie:removeCookie, clearCookies:clearCookies, arrayDeepClone:arrayDeepClone, arrayCreate:arrayCreate, initial:initial, shuffle:shuffle, partition:partition, group:group, arrayUnion:arrayUnion, arrayIntersection:arrayIntersection, arrayDifference:arrayDifference, arraySymmetricDifference:arraySymmetricDifference, setUnion:setUnion, setIntersection:setIntersection, setDifference:setDifference, setSymmetricDifference:setSymmetricDifference, isSuperset:isSuperset, min:min, max:max, arrayRepeat:arrayRepeat, arrayCycle:arrayCycle, arrayRange:arrayRange, zip:zip, unzip:unzip, zipObj:zipObj, arrayUnique:arrayUnique, arrayAdd:arrayAdd, arrayClear:arrayClear, arrayRemove:arrayRemove, arrayRemoveBy:arrayRemoveBy, arrayMerge:arrayMerge, iterRange:iterRange, iterCycle:iterCycle, iterRepeat:iterRepeat, takeWhile:takeWhile, dropWhile:dropWhile, take:take, drop:drop, forEach:forEach, forEachRight:forEachRight, map:map, filter:filter, reject:reject, slice:slice, tail:tail, item:item, nth:nth, size:size, first:first, head:head, last:last, reverse:reverse, sort:sort, includes:includes, contains:contains, find:find, findLast:findLast, every:every, some:some, none:none, takeRight:takeRight, takeRightWhile:takeRightWhile, dropRight:dropRight, dropRightWhile:dropRightWhile, concat:concat, reduce:reduce, enumerate:enumerate, entries:entries, flat:flat, join:join, withOut:withOut, getInV:getInV, getIn:getIn, setIn:setIn, hasIn:hasIn, isPropertyKey:isPropertyKey, toPropertyKey:toPropertyKey, toObject:toObject, isSameValue:isSameValue, isSameValueZero:isSameValueZero, isSameValueNonNumber:isSameValueNonNumber, createMethodProperty:createMethodProperty, type:type, isIndex:isIndex, toIndex:toIndex, toInteger:toInteger, createDataProperty:createDataProperty, toArray:toArray, sum:sum, avg:avg, product:product, clamp:clamp, minmax:minmax, isEven:isEven, isOdd:isOdd, toInt8:toInt8, toUInt8:toUInt8, toInt16:toInt16, toUInt16:toUInt16, toInt32:toInt32, toUInt32:toUInt32, toBigInt64:toBigInt64, toBigUInt64:toBigUInt64, toFloat32:toFloat32, isInt8:isInt8, isUInt8:isUInt8, isInt16:isInt16, isUInt16:isUInt16, isInt32:isInt32, isUInt32:isUInt32, isBigInt64:isBigInt64, isBigUInt64:isBigUInt64, signbit:signbit, randomInt:randomInt, randomFloat:randomFloat, inRange:inRange}; if (typeof window!=="undefined"){window.celestra=celestra;celestra.__prevCEL__=window.CEL;window.CEL=celestra;} }(window,document)); \ No newline at end of file diff --git a/js-cheatsheet.odt b/js-cheatsheet.odt index 2fe585c..d820ee8 100644 Binary files a/js-cheatsheet.odt and b/js-cheatsheet.odt differ diff --git a/js-cheatsheet.pdf b/js-cheatsheet.pdf index 102d4f2..3bb6a1d 100644 Binary files a/js-cheatsheet.pdf and b/js-cheatsheet.pdf differ diff --git a/unittest.js b/unittest.js index b40f0c0..84e1bf7 100644 --- a/unittest.js +++ b/unittest.js @@ -183,7 +183,7 @@ CUT.isNotEqual( (function(){ "use strict"; -/* Celestra v5.5.5 testcases */ +/* Celestra v5.6.0 testcases */ /* Not auto tested functions */ CUT.addElement("hr"); @@ -248,63 +248,6 @@ CUT.isTrue("v3.8.1 aliases removed in v4.0.0", && CEL.isUndefined(CEL.forOf) ); -// randomID begin - -var rIDstr = CEL.randomID(false); -CUT.isTrue("randomID(false); without date without date default", - rIDstr.length === 32 && /[0-9a-fA-F]/.test(rIDstr) -); -CUT.log("\"" + rIDstr + "\""); - -var rIDstr = CEL.randomID(); -CUT.isTrue("randomID(); with hyphens without date default", - rIDstr.length === 36 - && /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/ - .test(rIDstr) - && rIDstr[14] === "4" - && "89ab".includes(rIDstr[19]) -); -CUT.log("\"" + rIDstr + "\""); - -var rIDstr = CEL.randomID(false, true); -CUT.isTrue("randomID(); without hyphens with date", - rIDstr.length === 32 && /[0-9a-fA-F]/.test(rIDstr) -); -CUT.log("\"" + rIDstr + "\""); - -var rIDstr = CEL.randomID(true); -CUT.isTrue("randomID(true); with hyphens without date", - rIDstr.length === 36 - && /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/ - .test(rIDstr) - && rIDstr[14] === "4" - && "89ab".includes(rIDstr[19]) -); -CUT.log("\"" + rIDstr + "\""); - -var rIDstr = CEL.randomID(false, true); -CUT.isTrue("randomID(false); with date with date", - rIDstr.length === 32 && /[0-9a-fA-F]/.test(rIDstr) ); -CUT.log("\"" + rIDstr + "\""); - -var rIDstr = CEL.randomID(true, true); -CUT.isTrue("randomID(); with hyphens with date", - rIDstr.length === 36 && - /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/ - .test(rIDstr) -); -CUT.log("\"" + rIDstr + "\""); - -var rIDstr = CEL.randomID(true, false); -CUT.isTrue("randomID(true); with hyphens without date", - rIDstr.length === 36 && - /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/ - .test(rIDstr) -); -CUT.log("\"" + rIDstr + "\""); - -// randomID end - CUT.isTrue("assertTrue();", CEL.assertTrue("lorem ipsum", true) ); CUT.isTrue("assertFalse();", CEL.assertFalse("lorem ipsum", false) ); CUT.isTrue("assertEq(); 1", CEL.assertEq("lorem ipsum", 1, 1) ); @@ -542,25 +485,6 @@ var testRandom = CEL.randomBoolean(); CUT.isTrue("randomBoolean(); - " + testRandom + "", CEL.isBoolean(testRandom) && (testRandom === true || testRandom === false) ); -var rndStr = CEL.randomString(); -CUT.isTrue("randomString(); default length 100, default false", - CEL.isString(rndStr) && rndStr.length === 100); -CUT.log(""+rndStr+""); -rndStr = CEL.randomString(10); -CUT.isTrue("randomString(10) default false", - CEL.isString(rndStr) && rndStr.length === 10); -CUT.log(""+rndStr+""); -rndStr = CEL.randomString(15,true); -CUT.isTrue("randomString(15,true);", CEL.isString(rndStr) &&rndStr.length===15); -CUT.log(""+rndStr+""); -rndStr = CEL.randomString(20,false); -CUT.isTrue("randomString(20,false);", CEL.isString(rndStr)&&rndStr.length===20); -CUT.log(""+rndStr+""); -rndStr = "1" + CEL.randomString(32,false); -CUT.isEqual("randomString(); random \"btc\" address", true, - CEL.isString(rndStr) && rndStr.length === 33 ); -CUT.log(""+rndStr+""); - var kayleeStr = "✓ à \r\n\t árvíztűrő tükörfúrógép ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP ,?;.:-_* ¤÷ר¸´˙`˛°˘^ˇ~'+!%/=()|\\<> \" \/ #&@{}[]€ ÍÄíŁß 0123456789 asdfghjklqwertzuiopyxcvbnm ASDFGHJKLQWERTZUIOPYXCVBNM"; CUT.isEqual("b64Encode();", "4pyTIMOgIA0KCSDDoXJ2w616dMWxcsWRIHTDvGvDtnJmw7pyw7Nnw6lwIMOBUlbDjVpUxbBSxZAgVMOcS8OWUkbDmlLDk0fDiVAgLD87LjotXyogwqTDt8OXwqjCuMK0y5lgy5vCsMuYXsuHficrISUvPSgpfFw8PiAiIC8gIyZAe31bXeKCrCDDjcOEw63FgcOfIDAxMjM0NTY3ODkgYXNkZmdoamtscXdlcnR6dWlvcHl4Y3Zibm0gQVNERkdISktMUVdFUlRaVUlPUFlYQ1ZCTk0=", @@ -1636,75 +1560,23 @@ CUT.isEqual("Object.is();", CUT.isEqual("Number.MIN_SAFE_INTEGER;",Number.MIN_SAFE_INTEGER,-9007199254740991); CUT.isEqual("Number.MAX_SAFE_INTEGER;",Number.MAX_SAFE_INTEGER,9007199254740991); -var groupArray = [1,2,3,4,5]; -var groupArrayObj = {"length": 5, 0: 1, 1: 2, 2: 3, 3: 4, 4: 5}; -var groupArrayRES = groupArray.group(i => (i % 2 === 0 ? "even": "odd")); -CUT.isTrue("Array.prototype.group(<fn>[,thisArg]); 1", - Object.prototype.toString.call(groupArrayRES).slice(8, -1).toLowerCase() - === "object" - && Object.keys(groupArrayRES).length === 2 - && Object.hasOwn(groupArrayRES, "even") - && Object.hasOwn(groupArrayRES, "odd") - && JSON.stringify(groupArrayRES["even"]) === "[2,4]" - && JSON.stringify(groupArrayRES["odd"]) === "[1,3,5]" -); -var groupArrayRES = Array.prototype.group.call( - groupArray, i => (i % 2 === 0 ? "even": "odd") -); -CUT.isTrue("Array.prototype.group(<fn>[,thisArg]); 2", - Object.prototype.toString.call(groupArrayRES).slice(8, -1).toLowerCase() - === "object" - && Object.keys(groupArrayRES).length === 2 - && Object.hasOwn(groupArrayRES, "even") - && Object.hasOwn(groupArrayRES, "odd") - && JSON.stringify(groupArrayRES["even"]) === "[2,4]" - && JSON.stringify(groupArrayRES["odd"]) === "[1,3,5]" -); -var groupArrayRES = Array.prototype.group.call( - groupArrayObj, i => (i % 2 === 0 ? "even": "odd") -); -CUT.isTrue("Array.prototype.group(<fn>[,thisArg]); 3", - Object.prototype.toString.call(groupArrayRES).slice(8, -1).toLowerCase() - === "object" - && Object.keys(groupArrayRES).length === 2 - && Object.hasOwn(groupArrayRES, "even") - && Object.hasOwn(groupArrayRES, "odd") - && JSON.stringify(groupArrayRES["even"]) === "[2,4]" - && JSON.stringify(groupArrayRES["odd"]) === "[1,3,5]" -); -var groupArrayRES = groupArray.groupToMap(i => (i % 2 === 0 ? "even": "odd")); -CUT.isTrue("Array.prototype.groupToMap(<fn>[,thisArg]); 1", - Object.prototype.toString.call(groupArrayRES).slice(8, -1).toLowerCase() - === "map" - && groupArrayRES.size === 2 - && groupArrayRES.has("even") - && groupArrayRES.has("odd") - && JSON.stringify(groupArrayRES.get("even")) === "[2,4]" - && JSON.stringify(groupArrayRES.get("odd")) === "[1,3,5]" -); -var groupArrayRES = Array.prototype.groupToMap.call( - groupArray, i => (i % 2 === 0 ? "even": "odd") -); -CUT.isTrue("Array.prototype.groupToMap(<fn>[,thisArg]); 2", - Object.prototype.toString.call(groupArrayRES).slice(8, -1).toLowerCase() - === "map" - && groupArrayRES.size === 2 - && groupArrayRES.has("even") - && groupArrayRES.has("odd") - && JSON.stringify(groupArrayRES.get("even")) === "[2,4]" - && JSON.stringify(groupArrayRES.get("odd")) === "[1,3,5]" -); -var groupArrayRES = Array.prototype.groupToMap.call( - groupArrayObj, i => (i % 2 === 0 ? "even": "odd") +const groupByInventory = [ + { name: 'asparagus', type: 'vegetables', quantity: 9 }, + { name: 'bananas', type: 'fruit', quantity: 5 }, + { name: 'goat', type: 'meat', quantity: 23 }, + { name: 'cherries', type: 'fruit', quantity: 12 }, + { name: 'fish', type: 'meat', quantity: 3 }, +]; + + +CUT.isEqual("Object.groupBy();", + JSON.stringify(Object.groupBy(groupByInventory, ({ quantity }) => (quantity < 6 ? "restock" : "sufficient"))), + '{"sufficient":[{"name":"asparagus","type":"vegetables","quantity":9},{"name":"goat","type":"meat","quantity":23},{"name":"cherries","type":"fruit","quantity":12}],"restock":[{"name":"bananas","type":"fruit","quantity":5},{"name":"fish","type":"meat","quantity":3}]}' ); -CUT.isTrue("Array.prototype.groupToMap(<fn>[,thisArg]); 3", - Object.prototype.toString.call(groupArrayRES).slice(8, -1).toLowerCase() - === "map" - && groupArrayRES.size === 2 - && groupArrayRES.has("even") - && groupArrayRES.has("odd") - && JSON.stringify(groupArrayRES.get("even")) === "[2,4]" - && JSON.stringify(groupArrayRES.get("odd")) === "[1,3,5]" + +CUT.isEqual("Map.groupBy();", + JSON.stringify(Array.from(Map.groupBy(groupByInventory, ({ quantity }) => (quantity < 6 ? "restock" : "sufficient")))), + '[["sufficient",[{"name":"asparagus","type":"vegetables","quantity":9},{"name":"goat","type":"meat","quantity":23},{"name":"cherries","type":"fruit","quantity":12}]],["restock",[{"name":"bananas","type":"fruit","quantity":5},{"name":"fish","type":"meat","quantity":3}]]]' ); var rIDstr = crypto.randomUUID();