mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-18 03:26:57 +02:00
polish(theme-classic): guard against potential definition mistakes in Tabs (#5674)
This commit is contained in:
parent
8d92e9bcf5
commit
c8739ec28e
10 changed files with 224 additions and 23 deletions
23
packages/docusaurus-theme-common/src/utils/jsUtils.ts
Normal file
23
packages/docusaurus-theme-common/src/utils/jsUtils.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// A replacement of lodash in client code
|
||||
|
||||
/**
|
||||
* Gets the duplicate values in an array.
|
||||
* @param arr The array.
|
||||
* @param comparator Compares two values and returns `true` if they are equal (duplicated).
|
||||
* @returns Value of the elements `v` that have a preceding element `u` where `comparator(u, v) === true`. Values within the returned array are not guaranteed to be unique.
|
||||
*/
|
||||
export function duplicates<T>(
|
||||
arr: readonly T[],
|
||||
comparator: (a: T, b: T) => boolean = (a, b) => a === b,
|
||||
): T[] {
|
||||
return arr.filter(
|
||||
(v, vIndex) => arr.findIndex((u) => comparator(u, v)) !== vIndex,
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue