fluent-flags
TypeScript icon, indicating that this package has built-in type declarations

3.1.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i fluent-flags

Weekly Downloads

42

Version

3.1.1

License

MIT

Unpacked Size

19.8 kB

Total Files

13

Last publish

Collaborators

  • stagas