개요
이 페이지는 Typescript 언어로 개발하는 프로젝트로 앱/웹을 구현하면서, 검색하여 참고한 사이트 및 정보를 정리해놓았습니다.
참고자료 목록
Typescript 일반
Array가 Empty이거나 undefined, null 체크를 동시에 체크하는 방법
if (array && array.length) {
// array and array.length are truthy
// ⇒ probably OK to process array
}
https://stackoverflow.com/questions/24403732/how-to-check-if-array-is-empty-or-does-not-exist
How to check if array is empty or does not exist?
What's the best way to check if an array is empty or does not exist? Something like this? if(array.length < 1 || array == undefined){ //empty }
stackoverflow.com
숫자 앞에 글자수만큼 0 패딩을 붙이는 쉬운 방법
function addLeadingZeros(num: number, totalLength: number): string {
return String(num).padStart(totalLength, '0');
}
console.log(addLeadingZeros(5, 2)); // 👉️ "05"
https://bobbyhadz.com/blog/typescript-add-leading-zero-to-number
Add Leading Zeros to a Number in TypeScript | bobbyhadz
To add leading zeros to a number in TypeScript, convert the number to a string. Call the `padStart()` method to add zeros to the start of the string. The `padStart` method returns a new string with the specified pad string applied from the start.
bobbyhadz.com
String이 숫자 형식인지 체크하는 방법
function isNumber(value: string | number): boolean
{
return ((value != null) &&
(value !== '') &&
!isNaN(Number(value.toString())));
}
https://stackoverflow.com/questions/23437476/in-typescript-how-to-check-if-a-string-is-numeric
In Typescript, How to check if a string is Numeric
In Typescript, this shows an error saying isNaN accepts only numeric values isNaN('9BX46B6A') and this returns false because parseFloat('9BX46B6A') evaluates to 9 isNaN(parseFloat('9BX46B6A')) ...
stackoverflow.com
특정 변수가 Date 형식인지 체크하는 방법
let x = new Date();
// typeof Date는 object를 반환하므로
// type of x === "string" 이렇게 사용할 수 없다.
if (x instanceof Date) {
// will execute
}
https://masteringjs.io/tutorials/fundamentals/typeof-date
How to Determine if a Variable is a Date
Here's how you can determine if a variable is a date in JavaScript
masteringjs.io
Locale이 적용된 Ordinal Number를 만들 수 있는 함수
function ordinal_suffix_of(i) {
var j = i % 10,
k = i % 100;
if (j == 1 && k != 11) {
return i + "st";
}
if (j == 2 && k != 12) {
return i + "nd";
}
if (j == 3 && k != 13) {
return i + "rd";
}
return i + "th";
}
https://stackoverflow.com/questions/13627308/add-st-nd-rd-and-th-ordinal-suffix-to-a-number
Add st, nd, rd and th (ordinal) suffix to a number
I would like to dynamically generate a string of text based on a current day. So, for example, if it is day 1 then I would like my code to generate = "Its the <dynamic>1*<dynamic string>...
stackoverflow.com
'[DEV] Programming Lang > TypeScript' 카테고리의 다른 글
[Typescript] 이슈 해결 모음 (0) | 2023.01.19 |
---|---|
[RxJs] debounceTime(milsec), distinctUntilChanged(), switchMap(), 실시간 검색 (0) | 2020.11.12 |
[RxJs] unSubscribe() 3가지 기술 (0) | 2020.10.29 |
Typescript 상에서 Object에 Attribute가 존재하는지 체크하는 3가지 방법 (0) | 2020.10.23 |
[ES6] Spread(...) 문법, 비구조화 할당 문법 (0) | 2020.10.23 |
최근댓글