Socket
Book a DemoInstallSign in
Socket

ifless

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ifless

Get rid of if statements in your code by using convenient api

Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
5
150%
Maintainers
1
Weekly downloads
 
Created
Source

ifless NPM version

Get rid of if statements in your code by using convenient api

Install

npm install ifless

or

yarn add ifless

Usage

Ifless

import Ifless from 'ifless';

const ifless = new Ifless();
const result = ifless
                  .when(() => false, 'foo')
                  .when(() => true, 'bar)
                  .result;
console.log(result); // bar

IflessNumber

import {IflessNumber} from 'ifless';

const iflessNumber = new IflessNumber(12);
const result = iflessNumber.whenLt(7, 'bar').whenGt(10, 'baz').result;
console.log(result); // baz

IflessString

import {IflessString} from 'ifless';

const iflessString = new IflessString('O. Henry - The Remnants of the Code');
const result = iflessString
	.whenStartsWith('Mark Twain', 'Author is Mark Twain')
	.whenStartsWith('O. Henry', 'Author is O. Henry')
	.whenStartsWith('Ernest Hemingway', 'Author is Ernest Hemingway').result;
console.log(result); // Author is O. Henry

// Reset previously performed conditions
// and run another ones without creating a new instance
const result2 = iflessString
	.reset()
	.whenEndsWith('Parade', 'Ends with "Parade"')
	.whenEndsWith('Code', 'Ends with "Code"')
	.whenEndsWith('Unfulfilment', 'Ends with "Unfulfilment"').result;
console.log(result2); // Ends with "Code"

IflessObject

import {IflessObject} from 'ifless';

const iflessString = new IflessObject({foo: 'bar'});
const result = iflessString
	.when(source => source.foo === 'qux', 'foo is qux')
	.when(source => source.foo === 'bar', 'foo is bar')
	.when(source => source.foo === 'corge', 'foo is corge').result;
console.log(result); // foo is bar

License

MIT © Rushan Alyautdinov

Keywords

ifless

FAQs

Package last updated on 11 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts