1.0.5 • Published 1 year ago

juny-tsutil v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

juny-tsutil / Modules

juny-tsutil

Table of contents

Enumerations

Functions

Functions

addDay

addDay(date, day): Date

Date 객체에 대한 날짜 더하기

Parameters

NameTypeDescription
dateDate계산하고자 하는 Date객체
daynumber추가하고자 하는 일수

Returns

Date

계산된 Date 객체

Defined in

date/addDay.ts:9


compareDate

compareDate(date, diff, callback?): boolean

Date 객체를 밀리초 까지의 비교로 같은 시간대인지 판단

Parameters

NameType
dateDate
diffDate
callback?(dateTimestamp: number, diffTimestamp: number) => boolean

Returns

boolean

Example

        expect(
           compareDate(new Date('2024-04-01'), new Date('2024-04-01'))
       ).toEqual(true);

       expect(
           compareDate(new Date('2024-04-01'), new Date('2024-04-02')
       )).toEqual(false);

       expect(
           compareDate(new Date('2024-04-01'), new Date('2024-04-02'),(date, diff) => {
               return date < diff
           })
       ).toEqual(true)

Defined in

date/compareDate.ts:27


fillWord

fillWord(str, length, word?, type?): string

글자수에서 부족한 앞자리를 특정 문자열로 채웁니다.

Parameters

NameTypeDefault valueDescription
strstringundefined소스 문자열
lengthnumberundefined타겟 문자열 갯수
wordstring''-
type-1 | 00-

Returns

string

string

Param

type - 0: 앞자리 채우기, -1: 뒷자리 채우기

Example

const result = fillWord('4',2,'0');
// result = "04"

const result = fillWord('4',2,'0',-1);
// result = "40"

Defined in

str/fillWord.ts:20


getDaysInMonth

getDaysInMonth(year, month): Date[]

특정 년도와 월의 시작일부터 종료일까지의 날짜 배열을 반환합니다.

Parameters

NameTypeDescription
yearnumber년도를 나타내는 숫자
monthnumber월을 나타내는 숫자 (1부터 12까지의 숫자)

Returns

Date[]

해당 년도와 월의 날짜 배열. 예: 'YYYY-MM-DD', 'YYYY-MM-DD', ...

Example

   getDaysInMonth(2024, 4);
    // [2024-04-01 ... 2024-04-30]

Defined in

date/getDaysInMonth.ts:18


getFirstInMonth

getFirstInMonth(year, month): Date

Parameters

NameType
yearnumber
monthnumber

Returns

Date

Defined in

date/getFirstDayInMotth.ts:10


getLastInMonth

getLastInMonth(year, month): Date

특정 년도와 월의 마지막일을 반환합니다.

Parameters

NameTypeDescription
yearnumber년도를 나타내는 숫자
monthnumber월을 나타내는 숫자 (1부터 12까지의 숫자)

Returns

Date

Date

Defined in

date/getLastDayInMotth.ts:9


getPreviousMonthLastDay

getPreviousMonthLastDay(date): Date

get previouse month

Parameters

NameType
dateDate

Returns

Date

previous date

Example

 getPreviouseMonth(
		new Date('2024-04-15') 
 )
 // 2024-03-31

Defined in

date/getPreviousMonthLastDay.ts:16


getPreviousMonthLastSunday

getPreviousMonthLastSunday(year, month): Date[] | []

the last Sunday of the previous month 특정년도의 월 시작일(1)이 일요일이 아닌 경우 이전 달의 마지막 주 일요일까지

Parameters

NameTypeDescription
yearnumber년도를 나타내는 숫자
monthnumber월을 나타내는 숫자 (1부터 12까지의 숫자)

Returns

Date[] | []

Date[] | []

Example

expect(
	getPreviousMonthLastSunday(2024,4)
).toEqual([
	new Date('2024-03-31T00:00:00.000Z')
])

expect(
	getPreviousMonthLastSunday(2024,5)
).toEqual([
	new Date('2024-04-28T00:00:00.000Z'),
		new Date('2024-04-29T00:00:00.000Z'),
		new Date('2024-04-30T00:00:00.000Z'),
])

Defined in

date/getPreviousMonthLastSunday.ts:33


isWeek

isWeek(date, dayOfWeek): boolean

요일 체크 checked is day of week

Parameters

NameType
dateDate
dayOfWeekDayOfWeek

Returns

boolean

boolean

Example

	const date = getFirstInMonth(2024, 4) // MON 2024-04-01T00:00:00.000Z
	isWeek(date,DayOfWeek.TUES); // true

Defined in

date/isWeek.ts:18


removeFirstSegment

removeFirstSegment(str, delimiter): string

Removes the first segment from a string delimited by the specified delimiter.

Parameters

NameTypeDescription
strstringThe input string.
delimiterstringThe delimiter used to split the string into segments.

Returns

string

The modified string with the first segment removed.

Example

 const str1 = 'foo/bar';
 const str2 = '/foo/bar';

 removeFirstSegment(str1,'/'); // /bar
 removeFirstSegment(str1,'/'); // /bar

Defined in

str/removeFirstSegment.ts:17


removeLastSegment

removeLastSegment(str, delimiter): string

Removes the Last segment from a string delimited by the specified delimiter.

Parameters

NameTypeDescription
strstringThe input string.
delimiterstringThe delimiter used to split the string into segments.

Returns

string

The modified string with the first segment removed.

Example

describe('removeLastSegment', ()=>{
    test('should return an remove Last segment',() => {
        expect(
            removeLastSegment('/foo/bar','/')
        ).toEqual('/foo');

        expect(
            removeLastSegment('foo/bar','/')
        ).toEqual('foo');

        expect(
            removeLastSegment('foo/bar/','/')
        ).toEqual('foo/bar');

    })
})

Defined in

str/removeLastSegment.ts:28


subtractDay

subtractDay(date, days): Date

주어진 날짜에서 일 수를 빼는 함수

Parameters

NameTypeDescription
dateDate일 수를 뺄 날짜
daysnumber뺄 일 수

Returns

Date

일 수를 뺀 날짜

Defined in

date/subtractDay.ts:8

1.0.2

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago