npm.io
3.1.1 • Published 4 years ago

fluent-flags

Licence
MIT
Version
3.1.1
Deps
0
Size
19 kB
Vulns
0
Weekly
0
Stars
1

fluent-flags

Decorates a function with arbitrary fluent boolean flags and passes them as the first parameter.

npm i fluent-flags pnpm add fluent-flags yarn add fluent-flags

API

# Flags src/index.ts#L6

    [K in T extends ReadonlyArray<inferred> ? U : never ]: boolean

# Fluent src/index.ts#L3
# Fn src/index.ts#L2

    # (args)

      # args

      (args)  =>

# Key src/index.ts#L1

    string

# NarrowHelper src/index.ts#L11

    T extends readonly tuple ? readonly tuple : never | T extends string | number | bigint | boolean ? T : never | [K in keyof T ]: T [K] extends

    # (args)

      # args

        any []

      (args)  =>

        unknown

    ? T [K] : NarrowHelper<T [K]>

# FluentFlags(_flagKeys, cb, flags) – Decorates a function with fluent flags that are then passed as an object. src/index.ts#L27

    const cb = FluentFlags(
      ['foo', 'bar'],
      flags => (arg: string) => [flags.foo, flags.bar, arg]
    )
    expect(cb()).toMatchObject([void 0, void 0, void 0])
    expect(cb('hello')).toMatchObject([void 0, void 0, 'hello'])
    expect(cb.bar('hello')).toMatchObject([void 0, true, 'hello'])
    expect(cb.foo.bar('hello')).toMatchObject([true, true, 'hello'])

    # _flagKeys
    # cb(flags)

      # flags

      cb(flags)  =>

    # flags  =  {}

      any

    FluentFlags<K, C extends  Fn<any, any>, T>(_flagKeys, cb, flags)  =>

Contributing

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT 2022 stagas