@glimmer/util
- Version 0.93.1
- Published
- 61.9 kB
- 2 dependencies
- MIT license
Install
npm i @glimmer/util
yarn add @glimmer/util
pnpm add @glimmer/util
Overview
Common utilities used in Glimmer
Index
Variables
Functions
Classes
Type Aliases
Variables
variable assign
let assign: { <T extends {}, U>(target: T, source: U): T & U; <T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V; <T_2 extends {}, U_2, V_1, W>( target: T_2, source1: U_2, source2: V_1, source3: W ): T_2 & U_2 & V_1 & W; (target: object, ...sources: any[]): any;};
variable beginTestSteps
let beginTestSteps: () => void;
variable EMPTY_ARRAY
const EMPTY_ARRAY: readonly unknown[];
variable EMPTY_NUMBER_ARRAY
const EMPTY_NUMBER_ARRAY: number[];
variable EMPTY_STRING_ARRAY
const EMPTY_STRING_ARRAY: string[];
variable endTestSteps
let endTestSteps: () => void;
variable LOCAL_LOGGER
const LOCAL_LOGGER: Console;
This constant exists to make it easier to differentiate normal logs from errant console.logs. LOCAL_LOGGER should only be used inside a LOCAL_TRACE_LOGGING check.
It does not alleviate the need to check LOCAL_TRACE_LOGGING, which is used for stripping.
variable LOGGER
const LOGGER: Console;
This constant exists to make it easier to differentiate normal logs from errant console.logs. LOGGER can be used outside of LOCAL_TRACE_LOGGING checks, and is meant to be used in the rare situation where a console.* call is actually appropriate.
variable logStep
let logStep: (type: string, steps: unknown) => void;
variable SERIALIZATION_FIRST_NODE_STRING
const SERIALIZATION_FIRST_NODE_STRING: string;
variable verifySteps
let verifySteps: ( type: string, steps: unknown[] | ((steps: unknown[]) => void), message?: string) => void;
Functions
function assertNever
assertNever: (value: never, desc?: string) => never;
function clearElement
clearElement: (parent: SimpleElement) => void;
function dict
dict: <T = unknown>() => Dict<T>;
function emptyArray
emptyArray: <T>() => T[];
function entries
entries: <D extends object>(dict: D) => ObjectEntry<D>[];
function enumerate
enumerate: <T>(input: Iterable<T>) => IterableIterator<[number, T]>;
function intern
intern: (str: string) => string;
Strongly hint runtimes to intern the provided string.
When do I need to use this function?
For the most part, never. Pre-mature optimization is bad, and often the runtime does exactly what you need it to, and more often the trade-off isn't worth it.
Why?
Runtimes store strings in at least 2 different representations: Ropes and Symbols (interned strings). The Rope provides a memory efficient data-structure for strings created from concatenation or some other string manipulation like splitting.
Unfortunately checking equality of different ropes can be quite costly as runtimes must resort to clever string comparison algorithms. These algorithms typically cost in proportion to the length of the string. Luckily, this is where the Symbols (interned strings) shine. As Symbols are unique by their string content, equality checks can be done by pointer comparison.
How do I know if my string is a rope or symbol?
Typically (warning general sweeping statement, but truthy in runtimes at present) static strings created as part of the JS source are interned. Strings often used for comparisons can be interned at runtime if some criteria are met. One of these criteria can be the size of the entire rope. For example, in chrome 38 a rope longer then 12 characters will not intern, nor will segments of that rope.
Some numbers: http://jsperf.com/eval-vs-keys/8
Known Trick™
{String} interned version of the provided string
function isDict
isDict: <T>(u: T) => u is any;
function isEmptyArray
isEmptyArray: (input: unknown[] | readonly unknown[]) => boolean;
This function returns
true
if the input array is the special empty array sentinel, which is sometimes used for optimizations.
function isIndexable
isIndexable: <T>(u: T) => u is object & T;
function isSerializationFirstNode
isSerializationFirstNode: (node: SimpleNode) => boolean;
function keys
keys: <T extends object>(obj: T) => (keyof T)[];
function reverse
reverse: <T>(input: T[]) => IterableIterator<T>;
function strip
strip: (strings: TemplateStringsArray, ...args: unknown[]) => string;
function values
values: <T>(obj: { [s: string]: T }) => T[];
function zipArrays
zipArrays: <T>( left: T[], right: T[]) => IterableIterator< | ['retain', number, T, T] | ['pop', number, T, undefined] | ['push', number, undefined, T]>;
function zipTuples
zipTuples: <T extends readonly unknown[]>( left: T, right: T) => IterableIterator<ZipEntry<T>>;
Zip two tuples with the same type and number of elements.
Classes
class Stack
class StackImpl<T> implements Stack<T> {}
constructor
constructor(values?: T[]);
property current
current: Nullable<T>;
property size
readonly size: number;
method isEmpty
isEmpty: () => boolean;
method nth
nth: (from: number) => Nullable<T>;
method pop
pop: () => Nullable<T>;
method push
push: (item: T) => void;
method snapshot
snapshot: () => T[];
method toArray
toArray: () => T[];
Type Aliases
type FIXME
type FIXME<T, S extends string> = (T & S) | T;
Package Files (1)
Dependencies (2)
Dev Dependencies (9)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@glimmer/util
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@glimmer/util)
- HTML<a href="https://www.jsdocs.io/package/@glimmer/util"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3945 ms. - Missing or incorrect documentation? Open an issue for this package.