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 fullName = ( | |
{firstName = "", lastName = ""} // we are providing default values | |
: {firstName: string, lastName: string} // type, can be inferenced | |
= {} // default value object for object argument | |
) => `${firstName} ${lastName}`; |
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
function add(a: number, b: number): number { return a + b }; | |
const add = (a: number, b: number): number => a + b; | |
type Arithmetics = (a: number, b: number) => number; | |
// or | |
/* | |
interface Arithmetics { | |
(a: number, b: number): number; | |
} |
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
/** | |
* A person object with name, age and sayName method. | |
* @typedef {Object} Person | |
* @property {string} name The person's name. | |
* @property {number} age The person's age. | |
* @property {Function} sayName A function that alerts the person's name. | |
*/ | |
const person = { | |
name: 'Joe', | |
age: 32, |
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 React from "react"; | |
import {inject, observer} from "mobx-react"; | |
export class SubjectsPresenter extends React.Component {...} | |
export default inject( | |
({subjectStore, translator}, {subjectSelections, ...props}) => { | |
const subjectOptions = subjectStore.getFilteredSubjects(subjectSelections); | |
return { | |
subjectOptions, |
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
// see types of prompts: | |
// https://github.com/enquirer/enquirer/tree/master/examples | |
// | |
module.exports = [ | |
{ | |
type: "input", | |
name: "name", | |
message: "What's the name of your package?" | |
}, | |
{ |
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
Calendar.defaultProps = { | |
Wrapper: styled.div` | |
display: flex; | |
flex-direction: row; | |
`, | |
Column: styled.div` | |
display: flex; | |
flex-direction: column; | |
margin: 0.5rem; | |
`, |
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 React from "react"; | |
import ReactDOM from "react-dom"; | |
import Calendar from "./components/Calendar"; | |
const App = () => ( | |
<> | |
<Calendar> | |
{({ Wrapper, Column, Box, Item, headers }) => ( | |
<Wrapper> | |
{headers.map((header, index) => ( |
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 FormattedNumber = ({ value, roundingFn = val => val }) => roundingFn(value); | |
//js | |
console.log( | |
FormattedNumber({value: 5.6}) /* 5.6 */ | |
); | |
//jsx | |
<FormattedNumber value={5.6} /> /* 5.6 */ | |
<FormattedNumber value={5.6} roundingFn={Math.floor} /> /* 5 */ |
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
/*-------- Promise.then() syntax ---------*/ | |
// when expect() is in Promise.then() method body | |
// we have to use callback function done() | |
it("test two inputs to have labels with same classes using Promise.then() ", (done) => { | |
getInputsLabelElement(input1).then((label1) => { | |
getInputsLabelElement(input2).then((label2) => { | |
label1.getAttribute("class").then((label1Classes) => { | |
label2.getAttribute("class").then((label2Classes) => { | |
expect(label1Classes).toBe(label2Classes); |
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
Original Value | Converted to Number | Converted to String | Converted to Boolean | |
---|---|---|---|---|
false | 0 | false | false | |
true | 1 | true | true | |
0 | 0 | 0 | false | |
1 | 1 | 1 | true | |
0 | 0 | 0 | true | |
000 | 0 | 000 | true | |
1 | 1 | 1 | true | |
NaN | NaN | NaN | false | |
Infinity | Infinity | Infinity | true |