Skip to content

Instantly share code, notes, and snippets.

View dunz's full-sized avatar
๐ŸŽฏ
Focusing

dunz dunz

๐ŸŽฏ
Focusing
  • Woowahan Bros
  • Seoul
View GitHub Profile
@dunz
dunz / createReducer.js
Last active April 17, 2021 06:53
๋ฆฌ๋“€์„œ ์ƒ์„ฑ ๋ชจ๋“ˆ ๋ถ„๋ฆฌํ•˜์—ฌ ๋ฆฌ๋“€์„œ ์ƒ์„ฑ ๋กœ์ง ๊ฐ„์†Œํ™”
// # Common Module
const createReducer = (initialState, reducer) => (state = initialState, action) => {
return Reflect.has(reducer, action.type)
? reducer[action.type](state)
: state;
}
// # Usages
// ## before
const initialState = 0;
@dunz
dunz / utc-utils.ts
Created April 12, 2021 14:00
UTC utils
/**
* ๋กœ์ปฌ ํƒ€์ž„์กด ๊ตฌํ•˜๊ธฐ
*/
export const getLocaleTimezone = () => new Date().getTimezoneOffset() / -60;
/**
* Timezone์„ ๊ธฐ์ค€์œผ๋กœ ๋„˜๊ฒจ๋ฐ›์€ ๋‚ ์งœ๋ฅผ ์„ค์ •ํ•˜์—ฌ ๊ทธ Date์˜ UTC ์ถ”์ถœํ•˜๊ธฐ
* @param timezone (-12 ~ +12)
* @param date
*/
@dunz
dunz / es6.js
Last active February 17, 2021 05:01
simple es6 utils
// ์ˆซ์žํ˜•๋ณ€ํ™˜ 2์ง„์ˆ˜, 10์ง„์ˆ˜, 8์ง„์ˆ˜ 16์ง„์ˆ˜
// https://unikys.tistory.com/334
// 10์ง„์ˆ˜๊ฐ€ ์ฃผ์–ด์ง€๊ณ  ๋‹ค๋ฅธํ˜• ๋ณ€ํ™˜ => source.toString(2 or 8 or 16)
// ๋‹ค๋ฅธํ˜•์ด ์ฃผ์–ด์ง€๊ณ  10์ง„์ˆ˜ ๋ณ€ํ™˜ => parseInt(source, 2 or 8 or 16)
// ๋‘ ๋ณ€์ˆ˜ ์Šค์™‘
let a = 1;
let b = 2;
// solution.1
@dunz
dunz / CaseUtil.ts
Created October 15, 2020 12:12
case util
import {
isPlainObject,
isArray,
isEmpty,
mapKeys,
mapValues,
cloneDeep,
snakeCase,
camelCase,
kebabCase,
@dunz
dunz / CustomError.ts
Created August 6, 2020 07:58
์ปค์Šคํ…€ ์—๋Ÿฌ ์ฒ˜๋ฆฌ
class Custom {
constructor() {
console.log(this.constructor) // [Function: Custom]
console.log(this.constructor.prototype) // Custom {}
console.log(new.target === this.constructor) // true
console.log(new.target.prototype === this.constructor.prototype) // true
}
}
const custom = new Custom()
@dunz
dunz / pagination.js
Created June 16, 2020 11:20
pagination source
import {Component, Prop, Watch} from 'vue-property-decorator';
import {BaseComponent} from 'seed/src/BaseComponent';
import {range} from 'lodash';
import {lazyInject} from 'seed/src/application-container/ApplicationContext';
import DependencyInjectId from '@/const/DependencyInjectId';
import ArticleCheckListService from '@/service/check-list/ArticleCheckListService';
import {StoveLogService} from 'seed/src/service/logger/StoveLogService';
import {LogActionType} from 'seed/src/enum/log/LogActionType';
const intValidator = (value: number) => value > 0;
@dunz
dunz / validator.js
Last active June 14, 2020 04:38
Validator Utilities from 1loc.dev
// ๋‚ ์งœ๊ฐ€ ๋‘ ๋‚ ์งœ ์‚ฌ์ด์ธ์ง€ ํ™•์ธ
const isBetween = (date, min, max) => (date.getTime() >= min.getTime() && date.getTime() <= max.getTime());
// ๋‚ ์งœ๊ฐ€ ์˜ค๋Š˜์ธ์ง€ ํ™•์ธ
const isToday = (date) => date.toISOString().slice(0, 10) === new Date().toISOString().slice(0, 10);
// ์ฃผ์–ด์ง„ ์ˆซ์ž๊ฐ€ ์†Œ์ˆ˜์ธ์ง€ ํ™•์ธ
const isPrime = num => (num > 1) && Array(Math.floor(Math.sqrt(num)) - 1).fill(0).map((_, i) => i + 2).every(i => num % i !== 0);
// ์ˆซ์ž๊ฐ€ 2์˜ ๊ฑฐ๋“ญ ์ œ๊ณฑ์ธ์ง€ ํ™•์ธ
@dunz
dunz / string.js
Last active January 26, 2022 08:08
String Utilities from 1loc.dev
// ๋ฌธ์ž์—ด์„ ๋Œ€๋ฌธ์ž๋กœ
const toUpper = string => string.toUpperCase();
// ๋ฌธ์ž์—ด์˜ ์ฒซ๋ฌธ์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ
const capitalize = str => `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
// ๊ฒฝ๋กœ๊ฐ€ ์ƒ๋Œ€์ ์ธ์ง€ ํ™•์ธ
const isRelative = path => !/^([a-z]+:)?[\\/]/i.test(path);
// Examples
@dunz
dunz / random.js
Created June 13, 2020 08:19
Random Utilities from 1loc.dev
// ์ž„์˜์˜ ๋ถ€์šธ ์ƒ์„ฑ
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')}`;
// ์ฃผ์–ด์ง„ ๋ฒ”์œ„์—์„œ ์ž„์˜์˜ ์ •์ˆ˜๋ฅผ ์ƒ์„ฑ
@dunz
dunz / number.js
Last active October 8, 2020 05:05
Number Utilities from 1loc.dev
// ์ˆซ์ž์— ์„œ์ˆ˜ ์ ‘๋ฏธ์‚ฌ ์ถ”๊ฐ€
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'