@mll-lab/js-utils 2.36.0 → 2.36.1

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.
@@ -16164,6 +16164,40 @@ function joinNonEmpty(maybeStrings, separator) {
16164
16164
  return maybeStrings.filter(Boolean).join(separator);
16165
16165
  }
16166
16166
 
16167
+ function hashCode(string) {
16168
+ let hash = 0;
16169
+ // eslint-disable-next-line no-plusplus
16170
+ for (let i = 0; i < string.length; i++) {
16171
+ // eslint-disable-next-line no-bitwise
16172
+ hash = string.charCodeAt(i) + ((hash << 5) - hash);
16173
+ }
16174
+ return hash;
16175
+ }
16176
+ function getHslColor(hash) {
16177
+ const h = range(hash, 0, 360);
16178
+ const s = range(hash, 50, 100);
16179
+ const l = range(hash, 20, 50);
16180
+ return `hsla(${h}, ${s}%, ${l}%, 1)`;
16181
+ }
16182
+ function range(hash, min, max) {
16183
+ const diff = max - min;
16184
+ const x = ((hash % diff) + diff) % diff;
16185
+ return x + min;
16186
+ }
16187
+ function stringToHslaColor(string) {
16188
+ return getHslColor(hashCode(string));
16189
+ }
16190
+ /**
16191
+ * Generates a random string with a length of 1-11 chars.
16192
+ */
16193
+ function randomString() {
16194
+ // Cut off the constant 0. from the beginning
16195
+ const fractionStart = 2;
16196
+ // Unequal distribution at the edges, but sufficiently random for the purposes of this function
16197
+ const randomLengthEnd = Math.round(Math.random() * 11) + 3;
16198
+ return Math.random().toString(36).substring(fractionStart, randomLengthEnd);
16199
+ }
16200
+
16167
16201
  /**
16168
16202
  * Converts pixel value to number.
16169
16203
  *
@@ -16258,9 +16292,11 @@ exports.parseSecondlessDateTime = parseSecondlessDateTime;
16258
16292
  exports.pick = pick;
16259
16293
  exports.pluralize = pluralize;
16260
16294
  exports.pxToNumber = pxToNumber;
16295
+ exports.randomString = randomString;
16261
16296
  exports.round = round;
16262
16297
  exports.soleItem = soleItem;
16263
16298
  exports.sortByArray = sortByArray;
16299
+ exports.stringToHslaColor = stringToHslaColor;
16264
16300
  exports.toggleElement = toggleElement;
16265
16301
  exports.withoutIndex = withoutIndex;
16266
16302
  //# sourceMappingURL=index.common.js.map