MCPcopy Create free account
hub / github.com/activejs/activejs / createUnit

Function createUnit

packages/core/src/lib/creators.ts:28–50  ·  view source on GitHub ↗
(
  initialValue: T,
  config?: Exclude<UnitConfig<T>, 'initialValue'>
)

Source from the content-addressed store, hash-verified

26 * @param config The configuration for the automatically selected Unit.
27 */
28export function createUnit<T>(
29 initialValue: T,
30 config?: Exclude<UnitConfig<T>, 'initialValue'>
31): ValueToUnitType<T> {
32 const unitConfig: UnitConfig<T> = {...config, initialValue};
33 const typeOfValue = typeof initialValue;
34
35 switch (true) {
36 case initialValue == null:
37 default:
38 return new GenericUnit(unitConfig as any) as any;
39 case typeOfValue === 'boolean':
40 return new BoolUnit(unitConfig as any) as any;
41 case typeOfValue === 'number':
42 return new NumUnit(unitConfig as any) as any;
43 case typeOfValue === 'string':
44 return new StringUnit(unitConfig as any) as any;
45 case Array.isArray(initialValue):
46 return new ListUnit(unitConfig as any) as any;
47 case isDict(initialValue):
48 return new DictUnit(unitConfig as any) as any;
49 }
50}

Callers

nothing calls this directly

Calls 1

isDictFunction · 0.90

Tested by

no test coverage detected