diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2021-09-16 16:29:20 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2021-09-16 16:29:20 +0200 |
| commit | 9a8b38c18a1853cdb63c7245fa8cc19735d2b569 (patch) | |
| tree | 6aad50a17e4ce55c5dab94bb4fab1475ca30648c /src/utils/index.js | |
| parent | 0885b9db9e264a666cd0fa656442569a953fb7f7 (diff) | |
refactor utils
Diffstat (limited to 'src/utils/index.js')
| -rw-r--r-- | src/utils/index.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/utils/index.js b/src/utils/index.js new file mode 100644 index 0000000..ee9dae9 --- /dev/null +++ b/src/utils/index.js @@ -0,0 +1,20 @@ +/** + * Utility functions + */ + +export const rand = (n) => Math.random() * n; +export const randint = (limit) => Math.floor(Math.random() * limit); +export const choice = (list) => list[randint(list.length)]; + +export const mod = (n, m) => n - m * Math.floor(n / m); + +export const pad = (value) => (value < 10 ? "0" + value : value); + +export const capitalizeWord = (text = "") => + text ? text.charAt(0).toUpperCase() + text.slice(1) : ""; + +export const capitalize = (text = "") => + String(text || "") + .split(" ") + .map(capitalizeWord) + .join(" "); |
