This file contains hidden or 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
/** | |
* Swedish/Finnish special characters: åäö | |
* Danish/Norwegian special characters: æøå | |
* Latin characters: a-z | |
* Other special characters: ç (e.g. country Curaçao) | |
*/ | |
const wordRegex = /[åäöçæøa-z]+/gi; | |
export const capitalizeWord = (word: string): string => | |
word.charAt(0).toUpperCase() + word.substring(1).toLowerCase(); |
This file contains hidden or 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
export const chunkArray = <T>(array: Array<T>, size: number) => { | |
const results = []; | |
while (array.length) { | |
results.push(array.splice(0, size)); | |
} | |
return results; | |
}; |
This file contains hidden or 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
export const camelToKebabCase = (text: string) => { | |
return text.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase(); | |
}; |
This file contains hidden or 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
export const setOrReplaceFavoritesIcon = (icon: string = defaultFavIcon) => { | |
const link: HTMLLinkElement = | |
document.querySelector('link[rel*="icon"]') || | |
document.createElement('link'); | |
link.type = 'image/x-icon'; | |
link.rel = 'shortcut icon'; | |
link.href = icon; | |
document.getElementsByTagName('head')[0].appendChild(link); | |
}; |
This file contains hidden or 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
{ | |
"New React FC": { | |
"prefix": "nfc", | |
"body": [ | |
"import React from 'react';", | |
"import classes from './${1}.module.scss';", | |
"", | |
"interface ${1}Props {}", | |
"", | |
"const ${1} = (props: ${1}Props) => {", |
This file contains hidden or 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
{ | |
"New Test React FC": { | |
"prefix": "ntfc", | |
"body": [ | |
"import React from 'react';", | |
"import { render } from '@testing-library/react';", | |
"import ${1} from './${1}';", | |
"", | |
"it ('${1} renders without crashing', () => {", | |
"\trender(", |
This file contains hidden or 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 { makeAutoObservable } from "mobx" | |
export class BalanceState { | |
balance = 1000 | |
constructor() { | |
makeAutoObservable(this) | |
} | |
add(value: number) { |
This file contains hidden or 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 { BalanceActionType, AddAction, WithdrawAction } from "./types" | |
export const add = (amount: number): AddAction => ({ | |
type: BalanceActionType.ADD, | |
payload: amount, | |
}) | |
export const withdraw = (amount: number): WithdrawAction => ({ | |
type: BalanceActionType.WITHDRAW, | |
payload: amount, |
This file contains hidden or 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 { Developer } from "./Developer"; | |
// name | |
test("should drink coffee", () => { | |
// setup | |
const developer = new Developer(); | |
// action | |
const result = developer.drinkCoffee(); | |
// expectation | |
expect(result).toContain("coffee ☕"); | |
}); |
This file contains hidden or 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
export class Developer { | |
public drinkCoffee(): string { | |
return "Drinking a cup of coffee ☕"; | |
} | |
} |
OlderNewer