1.0.0 • Published 5 years ago

optmap v1.0.0

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

optmap - Option mapping for JavaScript

Usage

  1. Install optmap via NPM (or Yarn):
npm i optmap
# OR:
yarn add optmap
  1. Import optmap
import { optmap } from 'optmap';
// OR:
const { optmap } = require('optmap');

Simple switch-case statement:

const value = optmap(otherValue, {
	'option1': 'Hello, World!',
	'option2': 'Something else'
});

// otherValue = 'option2'
// value      = 'Something else'

With options:

const color = optmap(framework, {
	'Vue': 'green',
	'Angular': 'red',
	'React': 'blue'
}, { ignoreCase: true })

// framework = 'anGuLar'
// color     = 'red'

API

optmap(value: any, options: IOptMapOptions, config?: IOptMapConfig): any

IOptMapOptions

The key must be a string, the value can be anything:

export interface IOptMapOptions {
	[key: string]: any;
}

IOptMapConfig

ignoreCase - Ignore case for option keys. Only works with string values.

1.0.0

5 years ago