Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { switchcaseD, switchcaseF, switchcaseA, switchcaseA2, switchcaseReverse, $Ω } = require ('./switch-alternatives.js')
- console.clear()
- console.log('Examples: switch-alternatives.js'); console.log();
- // ------------------------------------------------------------
- const mapperBest = switchcaseA({
- stringData: 'This is regular string data friends',
- functionData: () => ('the function worked')
- })(() => ('This will work with a function or straight data'))
- // Each case.
- console.log('Testing switchcaseA()')
- console.log('1.', mapperBest('stringData'))
- console.log('2.', mapperBest('functionData'))
- console.log('3.', mapperBest())
- console.log('------------')
- console.log()
- // An example.
- const mapperA2 = switchcaseA2({
- stringData: 'This is regular string data friends',
- functionData: () => ('the function worked')
- })(() => ('This will work with a function or straight data'))
- // Each case.
- console.log('Testing switchcaseA2()')
- console.log('1.', mapperA2('stringData'))
- console.log('2.', mapperA2('functionData'))
- console.log('3.', mapperA2())
- console.log('------------')
- console.log()
- // ------------------------------------------------------------
- const mapperFunc = switchcaseF({
- // Can't handle this version.
- // stringData: 'This is regular string data friends',
- functionData: () => ('the function worked')
- })(() => ('This will work ONLY with functions, the first one would fail if it were anything but'))
- // Each case.
- console.log('Testing switchcaseF()')
- console.log('1.', mapperFunc('stringData'))
- console.log('2.', mapperFunc('functionData'))
- console.log('3.', mapperFunc())
- console.log('------------')
- console.log()
- // ------------------------------------------------------------
- const mapper = switchcaseD({
- andric: 'hey there friend',
- amanda: 'get your hands off my wife!'
- })('I dunno, whatever dude')
- // Each case.
- console.log('Testing switchcaseD()')
- console.log('1.', mapper('andric'))
- console.log('2.', mapper('amanda'))
- console.log('3.', mapper())
- console.log('------------')
- console.log()
- const getDay = switchcaseD({
- 0: 'Sunday',
- 1: 'Monday',
- 2: 'Tuesday',
- 3: 'Wednesday',
- 4: 'Thursday',
- 5: 'Friday',
- 6: 'Saturday'
- })('Unknown')
- const today = () => getDay(new Date().getDay())
- console.log('Testing programatic switchcaseD()')
- console.log(today())
- console.log(new Date().getDay())
- console.log('------------')
- console.log()
- // const async asyncCases = () => {
- // const case1 = await networkcall()
- // const case2 = await networkcall()
- // const case3 = await networkcall()
- // return {
- // case1, case2, case3,
- // }
- // }
- // ------------------------------------------------------------
- const programatic2 = switchcaseReverse('I dunno, whatever dude')({
- andric: 'hey there friend',
- amanda: 'get your hands off my wife!'
- })
- // Each case.
- console.log('Testing switchcaseReverse()')
- console.log('1.', programatic2('andric'))
- console.log('2.', programatic2('amanda'))
- console.log('3.', programatic2())
- console.log('------------')
- console.log()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement