This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SET_CURRENT_USER } from '../actions/types'; | |
import { isEmpty } from '../../utilities/validations'; | |
import match from 'conditional-expression'; | |
const initialState = { | |
isAuthenticated: false, | |
user: {} | |
}; | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import match from 'conditional-expression'; | |
match('funny joke') | |
.equals('sad').then('I am false') | |
.with(/[a-z]/).then('I am true and I am the result') | |
.includes('joke').then('I am true but I am not evaluated') | |
.else('I just execute everything'); | |
// returns 'I am true and I am the result' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TextTransformation { | |
constructor(text) { | |
this.text = text; | |
} | |
makeImportant() { | |
this.text = this.text.trim(); // trim | |
this.text = this.text.toLowerCase(); // make lowercase | |
this.text = this.text.charAt(0).toUpperCase() + this.text.slice(1); // capitalize | |
this.text = this.text + '!'; // add ! | |
return this.text; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { assert } from 'chai'; | |
import TextTransformation from '../src/text-transform-class'; | |
describe('test makeImportant', () => { | |
it('Makes it capitalized, trimmed with ! at the end.', | |
() => assert.strictEqual(new TextTransformation (' pReSiDeNt ').makeImportant(), 'President!')); | |
}); | |
describe('test makeUnimportant', () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import TextTransformation from '../src/text-transform-class'; | |
cont textTransformation = new TextTransformation('bug'); | |
console.log(textTransformation.makeImportant()); | |
// output: Bug! | |
console.log(textTransformation.makeUnimportant()); | |
// output: bug!. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TextTransformation { | |
static capitalize(text) { | |
return text.charAt(0).toUpperCase() + text.slice(1); | |
} | |
static addExclamationMark(text) { | |
return text + '!'; | |
} | |
static addPunctuation(text) { | |
return text + '.'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { assert } from 'chai'; | |
import TextTransformation from '../src/text-transform-oop'; | |
describe('test atomic functions', () => { | |
it('capitalize(text) turns first character to Capital', | |
() => assert.strictEqual(TextTransformation.capitalize("pReSiDeNt"), 'PReSiDeNt')); | |
it('addExclamationMark(text) adds !', | |
() => assert.strictEqual(TextTransformation.addExclamationMark("text"), 'text!')); | |
it('addPunctuation(text) adds .', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))); | |
export const trim = text => text.trim(); | |
export const toLowerCase = text => text.toLowerCase(); | |
export const capitalize = text => text.charAt(0).toUpperCase() + text.slice(1); | |
export const addExclamationMark = text => text + '!'; | |
export const addPunctuation = text => text + '.'; | |
export const makeImportant = compose(addExclamationMark, capitalize, toLowerCase, trim); | |
export const makeUnimportant = compose(addPunctuation, toLowerCase, trim); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { assert } from 'chai'; | |
import * as TextTransformation from '../src/text-transform-functional'; | |
describe('test atomic functions', () => { | |
it('trim(text) trims spaces', | |
() => assert.strictEqual(TextTransformation.trim(' Text '), 'Text')); | |
it('trim(text) trims tabs', | |
() => assert.strictEqual(TextTransformation.trim(' Text '), 'Text')); | |
it('trim(text) trims new lines', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [url, setUrl] = useState('https://myserver/api/v1'); |