FunctionSelect: Select a function that passes a condition. A functional alternative to switch-case.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Muthu Kumar a730dca5f5 [docs] Update links in credits, trigger build Github pages 7 years ago
.vscode [misc] debug scripts 7 years ago
docs [docs] Update links in credits, trigger build Github pages 7 years ago
spec [tests] Updated tests to reflect no-satisfying-test scenario 7 years ago
.eslintignore [misc] Bump to v0.0.9 7 years ago
.eslintrc.js [eslint] Updated lint rules 7 years ago
.gitignore [lint] Added eslint 7 years ago
LICENSE Initial commit 7 years ago
README.md [docs] Update links in credits, trigger build Github pages 7 years ago
Select.js [docs] Added JSDoc comments 7 years ago
package-lock.json [misc] Bump to v0.0.9 7 years ago
package.json [misc] Bump to v0.0.9 7 years ago

README.md

select-return

Return a function based on a condition. Functional alternative to switch-case.

Usage

const a = 100;

const result = new Select(a)
	.for(x => x>10,
		a => `${a} is greater than 10.`)
	.for(x => x<10,
		a => `${a} is lesser than 10.`)
	.for(x => x===10,
		a => `${a} is 10.`)

console.log(result.resolve()); // -> "100 is greater than 10."

Docs

Docs exist in /docs directory. Will be served soon.

Development

If you find any mistakes in code/documentation, or if you feel something could be done better, do PR :)

I appreciate it.

  • Always write test spec for any code you add. Make sure they run as intended.
  • Add/update JSDoc comments as needed.
  • Use npm scripts for linting, debugging, building docs.

Place your test file as testscript.js in root.

The following npm scripts are available: npm run lint, npm run debug, npm run docs.

Credits

@Floofies was of huge help during development of this module.

Also, @TRGWII was a source of inspiration and guidance.