본문 바로가기

✘✘✘ Javascript25

[type] keyof, typeof 를 사용해 type 지정 예시 const keyToPropertyMap = { 'on-off': 'active', name: 'name', appliedTo: 'level', frequency: 'period', }; type SortInfo = { key?: keyof typeof keyToPropertyMap; // asc: boolean; }; 질문 keyof typeof keyToPropertyMap? 답변 type:: keyof typeof keyToPropertyMap = 'on-off' | 'name' | 'appliedTo' | 'frequencyÏ' 설명 이 예에서 keyof typeo.. 2023. 4. 8.
[event] window.matchMedia - mobile detecting: 모바일 확인 하기 + React Hook 1. javascript window.innerWidth and window.innerHeight: to get size of mobile device navigator.userAgent : To check if a device is a mobile device function isMobileDevice() { const userAgent = navigator.userAgent; return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent); } function getScreenSize() { const width = window.innerWidth || document.documentElement.client.. 2023. 4. 6.
[Quill] 툴바에 호버 시 tooltip 보여주기 import Quill from "quill"; interface TooltipOptions { tooltips?: { [key: string]: string }; } class TooltipModule { private quill: Quill; private options: TooltipOptions; constructor(quill: Quill, options: TooltipOptions = {}) { this.quill = quill; this.options = options; // Set default tooltips if not provided if (!this.options.tooltips) { this.options.tooltips = { bold: 'Bold', italic:.. 2023. 4. 5.
[Quill] link에 https protocol Sanitization (http/https 붙이기) Search:: quill editor I try to edit embed link, but edit button does not work Modify Link.sanitize const Link = Quill.import('formats/link'); const originalSanitize = Link.sanitize; Link.sanitize = function customSanitizeLinkInput(linkValueInput: any) { let val = linkValueInput; if (!/^(https|http?:\/\/)/.test(val)) val = `https://${val}`; return originalSanitize.call(this, val); // reta.. 2023. 4. 5.
[Node] execute command line with argument:: process.argv.slice(2) Search:: node execute with arguments How do I pass command line arguments to a Node.js program? To normalize the arguments like a regular javascript function would receive, I do this in my node.js shell scripts: var args = process.argv.slice(2); Note that the first arg is usually the path to nodejs, and the second arg is the location of the script you're executing. 2023. 1. 13.
How to detect text overflow ellipsis? Search:: how to check if html element is in ellipsis HTML text-overflow ellipsis detection Try this JS function, passing the span element as argument: function isEllipsisActive(e) { return (e.offsetWidth < e.scrollWidth); } @NicolasS.Xu I believe if the element is a span, you might get zeros in these properties. So one solution is to wrap the span in a div which has overflow: hidden and then che.. 2023. 1. 9.
Capitalize first letter ## Capitalize first letter **[How do I make the first letter of a string uppercase in JavaScript?](https://stackoverflow.com/questions/1026069/how-do-i-make-the-first-letter-of-a-string-uppercase-in-javascript)**[Ask Question](https://stackoverflow.com/questions/ask) - simple fastest ```jsx function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } consol.. 2023. 1. 9.
[Javascript] Promise.allSettled vs Promise.all, Promise states Pending Fulfilled Rejected Promise.all vs Promise.allSettled all // All values are non-promises, so the returned promise gets fulfilled const p = Promise.all([1, 2, 3]); // The only input promise is already fulfilled, // so the returned promise gets fulfilled const p2 = Promise.all([1, 2, 3, Promise.resolve(444)]); // One (and the only) input promise is rejected, // so the returned promis.. 2023. 1. 7.
[javascript] Promise vs setTimeout:: why Promise resolved first? Why Promise is resolved before setTimeout? - Event loop, task queue, micro task queue, stack Promise vs setTimeout Promise.resolve schedules a microtask and the setTimeout schedules a macrotask. And the microtasks are executed before running the next macrotask. console.log(1) setTimeout(() => { console.log(3) }); Promise.resolve().then(() => console.log(4)) console.log(7) Interesting question. I.. 2023. 1. 7.
[javascript] how to parse string to number, Number, parseInt, + Number() converts the type whereas parseInt parses the value of input. Number('123'); parseInt('123', 10); +'123'; Parseing string with non-digit character Number('123 asf'); // NaN parseInt('123 asf'); // 123 As you see, parseInt will parse up to the first non-digit character. On the other hand, Number will try to convert the entire string. binary, decimal parseInt('0101'); // 101 parseInt('010.. 2022. 7. 12.