UNPKG

static-injector

Version:

Angular 依赖注入独立版本;Angular dependency injection standalone version

133 lines (132 loc) 5.48 kB
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ /** * Determines if the contents of two arrays is identical * * @param a first array * @param b second array * @param identityAccessor Optional function for extracting stable object identity from a value in * the array. */ export declare function arrayEquals<T>(a: T[], b: T[], identityAccessor?: (value: T) => unknown): boolean; /** * Flattens an array. */ export declare function flatten(list: any[]): any[]; export declare function deepForEach<T>(input: (T | any[])[], fn: (value: T) => void): void; export declare function addToArray(arr: any[], index: number, value: any): void; export declare function removeFromArray(arr: any[], index: number): any; export declare function newArray<T = any>(size: number): T[]; export declare function newArray<T>(size: number, value: T): T[]; /** * Remove item from array (Same as `Array.splice()` but faster.) * * `Array.splice()` is not as fast because it has to allocate an array for the elements which were * removed. This causes memory pressure and slows down code when most of the time we don't * care about the deleted items array. * * https://jsperf.com/fast-array-splice (About 20x faster) * * @param array Array to splice * @param index Index of element in array to remove. * @param count Number of items to remove. */ export declare function arraySplice(array: any[], index: number, count: number): void; /** * Same as `Array.splice(index, 0, value)` but faster. * * `Array.splice()` is not fast because it has to allocate an array for the elements which were * removed. This causes memory pressure and slows down code when most of the time we don't * care about the deleted items array. * * @param array Array to splice. * @param index Index in array where the `value` should be added. * @param value Value to add to array. */ export declare function arrayInsert(array: any[], index: number, value: any): void; /** * Same as `Array.splice2(index, 0, value1, value2)` but faster. * * `Array.splice()` is not fast because it has to allocate an array for the elements which were * removed. This causes memory pressure and slows down code when most of the time we don't * care about the deleted items array. * * @param array Array to splice. * @param index Index in array where the `value` should be added. * @param value1 Value to add to array. * @param value2 Value to add to array. */ export declare function arrayInsert2(array: any[], index: number, value1: any, value2: any): void; /** * Get an index of an `value` in a sorted `array`. * * NOTE: * - This uses binary search algorithm for fast removals. * * @param array A sorted array to binary search. * @param value The value to look for. * @returns index of the value. * - positive index if value found. * - negative index if value not found. (`~index` to get the value where it should have been * located) */ export declare function arrayIndexOfSorted(array: string[], value: string): number; /** * `KeyValueArray` is an array where even positions contain keys and odd positions contain values. * * `KeyValueArray` provides a very efficient way of iterating over its contents. For small * sets (~10) the cost of binary searching an `KeyValueArray` has about the same performance * characteristics that of a `Map` with significantly better memory footprint. * * If used as a `Map` the keys are stored in alphabetical order so that they can be binary searched * for retrieval. * * See: `keyValueArraySet`, `keyValueArrayGet`, `keyValueArrayIndexOf`, `keyValueArrayDelete`. */ export interface KeyValueArray<VALUE> extends Array<VALUE | string> { __brand__: 'array-map'; } /** * Set a `value` for a `key`. * * @param keyValueArray to modify. * @param key The key to locate or create. * @param value The value to set for a `key`. * @returns index (always even) of where the value vas set. */ export declare function keyValueArraySet<V>(keyValueArray: KeyValueArray<V>, key: string, value: V): number; /** * Retrieve a `value` for a `key` (on `undefined` if not found.) * * @param keyValueArray to search. * @param key The key to locate. * @return The `value` stored at the `key` location or `undefined if not found. */ export declare function keyValueArrayGet<V>(keyValueArray: KeyValueArray<V>, key: string): V | undefined; /** * Retrieve a `key` index value in the array or `-1` if not found. * * @param keyValueArray to search. * @param key The key to locate. * @returns index of where the key is (or should have been.) * - positive (even) index if key found. * - negative index if key not found. (`~index` (even) to get the index where it should have * been inserted.) */ export declare function keyValueArrayIndexOf<V>(keyValueArray: KeyValueArray<V>, key: string): number; /** * Delete a `key` (and `value`) from the `KeyValueArray`. * * @param keyValueArray to modify. * @param key The key to locate or delete (if exist). * @returns index of where the key was (or should have been.) * - positive (even) index if key found and deleted. * - negative index if key not found. (`~index` (even) to get the index where it should have * been.) */ export declare function keyValueArrayDelete<V>(keyValueArray: KeyValueArray<V>, key: string): number;