![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
npm i switch-js
const switcher = require('switch-js');
const valueToTest = 'foo';
switcher(valueToTest)
.case('foo', () => console.log('foo!'))
.case('bar', () => console.log('bar!'))
.default(() => console.log('no match found in given cases!'))
.always(() => console.log('this is cool!'));
// result:
// foo!
// this is cool!
Check for multiple cases:
switcher(valueToTest)
.cases(['foo', 'bar'], () => console.log('foo or bar!'))
.default(() => console.log('no match found in given cases!'));
// result: foo or bar!
Check if value is matched by a function:
switcher(valueToTest)
.caseWhen(value => typeof value === 'string', () => console.log('a string!'))
.caseWhen(value => typeof value === 'number', () => console.log('a number!'))
.default(() => console.log('other datatypes!'));
// result: a string!
Use to
to set value:
const valueInUppercase = switcher(valueToTest)
.case('foo').to('FOO!')
.case('bar').to('BAR!')
.value('NO MATCH FOUND!');
// result: FOO!
// .value('NO MATCH FOUND!')
// has the same effect as
// .default().to('NO MATCH FOUND!').value()
Use mapTo
to set the value by a function:
const valueInUppercase = switcher(valueToTest)
.cases(['foo', 'bar']).mapTo(value => value.toUpperCase())
.default().mapTo(value => value.toUpperCase() + ' IS NOT A MATCH!')
.value();
// result: 'FOO'
switch(value)
start a switch chain
value
Value to checkcase(caseValue[, matchedCallback][, notMatchedCallback])
The case method you know
caseValue
matchedCallback
Function, optional. Invoked if caseValue
equals deeply to value
notMatchedCallback
Function, optional. Invoked otherwisecases(caseValues[, matchedCallback][, notMatchedCallback])
Check for multiple case values
caseValues
Array of caseValue
matchedCallback
Function, optional. Invoked if caseValues
includes value
notMatchedCallback
Function, optional. Invoked otherwisecaseWhen(matcher[, matchedCallback][, notMatchedCallback])
Check by a function
matcher
A match function used to check if value
is a matchmatchedCallback
Function, optional. Invoked if matcher(value)
returns a truthy valuenotMatchedCallback
Function, optional. Invoked otherwisedefault([noMatchFoundCallback, matchFoundCallback])
The default method you know
noMatchFoundCallback
Function, optional. Invoked if no match is foundmatchFoundCallback
Function, optional. Invoked otherwisealways(callback)
Invoked anyway
callback
Functionto(valueToReturn)
Set a new value to return by value()
if previous case is a match or it follows default()
valueToReturn
mapTo(mapper)
Similiar to to()
but set value by a mapper function
mapper
Function | String. If a string is passed, it will take as a path and invoke _.get(valueToTest, path)
from lodashvalue(defaultValue)
Return the value
defaultValue
Default value will return if no match is foundFAQs
Use switch and case as chainable functions
The npm package switch-js receives a total of 1 weekly downloads. As such, switch-js popularity was classified as not popular.
We found that switch-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.