Skip to content

Jaid/optis

Repository files navigation

Optis

Minimalistic library for building composable options processors.

import optis from 'optis'

const schema = optis({
  defaults: {
    target: 'world',
  },
})

export default (options: optis.Parameter<typeof schema>) => {
  const processedOptions = schema.process(options)
  return `Hello, ${processedOptions.target}!`
}

The default export also carries the public type helpers, so optis.Parameter<typeof schema>, optis.Processed<typeof schema> and optis.Schema<...> work without a second import type.

If you prefer direct named type imports, the same helpers are also exported as OptisParameter, OptisProcessed, OptisProcessedMap, OptisSchema, OptisSetup and related aliases.

import optis, {type OptisParameter} from 'optis'

const schema = optis({
  defaults: {
    target: 'world',
  },
})

export default (options: OptisParameter<typeof schema>) => {
  const processedOptions = schema.process(options)
  return `Hello, ${processedOptions.target}!`
}

Type-only and runtime features can be composed by chaining .extend() and .extendTyped().

import optis from 'optis'

const schema = optis({
  defaults: {
    cwd: process.cwd(),
  },
}).extendTyped<{
  optional: {
    user: string
  }
}>()

export default (options: optis.Parameter<typeof schema>) => {
  const processedOptions = schema.process(options)
  if (processedOptions.user) {
    console.log(`USER=${processedOptions.user}`)
  }
}

About

Optis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors