Skip to content

Commit

Permalink
feat(uip-utils): add jsdoc utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Sisha0 committed Jul 16, 2021
1 parent 4dfb265 commit 7692fc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/utils/token-list/token-list-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** Class for processing attribute's tokens. */
export default class TokenListUtils {
static split(attrValue: string | null): string[] {
return attrValue?.split(/\s+/) || [];
Expand All @@ -7,26 +8,31 @@ export default class TokenListUtils {
return values.join(' ');
}

/** Checking if all array elements are equal. */
static hasSameElements(values: any[]): boolean {
return values.every(val => val === values[0]);
}

/** Checking whether two arrays have same elements or not. */
static equals<T>(arr1: T[], arr2: T[]): boolean {
return TokenListUtils.contains(arr1, arr2) && TokenListUtils.contains(arr2, arr1);
}

/** Checking if array contains all elements from subArray. */
static contains<T>(array: T[], subArray: T[]): boolean {
const set = new Set(array);
return subArray.every(val => set.has(val));
}

/** Getting array which contains only common elements from arrays. */
static intersection<T>(...arrays: T[][]): T[] {
return Array.from(arrays.reduce((intersect, arr) => {
arr.forEach(val => !intersect.has(val) && intersect.delete(val));
return intersect;
}, new Set(arrays[0]))) as T[];
}

/** Removing all element appearances from array. */
static remove<T>(array: T[], element: T): T[] {
return array.filter(el => el !== element);
}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/warn-messages/warn.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/** Object with messages used for indicating
* [setting's]{@link UIPSetting} inconsistent state
*/
export const WARN = {
inconsistent: 'Inconsistent value',
multiple: 'Multiple values',
Expand Down

0 comments on commit 7692fc8

Please # to comment.