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
| # Fig pre block. Keep at the top of this file. | |
| [[ -f "$HOME/.fig/shell/zshrc.pre.zsh" ]] && . "$HOME/.fig/shell/zshrc.pre.zsh" | |
| # ------------------------------------------------------------------- | |
| # PATH | |
| # ------------------------------------------------------------------- | |
| # oh-my-zs # | |
| export ZSH=$HOME/.oh-my-zsh | |
| # MongoDB # |
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
| // λͺ¨λ λ°°μ΄ μμκ° μ£Όμ΄μ§ κ°κ³Ό κ°μμ§ νμΈ | |
| const isEqual = (arr, value) => arr.every(item => item === value); | |
| // λ°°μ΄μ λͺ¨λ νλͺ©μ΄ κ°μμ§ νμΈ | |
| const areEqual = arr => arr.every(item => item === arr[0]); | |
| const areEqual = arr => new Set(arr).size === 1; | |
| // λ°°μ΄μ μΌλΆ κΈ°μ€κ³Ό μΌμΉνλ κ°μ΄ ν¬ν¨λμ΄ μλμ§ νμΈ | |
| const contains = (arr, predicate) => !!arr.find(predicate); | |
| const contains = (arr, predicate) => arr.some(criteria); |
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
| // κ°μ΄ μΌλ° κ°μ²΄μΈμ§ νμΈ | |
| const isPlainObject = v => !!v && typeof v === 'object' && (v.__proto__ === null || v.__proto__ === Object.prototype); | |
| const isPlainObject = obj => !!obj && obj.constructor === Object | |
| // κ°μ΄ κ°μ²΄μΈμ§ νμΈ | |
| const isObject = v => !!v && typeof v === 'object'; | |
| // κ°μ²΄κ° λΉμ΄ μλμ§ νμΈ | |
| const isEmpty = obj => !!obj && obj.constructor === Object && Reflect.ownKeys(obj).length === 0; | |
| const isEmpty = obj => JSON.stringify(obj) === '{}'; |
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
| // λ λ μ§ μ¬μ΄μ μ°¨μ΄ μΌ μ κ³μ° | |
| const diffDays = (d1, d2) => Math.ceil(Math.abs(d1 - d2) / (60*60*24*1000)); | |
| // λ λ μ§ λΉκ΅ | |
| const compare = (a, b) => a.getTime() > b.getTime(); | |
| // λ μ§λ₯Ό yyyy mm dd νμμΌλ‘ λ³ν | |
| const formatYmd = date => date.toISOString().slice(0, 10); | |
| // μ΄λ₯Ό hh mm ss νμμΌλ‘ λ³ν |
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
| // μμκ° μμμΈμ§ νμΈ | |
| const isDescendant = (child, parent) => parent.contains(child); | |
| const div = document.createElement('div') | |
| const h1 = document.createElement('h1') | |
| div.append(h1) | |
| isDescendant(h1, div) | |
| // μμκ° νμ±νλμ΄ μλμ§ νμΈ | |
| const hasFocus = ele => (ele === document.activeElement); |
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
| // κ°μ΄ ν¨μμΈμ§ νμΈ | |
| const isFunction = v => [ | |
| '[object Function]', | |
| '[object GeneratorFunction]', | |
| '[object AsyncFunction]', | |
| '[object Promise]' | |
| ].includes(Object.prototype.toString.call(v)); | |
| // κ°μ΄ μ λλ μ΄ν° ν¨μμΈμ§ νμΈ | |
| const isGeneratorFunction = v => Object.prototype.toString.call(v) === '[object GeneratorFunction]'; |
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
| // μ½λκ° nodeνκ²½μμ μ€νμ€μΈμ§ νμΈ | |
| const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null; | |
| // λΈλΌμ°μ μμ μ½λκ° μ€ν μ€μΈμ§ νμΈ | |
| const isBrowser = typeof window === 'object' && typeof document === 'object'; | |
| // μμ¨λ₯Ό νμ¨λ‘ λ³ν | |
| const celsiusToFahrenheit = celsius => celsius * 9/5 + 32; | |
| // νμ¨λ₯Ό μμ¨λ‘ λ³ν |
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
| // μ«μμ μμ μ λ―Έμ¬ μΆκ° | |
| const addOrdinal = n => `${n}${['st', 'nd', 'rd'][((n + 90) % 100 - 10) % 10 - 1] || 'th'}`; | |
| const addOrdinal = n => `${n}${[, 'st', 'nd', 'rd'][/1?.$/.exec(n)] || 'th'}`; | |
| const addOrdinal = n => `${n}${[, 'st', 'nd', 'rd'][n % 100 >> 3^1 && n % 10] || 'th'}`; | |
| const addOrdinal = n => `${n}${{one: 'st', two: 'nd', few: 'rd', other: 'th'}[new Intl.PluralRules('en', { type: 'ordinal' }).select(n)]}`; | |
| // Examples | |
| addOrdinal(1); // '1st' | |
| addOrdinal(2); // '2nd' | |
| addOrdinal(3); // '3rd' |
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
| // μμμ λΆμΈ μμ± | |
| const randomBoolean = () => Math.random() >= 0.5; | |
| // μ£Όμ΄μ§ λ²μμμ μμμ λΆλ μμμ μλ₯Ό μμ± | |
| const randomFloat = (min, max) => Math.random() * (max - min) + min; | |
| // μμμ 16 μ§μ μμ μμ± | |
| const randomColor = () => `#${Math.random().toString(16).slice(2, 8).padEnd(6, '0')}`; | |
| // μ£Όμ΄μ§ λ²μμμ μμμ μ μλ₯Ό μμ± |
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
| // λ¬Έμμ΄μ λλ¬Έμλ‘ | |
| const toUpper = string => string.toUpperCase(); | |
| // λ¬Έμμ΄μ 첫문μλ₯Ό λλ¬Έμλ‘ | |
| const capitalize = str => `${str.charAt(0).toUpperCase()}${str.slice(1)}`; | |
| // κ²½λ‘κ° μλμ μΈμ§ νμΈ | |
| const isRelative = path => !/^([a-z]+:)?[\\/]/i.test(path); | |
| // Examples |
OlderNewer