toosoon-utils 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Capitalize a string
3
+ *
4
+ * @param {string} string String to capitalize
5
+ * @returns {string} Capitalized string
6
+ */
7
+ export declare function capitalize(string: string): string;
8
+ /**
9
+ * Clean a path by removing params
10
+ *
11
+ * @param {string} path Path to clean
12
+ * @returns {string} Cleaned path
13
+ */
14
+ export declare function cleanPath(path: string): string;
package/lib/strings.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanPath = exports.capitalize = void 0;
4
+ /**
5
+ * Capitalize a string
6
+ *
7
+ * @param {string} string String to capitalize
8
+ * @returns {string} Capitalized string
9
+ */
10
+ function capitalize(string) {
11
+ return string.charAt(0).toUpperCase() + string.slice(1);
12
+ }
13
+ exports.capitalize = capitalize;
14
+ /**
15
+ * Clean a path by removing params
16
+ *
17
+ * @param {string} path Path to clean
18
+ * @returns {string} Cleaned path
19
+ */
20
+ function cleanPath(path) {
21
+ return path.split('#')[0].split('?')[0];
22
+ }
23
+ exports.cleanPath = cleanPath;
@@ -0,0 +1 @@
1
+ {"program":{"fileNames":["../node_modules/typescript/lib/lib.d.ts","../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../node_modules/typescript/lib/lib.scripthost.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2017.date.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/typescript/lib/lib.esnext.intl.d.ts","../node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../src/constants.ts","../src/types.ts","../src/geometry.ts","../src/maths.ts","../src/colors.ts","../src/dom.ts","../src/files.ts","../src/functions.ts","../src/now.ts","../src/random.ts","../src/strings.ts","../src/index.ts","../node_modules/@types/node/assert.d.ts","../node_modules/@types/node/assert/strict.d.ts","../node_modules/undici-types/header.d.ts","../node_modules/undici-types/readable.d.ts","../node_modules/undici-types/file.d.ts","../node_modules/undici-types/fetch.d.ts","../node_modules/undici-types/formdata.d.ts","../node_modules/undici-types/connector.d.ts","../node_modules/undici-types/client.d.ts","../node_modules/undici-types/errors.d.ts","../node_modules/undici-types/dispatcher.d.ts","../node_modules/undici-types/global-dispatcher.d.ts","../node_modules/undici-types/global-origin.d.ts","../node_modules/undici-types/pool-stats.d.ts","../node_modules/undici-types/pool.d.ts","../node_modules/undici-types/handlers.d.ts","../node_modules/undici-types/balanced-pool.d.ts","../node_modules/undici-types/agent.d.ts","../node_modules/undici-types/mock-interceptor.d.ts","../node_modules/undici-types/mock-agent.d.ts","../node_modules/undici-types/mock-client.d.ts","../node_modules/undici-types/mock-pool.d.ts","../node_modules/undici-types/mock-errors.d.ts","../node_modules/undici-types/proxy-agent.d.ts","../node_modules/undici-types/api.d.ts","../node_modules/undici-types/cookies.d.ts","../node_modules/undici-types/patch.d.ts","../node_modules/undici-types/filereader.d.ts","../node_modules/undici-types/diagnostics-channel.d.ts","../node_modules/undici-types/websocket.d.ts","../node_modules/undici-types/content-type.d.ts","../node_modules/undici-types/cache.d.ts","../node_modules/undici-types/interceptors.d.ts","../node_modules/undici-types/index.d.ts","../node_modules/@types/node/globals.d.ts","../node_modules/@types/node/async_hooks.d.ts","../node_modules/@types/node/buffer.d.ts","../node_modules/@types/node/child_process.d.ts","../node_modules/@types/node/cluster.d.ts","../node_modules/@types/node/console.d.ts","../node_modules/@types/node/constants.d.ts","../node_modules/@types/node/crypto.d.ts","../node_modules/@types/node/dgram.d.ts","../node_modules/@types/node/diagnostics_channel.d.ts","../node_modules/@types/node/dns.d.ts","../node_modules/@types/node/dns/promises.d.ts","../node_modules/@types/node/domain.d.ts","../node_modules/@types/node/dom-events.d.ts","../node_modules/@types/node/events.d.ts","../node_modules/@types/node/fs.d.ts","../node_modules/@types/node/fs/promises.d.ts","../node_modules/@types/node/http.d.ts","../node_modules/@types/node/http2.d.ts","../node_modules/@types/node/https.d.ts","../node_modules/@types/node/inspector.d.ts","../node_modules/@types/node/module.d.ts","../node_modules/@types/node/net.d.ts","../node_modules/@types/node/os.d.ts","../node_modules/@types/node/path.d.ts","../node_modules/@types/node/perf_hooks.d.ts","../node_modules/@types/node/process.d.ts","../node_modules/@types/node/punycode.d.ts","../node_modules/@types/node/querystring.d.ts","../node_modules/@types/node/readline.d.ts","../node_modules/@types/node/readline/promises.d.ts","../node_modules/@types/node/repl.d.ts","../node_modules/@types/node/stream.d.ts","../node_modules/@types/node/stream/promises.d.ts","../node_modules/@types/node/stream/consumers.d.ts","../node_modules/@types/node/stream/web.d.ts","../node_modules/@types/node/string_decoder.d.ts","../node_modules/@types/node/test.d.ts","../node_modules/@types/node/timers.d.ts","../node_modules/@types/node/timers/promises.d.ts","../node_modules/@types/node/tls.d.ts","../node_modules/@types/node/trace_events.d.ts","../node_modules/@types/node/tty.d.ts","../node_modules/@types/node/url.d.ts","../node_modules/@types/node/util.d.ts","../node_modules/@types/node/v8.d.ts","../node_modules/@types/node/vm.d.ts","../node_modules/@types/node/wasi.d.ts","../node_modules/@types/node/worker_threads.d.ts","../node_modules/@types/node/zlib.d.ts","../node_modules/@types/node/globals.global.d.ts","../node_modules/@types/node/index.d.ts"],"fileInfos":["a7297ff837fcdf174a9524925966429eb8e5feecc2cc55cc06574e6b092c1eaa",{"version":"f33e5332b24c3773e930e212cbb8b6867c8ba3ec4492064ea78e55a524d57450","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","26f2f787e82c4222710f3b676b4d83eb5ad0a72fa7b746f03449e7a026ce5073","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4",{"version":"21e41a76098aa7a191028256e52a726baafd45a925ea5cf0222eb430c96c1d83","affectsGlobalScope":true},{"version":"80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89","affectsGlobalScope":true},{"version":"cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573","affectsGlobalScope":true},{"version":"138fb588d26538783b78d1e3b2c2cc12d55840b97bf5e08bca7f7a174fbe2f17","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"e0275cd0e42990dc3a16f0b7c8bca3efe87f1c8ad404f80c6db1c7c0b828c59f","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"49ed889be54031e1044af0ad2c603d627b8bda8b50c1a68435fe85583901d072","affectsGlobalScope":true},{"version":"e93d098658ce4f0c8a0779e6cab91d0259efb88a318137f686ad76f8410ca270","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"ec0104fee478075cb5171e5f4e3f23add8e02d845ae0165bfa3f1099241fa2aa","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"acae90d417bee324b1372813b5a00829d31c7eb670d299cd7f8f9a648ac05688","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"13f6e6380c78e15e140243dc4be2fa546c287c6d61f4729bc2dd7cf449605471","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},{"version":"c10f64b494e9a37f8bd983e874a03a17670d8405d98c7a065821921c545a48f7","signature":"8375cf161a0f21acd9ff0b3bc4c00780dfdfe6b508f312dd839702d8c4251c68"},{"version":"223745a7683ea5a3522e0d6419b0e639e10e5408aff27b86568901fef768f591","signature":"50c69a2b59e87e2aebdd6294b41cf6d9896ce198d05b4c1691d832a48c5393f4"},{"version":"cc859cf585321ba13306b886bcf6970f5745db282e886226da571d148fdcbb46","signature":"600074017fd954caf6d25d3111edb02aaa24bd91074d928cd02a2d713d6ea757"},{"version":"bcbd63cc0e57b35308858e624267b68ee6d9c9d02cb0a2d847fad074a33efd30","signature":"0ee705cedd747b89444ca301c710e45a43fa2f46be6eee021c204e677485b2da"},{"version":"6a7bca3c2a73ac500fce173f0af0491cd3dbb8c80196fa39dab02a47ac91fc95","signature":"3510aeb3423ac8b327be41d4bbd7cb499f66d8e0fbeb9066602a7436dbc45d51"},{"version":"5fca568d9fe91b3c1d6928a962bd8874ceaad50d8ce7355efb333dfc9e7b087a","signature":"3de595b5b4fe6c50f526b62dc9536c54ba6f97f7c7652d5730914de3be6cdaac"},{"version":"cdac34b1bfa8c5301a99aae634399581b07d441a342b2e99af272efacd28bf33","signature":"aefd19e3ecee790394b8e83bef9e0edb96417d603367ac43459bebad63de0048"},{"version":"704ae5b207e9e2554a1fbfea2e5055d23a1e9735819c868ccf7935d05080bfc8","signature":"7a629cbd546b33944f330f69db11c17a1121dad8ba23b6d232ff8c5d9ef28e58"},{"version":"07b66ab5b8a992f40130fe16efd6874a337ea4a651762bd169181ad15043ee1d","signature":"d43b3a78108cb3511d734b51e03e24ac5dc922e9791dded3ded9dc567629c838"},{"version":"52cbd1c8d55a99cb3f58c09f4537890345baba3e4913a0afcd962ac8916ed799","signature":"661d17747fcf18e933f4f73cea2589d144d39499e7686abb665335f6b01ddeab"},{"version":"7ff1ac0e7aebca773d04dda761bca41d14320e0622ef69f6f2447e7b000f4fa7","signature":"399d115998e6ee77790354467a58babe1c7ee7caba7eed1bf471f4ec8a9a365f"},{"version":"c9aff01f7720775b1365489a4a3aed910bca1c6420ed71dea163cbd67906d850","signature":"5c8e49206787be9b02bf3e581c239d9cf71efbb8e82834ecd1b159936f1277c7"},"efc7d584a33fe3422847783d228f315c4cd1afe74bd7cf8e3f0e4c1125129fef","7394959e5a741b185456e1ef5d64599c36c60a323207450991e7a42e08911419","5929864ce17fba74232584d90cb721a89b7ad277220627cc97054ba15a98ea8f","7180c03fd3cb6e22f911ce9ba0f8a7008b1a6ddbe88ccf16a9c8140ef9ac1686","25c8056edf4314820382a5fdb4bb7816999acdcb929c8f75e3f39473b87e85bc","54cb85a47d760da1c13c00add10d26b5118280d44d58e6908d8e89abbd9d7725","3e4825171442666d31c845aeb47fcd34b62e14041bb353ae2b874285d78482aa","c6fd2c5a395f2432786c9cb8deb870b9b0e8ff7e22c029954fabdd692bff6195","a967bfe3ad4e62243eb604bf956101e4c740f5921277c60debaf325c1320bf88","e9775e97ac4877aebf963a0289c81abe76d1ec9a2a7778dbe637e5151f25c5f3","471e1da5a78350bc55ef8cef24eb3aca6174143c281b8b214ca2beda51f5e04a","cadc8aced301244057c4e7e73fbcae534b0f5b12a37b150d80e5a45aa4bebcbd","385aab901643aa54e1c36f5ef3107913b10d1b5bb8cbcd933d4263b80a0d7f20","9670d44354bab9d9982eca21945686b5c24a3f893db73c0dae0fd74217a4c219","db3435f3525cd785bf21ec6769bf8da7e8a776be1a99e2e7efb5f244a2ef5fee","c3b170c45fc031db31f782e612adf7314b167e60439d304b49e704010e7bafe5","40383ebef22b943d503c6ce2cb2e060282936b952a01bea5f9f493d5fb487cc7","4893a895ea92c85345017a04ed427cbd6a1710453338df26881a6019432febdd","3a84b7cb891141824bd00ef8a50b6a44596aded4075da937f180c90e362fe5f6","13f6f39e12b1518c6650bbb220c8985999020fe0f21d818e28f512b7771d00f9","9b5369969f6e7175740bf51223112ff209f94ba43ecd3bb09eefff9fd675624a","4fe9e626e7164748e8769bbf74b538e09607f07ed17c2f20af8d680ee49fc1da","24515859bc0b836719105bb6cc3d68255042a9f02a6022b3187948b204946bd2","33203609eba548914dc83ddf6cadbc0bcb6e8ef89f6d648ca0908ae887f9fcc5","0db18c6e78ea846316c012478888f33c11ffadab9efd1cc8bcc12daded7a60b6","89167d696a849fce5ca508032aabfe901c0868f833a8625d5a9c6e861ef935d2","e53a3c2a9f624d90f24bf4588aacd223e7bec1b9d0d479b68d2f4a9e6011147f","339dc5265ee5ed92e536a93a04c4ebbc2128f45eeec6ed29f379e0085283542c","9f0a92164925aa37d4a5d9dd3e0134cff8177208dba55fd2310cd74beea40ee2","8bfdb79bf1a9d435ec48d9372dc93291161f152c0865b81fc0b2694aedb4578d","2e85db9e6fd73cfa3d7f28e0ab6b55417ea18931423bd47b409a96e4a169e8e6","c46e079fe54c76f95c67fb89081b3e399da2c7d109e7dca8e4b58d83e332e605","d32275be3546f252e3ad33976caf8c5e842c09cb87d468cb40d5f4cf092d1acc","4a0c3504813a3289f7fb1115db13967c8e004aa8e4f8a9021b95285502221bd1",{"version":"a14ed46fa3f5ffc7a8336b497cd07b45c2084213aaca933a22443fcb2eef0d07","affectsGlobalScope":true},"cce1f5f86974c1e916ec4a8cab6eec9aa8e31e8148845bf07fbaa8e1d97b1a2c",{"version":"e2eb1ce13a9c0fa7ab62c63909d81973ef4b707292667c64f1e25e6e53fa7afa","affectsGlobalScope":true},"16d74fe4d8e183344d3beb15d48b123c5980ff32ff0cc8c3b96614ddcdf9b239","7b43160a49cf2c6082da0465876c4a0b164e160b81187caeb0a6ca7a281e85ba",{"version":"41fb2a1c108fbf46609ce5a451b7ec78eb9b5ada95fd5b94643e4b26397de0b3","affectsGlobalScope":true},"a40826e8476694e90da94aa008283a7de50d1dafd37beada623863f1901cb7fb",{"version":"a1d2988ad9d2aef7b9915a22b5e52c165c83a878f2851c35621409046bbe3c05","affectsGlobalScope":true},"bd3f5d05b6b5e4bfcea7739a45f3ffb4a7f4a3442ba7baf93e0200799285b8f1","4c775c2fccabf49483c03cd5e3673f87c1ffb6079d98e7b81089c3def79e29c6","8806ae97308ef26363bd7ec8071bca4d07fb575f905ee3d8a91aff226df6d618","af5bf1db6f1804fb0069039ae77a05d60133c77a2158d9635ea27b6bb2828a8f","b7fe70be794e13d1b7940e318b8770cd1fb3eced7707805318a2e3aaac2c3e9e",{"version":"2c71199d1fc83bf17636ad5bf63a945633406b7b94887612bba4ef027c662b3e","affectsGlobalScope":true},{"version":"7ae9dc7dbb58cd843065639707815df85c044babaa0947116f97bdb824d07204","affectsGlobalScope":true},"fe1fd6afdfe77976d4c702f3746c05fb05a7e566845c890e0e970fe9376d6a90","313a0b063f5188037db113509de1b934a0e286f14e9479af24fada241435e707","f1ace2d2f98429e007d017c7a445efad2aaebf8233135abdb2c88b8c0fef91ab","87ef1a23caa071b07157c72077fa42b86d30568f9dc9e31eed24d5d14fc30ba8","396a8939b5e177542bdf9b5262b4eee85d29851b2d57681fa9d7eae30e225830","21773f5ac69ddf5a05636ba1f50b5239f4f2d27e4420db147fc2f76a5ae598ac",{"version":"ea455cc68871b049bcecd9f56d4cf27b852d6dafd5e3b54468ca87cc11604e4d","affectsGlobalScope":true},"c07146dbbbd8b347241b5df250a51e48f2d7bef19b1e187b1a3f20c849988ff1","45b1053e691c5af9bfe85060a3e1542835f8d84a7e6e2e77ca305251eda0cb3c","0f05c06ff6196958d76b865ae17245b52d8fe01773626ac3c43214a2458ea7b7",{"version":"ae5507fc333d637dec9f37c6b3f4d423105421ea2820a64818de55db85214d66","affectsGlobalScope":true},{"version":"0666f4c99b8688c7be5956df8fecf5d1779d3b22f8f2a88258ae7072c7b6026f","affectsGlobalScope":true},"8abd0566d2854c4bd1c5e48e05df5c74927187f1541e6770001d9637ac41542e","54e854615c4eafbdd3fd7688bd02a3aafd0ccf0e87c98f79d3e9109f047ce6b8","d8dba11dc34d50cb4202de5effa9a1b296d7a2f4a029eec871f894bddfb6430d","8b71dd18e7e63b6f991b511a201fad7c3bf8d1e0dd98acb5e3d844f335a73634","01d8e1419c84affad359cc240b2b551fb9812b450b4d3d456b64cda8102d4f60","8221b00f271cf7f535a8eeec03b0f80f0929c7a16116e2d2df089b41066de69b","269929a24b2816343a178008ac9ae9248304d92a8ba8e233055e0ed6dbe6ef71","93452d394fdd1dc551ec62f5042366f011a00d342d36d50793b3529bfc9bd633","7424817d5eb498771e6d1808d726ec38f75d2eaf3fa359edd5c0c540c52725c1","9a9634296cca836c3308923ba7aa094fa6ed76bb1e366d8ddcf5c65888ab1024",{"version":"bddce945d552a963c9733db106b17a25474eefcab7fc990157a2134ef55d4954","affectsGlobalScope":true},{"version":"7052b7b0c3829df3b4985bab2fd74531074b4835d5a7b263b75c82f0916ad62f","affectsGlobalScope":true},"aa34c3aa493d1c699601027c441b9664547c3024f9dbab1639df7701d63d18fa","4b55240c2a03b2c71e98a7fc528b16136faa762211c92e781a01c37821915ea6","7c651f8dce91a927ab62925e73f190763574c46098f2b11fb8ddc1b147a6709a","7440ab60f4cb031812940cc38166b8bb6fbf2540cfe599f87c41c08011f0c1df",{"version":"94c086dff8dbc5998749326bc69b520e8e4273fb5b7b58b50e0210e0885dfcde","affectsGlobalScope":true},{"version":"f5b5dc128973498b75f52b1b8c2d5f8629869104899733ae485100c2309b4c12","affectsGlobalScope":true},"ebe5facd12fd7745cda5f4bc3319f91fb29dc1f96e57e9c6f8b260a7cc5b67ee","79bad8541d5779c85e82a9fb119c1fe06af77a71cc40f869d62ad379473d4b75","37dc027f781c75f0f546e329cfac7cf92a6b289f42458f47a9adc25e516b6839",{"version":"629d20681ca284d9e38c0a019f647108f5fe02f9c59ac164d56f5694fc3faf4d","affectsGlobalScope":true},"e7dbf5716d76846c7522e910896c5747b6df1abd538fee8f5291bdc843461795",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"b510d0a18e3db42ac9765d26711083ec1e8b4e21caaca6dc4d25ae6e8623f447"],"root":[[49,60]],"options":{"allowJs":true,"allowSyntheticDefaultImports":true,"declaration":true,"esModuleInterop":true,"experimentalDecorators":true,"module":1,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","skipLibCheck":true,"strict":true,"target":1},"fileIdsList":[[61],[96],[97,102,130],[98,109,110,117,127,138],[98,99,109,117],[100,139],[101,102,110,118],[102,127,135],[103,105,109,117],[96,104],[105,106],[109],[107,109],[96,109],[109,110,111,127,138],[109,110,111,124,127,130],[94,97,143],[105,109,112,117,127,138],[109,110,112,113,117,127,135,138],[112,114,127,135,138],[61,62,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145],[109,115],[116,138,143],[105,109,117,127],[118],[119],[96,120],[121,137,143],[122],[123],[109,124,125],[124,126,139,141],[97,109,127,128,129,130],[97,127,129],[127,128],[130],[131],[96,127],[109,133,134],[133,134],[102,117,127,135],[136],[117,137],[97,112,123,138],[102,139],[127,140],[116,141],[142],[97,102,109,111,120,127,138,141,143],[127,144],[71,75,138],[71,127,138],[66],[68,71,135,138],[117,135],[146],[66,146],[68,71,117,138],[63,64,67,70,97,109,127,138],[63,69],[67,71,97,130,138,146],[97,146],[87,97,146],[65,66,146],[71],[65,66,67,68,69,70,71,72,73,75,76,77,78,79,80,81,82,83,84,85,86,88,89,90,91,92,93],[71,78,79],[69,71,79,80],[70],[63,66,71],[71,75,79,80],[75],[69,71,74,138],[63,68,69,71,75,78],[97,127],[66,71,87,97,143,146],[51,52],[50],[49,50],[49,50,51,52,53,54,55,56,57,58,59],[50,51]],"referencedMap":[[61,1],[62,1],[96,2],[97,3],[98,4],[99,5],[100,6],[101,7],[102,8],[103,9],[104,10],[105,11],[106,11],[108,12],[107,13],[109,14],[110,15],[111,16],[95,17],[112,18],[113,19],[114,20],[146,21],[115,22],[116,23],[117,24],[118,25],[119,26],[120,27],[121,28],[122,29],[123,30],[124,31],[125,31],[126,32],[127,33],[129,34],[128,35],[130,36],[131,37],[132,38],[133,39],[134,40],[135,41],[136,42],[137,43],[138,44],[139,45],[140,46],[141,47],[142,48],[143,49],[144,50],[78,51],[85,52],[77,51],[92,53],[69,54],[68,55],[91,56],[86,57],[89,58],[71,59],[70,60],[66,61],[65,62],[88,63],[67,64],[72,65],[76,65],[94,66],[93,65],[80,67],[81,68],[83,69],[79,70],[82,71],[87,56],[74,72],[75,73],[84,74],[64,75],[90,76],[53,77],[56,78],[51,79],[60,80],[58,81]],"exportedModulesMap":[[61,1],[62,1],[96,2],[97,3],[98,4],[99,5],[100,6],[101,7],[102,8],[103,9],[104,10],[105,11],[106,11],[108,12],[107,13],[109,14],[110,15],[111,16],[95,17],[112,18],[113,19],[114,20],[146,21],[115,22],[116,23],[117,24],[118,25],[119,26],[120,27],[121,28],[122,29],[123,30],[124,31],[125,31],[126,32],[127,33],[129,34],[128,35],[130,36],[131,37],[132,38],[133,39],[134,40],[135,41],[136,42],[137,43],[138,44],[139,45],[140,46],[141,47],[142,48],[143,49],[144,50],[78,51],[85,52],[77,51],[92,53],[69,54],[68,55],[91,56],[86,57],[89,58],[71,59],[70,60],[66,61],[65,62],[88,63],[67,64],[72,65],[76,65],[94,66],[93,65],[80,67],[81,68],[83,69],[79,70],[82,71],[87,56],[74,72],[75,73],[84,74],[64,75],[90,76],[56,78],[51,78],[60,80],[58,78]],"semanticDiagnosticsPerFile":[61,62,96,97,98,99,100,101,102,103,104,105,106,108,107,109,110,111,95,145,112,113,114,146,115,116,117,118,119,120,121,122,123,124,125,126,127,129,128,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,1,47,48,9,13,12,3,14,15,16,17,18,19,20,21,4,5,22,26,23,24,25,27,28,29,6,30,31,32,33,7,37,34,35,36,38,8,39,44,45,40,41,42,43,2,46,11,10,78,85,77,92,69,68,91,86,89,71,70,66,65,88,67,72,73,76,63,94,93,80,81,83,79,82,87,74,75,84,64,90,53,49,54,55,56,51,60,52,57,58,59,50]},"version":"5.3.3"}
package/lib/types.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export interface Vector2 {
2
+ x: number;
3
+ y: number;
4
+ }
5
+ export interface Vector3 extends Vector2 {
6
+ z: number;
7
+ }
8
+ export interface Vector4 extends Vector3 {
9
+ w: number;
10
+ }
11
+ export interface Deferred<T> {
12
+ promise: Promise<T>;
13
+ resolve: (value: T | PromiseLike<T>) => void;
14
+ reject: (reason?: unknown) => void;
15
+ }
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "toosoon-utils",
3
+ "version": "1.0.0",
4
+ "description": "Utility functions",
5
+ "main": "./lib/index.js",
6
+ "scripts": {
7
+ "build": "npx tsc",
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/toosoon-dev/toosoon-utils.git"
13
+ },
14
+ "keywords": [
15
+ "tooson",
16
+ "utils",
17
+ "colors",
18
+ "dom",
19
+ "files",
20
+ "functions",
21
+ "geometry",
22
+ "maths",
23
+ "now",
24
+ "random",
25
+ "strings"
26
+ ],
27
+ "author": "Arnaud Rocca",
28
+ "license": "MIT",
29
+ "bugs": {
30
+ "url": "https://github.com/toosoon-dev/toosoon-utils/issues"
31
+ },
32
+ "homepage": "https://github.com/toosoon-dev/toosoon-utils#readme",
33
+ "devDependencies": {
34
+ "@types/node": "^20.11.19",
35
+ "typescript": "^5.3.3"
36
+ }
37
+ }
package/src/colors.ts ADDED
@@ -0,0 +1,376 @@
1
+ import { toDegrees, toRadians } from './geometry';
2
+ import { clamp } from './maths';
3
+
4
+ // ******************************************
5
+ // RGB & Hexadecimal color spaces
6
+ // ******************************************
7
+
8
+ /**
9
+ * Normalize hexadecimal string
10
+ *
11
+ * @param {string} hex Hexadecimal string
12
+ * @returns {string} Normalized hexadecimal string
13
+ */
14
+ export function normalizeHexString(hex: string): string {
15
+ let match: RegExpMatchArray | null;
16
+ let result: string = '000000';
17
+ hex = hex.toLocaleLowerCase();
18
+
19
+ if ((match = hex.match(/(#|0x)?([a-f0-9]{6})/i))) {
20
+ result = match[2];
21
+ } else if ((match = hex.match(/^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i))) {
22
+ result = match[1] + match[1] + match[2] + match[2] + match[3] + match[3];
23
+ } else if ((match = hex.match(/rgb\(\s*(\d*)\s*,\s*(\d*)\s*,\s*(\d*)\s*\)/))) {
24
+ result =
25
+ parseInt(match[1]).toString(16).padStart(2, '0') +
26
+ parseInt(match[2]).toString(16).padStart(2, '0') +
27
+ parseInt(match[3]).toString(16).padStart(2, '0');
28
+ }
29
+
30
+ return `#${result}`;
31
+ }
32
+
33
+ /**
34
+ * Convert RGB color to hexadecimal
35
+ * Note: rgb values are contained in the interval [0, 1]
36
+ *
37
+ * @param {[number, number, number]} rgb RGB color
38
+ * @returns {number} Hexadecimal color
39
+ */
40
+ export function rgbToHex([r, g, b]: [number, number, number]): number {
41
+ return ((r * 255) << 16) ^ ((g * 255) << 8) ^ ((b * 255) << 0);
42
+ }
43
+
44
+ /**
45
+ * Convert RGB color to hexadecimal string
46
+ * Note: rgb values are contained in the interval [0, 1]
47
+ *
48
+ * @param {[number, number, number]} rgb RGB color
49
+ * @returns {string} Hexadecimal string
50
+ */
51
+ export function rgbToHexString([r, g, b]: [number, number, number]): string {
52
+ const red = clamp(Math.round(r * 255), 0, 255);
53
+ const green = clamp(Math.round(g * 255), 0, 255);
54
+ const blue = clamp(Math.round(b * 255), 0, 255);
55
+
56
+ const result = (blue | (green << 8) | (red << 16) | (1 << 24)).toString(16).slice(1);
57
+ return `#${result}`;
58
+ }
59
+
60
+ /**
61
+ * Convert hexadecimal color to RGB
62
+ * Note: rgb values are contained in the interval [0, 1]
63
+ *
64
+ * @param {(number|string)} hex Hexadecimal color
65
+ * @returns {[number, number, number]} RGB color
66
+ */
67
+ export function hexToRgb(hex: number | string): [number, number, number] {
68
+ if (typeof hex === 'number') {
69
+ hex = Math.floor(hex);
70
+ } else if (typeof hex === 'string') {
71
+ hex = normalizeHexString(hex).replace(/^#/, '');
72
+ hex = parseInt(hex, 16);
73
+ }
74
+
75
+ const red = ((hex >> 16) & 255) / 255;
76
+ const green = ((hex >> 8) & 255) / 255;
77
+ const blue = (hex & 255) / 255;
78
+
79
+ return [red, green, blue];
80
+ }
81
+
82
+ /**
83
+ * Lighten a color
84
+ *
85
+ * @param {string} hex Hexadecimal string
86
+ * @param {number} [amount=0] Amount of the color offset
87
+ * @returns {string} Computed hexadecimal
88
+ */
89
+ export function lighten(hex: string, amount: number = 0): string {
90
+ let prefix = '';
91
+
92
+ if (hex[0] === '#') {
93
+ hex = hex.slice(1);
94
+ prefix = '#';
95
+ }
96
+
97
+ const value = parseInt(hex, 16);
98
+
99
+ let r = (value >> 16) + amount;
100
+ r = clamp(r, 0, 255);
101
+
102
+ let b = ((value >> 8) & 0x00ff) + amount;
103
+ b = clamp(b, 0, 255);
104
+
105
+ let g = (value & 0x0000ff) + amount;
106
+ g = clamp(g, 0, 255);
107
+
108
+ let result: number | string = g | (b << 8) | (r << 16);
109
+ if (r === 0 && g === 0 && b === 0 && amount !== 0) {
110
+ result = '000000';
111
+ }
112
+
113
+ return prefix + result.toString(16);
114
+ }
115
+
116
+ /**
117
+ * Darken a color
118
+ *
119
+ * @param {string} hex Hexadecimal string
120
+ * @param {number} [amount=0] Amount of the color offset
121
+ * @returns {string} Computed hexadecimal
122
+ */
123
+ export function darken(hex: string, amount: number = 0): string {
124
+ return lighten(hex, -amount);
125
+ }
126
+
127
+ // ***************************************************
128
+ // RGB & Hue-Saturation-Lightness (HSL) color spaces
129
+ // ***************************************************
130
+
131
+ /**
132
+ * Normalize HSL string
133
+ * Note: hsl values are contained in the intervals H: [0, 360], S: [0, 1], L: [0, 1]
134
+ *
135
+ * @param {string} hsl HSL string (format: 'hsl(360, 100%, 100%)')
136
+ * @returns {[number, number, number]} Normalized HSL color
137
+ */
138
+ export function normalizeHslString(hsl: string): [number, number, number] {
139
+ const [hue, saturation, lightness] = hsl.match(/\d+/g)?.map(Number) ?? [0, 0, 0];
140
+ return [hue, saturation / 100, lightness / 100];
141
+ }
142
+
143
+ /**
144
+ * Convert RGB color to HSL color
145
+ * Notes:
146
+ * - rgb values are contained in the interval [0, 1]
147
+ * - hsl values are contained in the intervals H: [0, 360], S: [0, 1], L: [0, 1]
148
+ *
149
+ * @param {[number, number, number]} rgb RGB color
150
+ * @returns {[number, number, number]} HSL color
151
+ */
152
+ export function rgbToHsl([r, g, b]: [number, number, number]): [number, number, number] {
153
+ const l = Math.max(r, g, b);
154
+ const s = l - Math.min(r, g, b);
155
+ const h = s ? (l === r ? (g - b) / s : l === g ? 2 + (b - r) / s : 4 + (r - g) / s) : 0;
156
+
157
+ return [
158
+ 60 * h < 0 ? 60 * h + 360 : 60 * h,
159
+ s ? (l <= 0.5 ? s / (2 * l - s) : s / (2 - (2 * l - s))) : 0,
160
+ (2 * l - s) / 2
161
+ ];
162
+ }
163
+
164
+ /**
165
+ * Convert HSL color to RGB color
166
+ * Notes:
167
+ * - rgb values are contained in the interval [0, 1]
168
+ * - hsl values are contained in the intervals H: [0, 360], S: [0, 1], L: [0, 1]
169
+ *
170
+ * @param {[number, number, number]} hsl HSL color
171
+ * @returns {[number, number, number]} RGB color
172
+ */
173
+ export function hslToRgb([h, s, l]: [number, number, number]): [number, number, number] {
174
+ const a = s * Math.min(l, 1 - l);
175
+ const k = (v: number) => (v + h / 30) % 12;
176
+ const f = (v: number) => l - a * Math.max(-1, Math.min(k(v) - 3, Math.min(9 - k(v), 1)));
177
+ return [f(0), f(8), f(4)];
178
+ }
179
+
180
+ // ***************************************************
181
+ // RGB & Hue-Saturation-Brightness (HSB) color spaces
182
+ // ***************************************************
183
+
184
+ /**
185
+ * Convert RGB color to HSB color
186
+ * Notes:
187
+ * - rgb values are contained in the interval [0, 1]
188
+ * - hsb values are contained in the intervals H: [0, 360], S: [0, 1], B: [0, 1]
189
+ *
190
+ * @param {[number, number, number]} rgb RGB color
191
+ * @returns {[number, number, number]} HSB color
192
+ */
193
+ export function rgbToHsb([r, g, b]: [number, number, number]): [number, number, number] {
194
+ const max = Math.max(r, g, b);
195
+ const min = Math.min(r, g, b);
196
+ const delta = max - min;
197
+ const h =
198
+ delta === 0 ? 0 : delta && max === r ? (g - b) / delta : max === g ? 2 + (b - r) / delta : 4 + (r - g) / delta;
199
+ return [60 * (h < 0 ? h + 6 : h), max && delta / max, max];
200
+ }
201
+
202
+ /**
203
+ * Convert HSB color to RGB color
204
+ * Notes:
205
+ * - rgb values are contained in the interval [0, 1]
206
+ * - hsb values are contained in the intervals H: [0, 360], S: [0, 1], B: [0, 1]
207
+ *
208
+ * @param {[number, number, number]} hsb HSB color
209
+ * @returns {[number, number, number]} RGB color
210
+ */
211
+ export function hsbToRgb([h, s, b]: [number, number, number]): [number, number, number] {
212
+ const k = (v: number) => (v + h / 60) % 6;
213
+ const f = (v: number) => b * (1 - s * Math.max(0, Math.min(k(v), 4 - k(v), 1)));
214
+ return [f(5), f(3), f(1)];
215
+ }
216
+
217
+ // *********************************************
218
+ // LAB & Hue-Chroma-Luminance (HCL) color spaces
219
+ // *********************************************
220
+
221
+ /**
222
+ * Convert LAB color space to HCL color
223
+ * -> http://www.brucelindbloom.com/index.html?Eqn_Lab_to_LCH.html
224
+ *
225
+ * @param {[number, number, number]} lab LAB color
226
+ * @returns {[number, number, number]} HCL color
227
+ */
228
+ export function labToHcl([l, a, b]: [number, number, number]): [number, number, number] {
229
+ const c = Math.sqrt(a * a + b * b);
230
+ const h = abToHue(a, b);
231
+ return [h, c, l];
232
+ }
233
+
234
+ /**
235
+ * Convert HCL color space color space to LAB color
236
+ * -> http://www.brucelindbloom.com/index.html?Eqn_LCH_to_Lab.html
237
+ *
238
+ * @param {[number, number, number]} hcl HCL color
239
+ * @returns {[number, number, number]} LAB color space
240
+ */
241
+ export function hclToLab([h, c, l]: [number, number, number]): [number, number, number] {
242
+ const a = c * Math.cos(toRadians(h));
243
+ const b = c * Math.sin(toRadians(h));
244
+ return [l, a, b];
245
+ }
246
+
247
+ /**
248
+ * Convert A and B of LAB color to Hue of LCH color
249
+ * -> https://stackoverflow.com/questions/53733379/conversion-of-cielab-to-cielchab-not-yielding-correct-result
250
+ *
251
+ * @param {number} a A value of LAB color
252
+ * @param {number} b B value of LAB color
253
+ * @returns {number} Hue value
254
+ */
255
+ function abToHue(a: number, b: number): number {
256
+ if (a >= 0 && b === 0) {
257
+ return 0;
258
+ }
259
+ if (a < 0 && b === 0) {
260
+ return 180;
261
+ }
262
+ if (a === 0 && b > 0) {
263
+ return 90;
264
+ }
265
+ if (a === 0 && b < 0) {
266
+ return 270;
267
+ }
268
+
269
+ let xBias = 0;
270
+ if (a > 0 && b > 0) {
271
+ xBias = 0;
272
+ } else if (a < 0) {
273
+ xBias = 180;
274
+ } else if (a > 0 && b < 0) {
275
+ xBias = 360;
276
+ }
277
+
278
+ return toDegrees(Math.atan(b / a)) + xBias;
279
+ }
280
+
281
+ // ******************************************
282
+ // LAB & RGB color spaces
283
+ // ******************************************
284
+ const f1 = (v: number) => (v * v * v > 0.008856 ? v * v * v : (v - 16 / 116) / 7.787);
285
+ const f2 = (v: number) => (v > 0.0031308 ? 1.055 * Math.pow(v, 1 / 2.4) - 0.055 : 12.92 * v);
286
+ const f3 = (v: number) => (v > 0.04045 ? Math.pow((v + 0.055) / 1.055, 2.4) : v / 12.92);
287
+ const f4 = (v: number) => (v > 0.008856 ? Math.pow(v, 1 / 3) : 7.787 * v + 16 / 116);
288
+
289
+ /**
290
+ * Converts LAB color to RGB
291
+ *
292
+ * @param {[number, number, number]} lab LAB color
293
+ * @returns {[number, number, number]} RGB color
294
+ */
295
+ export function labToRgb([l, a, b]: [number, number, number]): [number, number, number] {
296
+ let y = (l + 16) / 116;
297
+ let x = a / 500 + y;
298
+ let z = y - b / 200;
299
+
300
+ x = 0.95047 * f1(x);
301
+ y = 1.0 * f1(y);
302
+ z = 1.08883 * f1(z);
303
+
304
+ return [
305
+ clamp(f2(x * 3.2406 + y * -1.5372 + z * -0.4986)),
306
+ clamp(f2(x * -0.9689 + y * 1.8758 + z * 0.0415)),
307
+ clamp(f2(x * 0.0557 + y * -0.204 + z * 1.057))
308
+ ];
309
+ }
310
+
311
+ /**
312
+ * Converts RGB color to Lab color
313
+ *
314
+ * @param {[number, number, number]} rgb RGB color
315
+ * @returns {[number, number, number]} LAB color
316
+ */
317
+ export function rgbToLab([r, g, b]: [number, number, number]): [number, number, number] {
318
+ r = f3(r);
319
+ g = f3(g);
320
+ b = f3(b);
321
+
322
+ let x = f4((r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047);
323
+ let y = f4((r * 0.2126 + g * 0.7152 + b * 0.0722) / 1);
324
+ let z = f4((r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883);
325
+
326
+ return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
327
+ }
328
+
329
+ /**
330
+ * Get the delta from two LAB colors
331
+ *
332
+ * @param {[number, number, number]} labA First LAB color
333
+ * @param {[number, number, number]} labB Second LAB color
334
+ * @returns {number} Delta
335
+ */
336
+ export function deltaE(labA: [number, number, number], labB: [number, number, number]): number {
337
+ const deltaL = labA[0] - labB[0];
338
+ const deltaA = labA[1] - labB[1];
339
+ const deltaB = labA[2] - labB[2];
340
+ const c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);
341
+ const c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);
342
+ const deltaC = c1 - c2;
343
+ let deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;
344
+ deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
345
+ const sc = 1.0 + 0.045 * c1;
346
+ const sh = 1.0 + 0.015 * c1;
347
+ const deltaLKlsl = deltaL / 1;
348
+ const deltaCkcsc = deltaC / sc;
349
+ const deltaHkhsh = deltaH / sh;
350
+ const i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;
351
+ return i < 0 ? 0 : Math.sqrt(i);
352
+ }
353
+
354
+ // *********************************************
355
+ // RGB & Hue-Chroma-Luminance (HCL) color spaces
356
+ // *********************************************
357
+
358
+ /**
359
+ * Converts RGB color to HCL color
360
+ *
361
+ * @param {[number, number, number]} rgb RGB color
362
+ * @returns {[number, number, number]} HCL color
363
+ */
364
+ export function rgbToHcl([r, g, b]: [number, number, number]): [number, number, number] {
365
+ return labToHcl(rgbToLab([r, g, b]));
366
+ }
367
+
368
+ /**
369
+ * Converts HCL color to RGB color
370
+ *
371
+ * @param {[number, number, number]} hcl RGB color
372
+ * @returns {[number, number, number]} RGB color
373
+ */
374
+ export function hclToRgb([h, c, l]: [number, number, number]): [number, number, number] {
375
+ return labToRgb(hclToLab([h, c, l]));
376
+ }