Vendor Cordis framework packages as source
cordis 4.0.0-rc.6, plugin-loader, -include, -group, -timer, -hmr, -logger-console, cosmokit 1.8.1, schemastery 3.18.0 — copied from the cordis-workspace checkout, flattened under vendor/, original npm names, private: true. vendor/README.md is the manifest: upstream repos + commit SHAs, local-modification log, sync procedure. Local modification: hmr's locale YAML imports and .i18n() call removed (avoids a runtime YAML import hook we don't vendor).
This commit is contained in:
42
vendor/cosmokit/src/array.ts
vendored
Normal file
42
vendor/cosmokit/src/array.ts
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import { isNullable } from './misc'
|
||||
|
||||
/** Return true when every item in `array2` is present in `array1`. */
|
||||
export function contain(array1: readonly any[], array2: readonly any[]) {
|
||||
return array2.every(item => array1.includes(item))
|
||||
}
|
||||
|
||||
/** Return items that appear in both arrays. */
|
||||
export function intersection<T>(array1: readonly T[], array2: readonly T[]) {
|
||||
return array1.filter(item => array2.includes(item))
|
||||
}
|
||||
|
||||
/** Return items from `array1` that do not appear in `array2`. */
|
||||
export function difference<S>(array1: readonly S[], array2: readonly any[]) {
|
||||
return array1.filter(item => !array2.includes(item))
|
||||
}
|
||||
|
||||
/** Return the set-union of two arrays while preserving first occurrence order. */
|
||||
export function union<T>(array1: readonly T[], array2: readonly T[]) {
|
||||
return Array.from(new Set([...array1, ...array2]))
|
||||
}
|
||||
|
||||
/** Remove duplicate values while preserving first occurrence order. */
|
||||
export function deduplicate<T>(array: readonly T[]) {
|
||||
return [...new Set(array)]
|
||||
}
|
||||
|
||||
/** Remove one item from an array and report whether it was found. */
|
||||
export function remove<T>(list: T[], item: T) {
|
||||
const index = list?.indexOf(item)
|
||||
if (index >= 0) {
|
||||
list.splice(index, 1)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** Normalize nullish, scalar, or array input to an array. */
|
||||
export function makeArray<T>(source: null | undefined | T | T[]) {
|
||||
return Array.isArray(source) ? source : isNullable(source) ? [] : [source]
|
||||
}
|
||||
Reference in New Issue
Block a user