Skip to content
/ dc-utils Public

造一个常用方法库,试水typescript+rollup

License

Notifications You must be signed in to change notification settings

Jiuto/dc-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dc-utils

一个正在完善的常用方法库

时间

示例

import { utils } from "@dc/utils"
utils.formatDate(new Date())

formatDate

formatDate(date: Date): string接受一个Date类型的参数,返回YYYY-MM-DD格式的字符串

getToday

getToday(): string返回YYYY-MM-DD格式的今日日期

getTomorrow

getTomorrow(): string返回YYYY-MM-DD格式的明日日期

getMonthDays

getMonthDays(y: number, m: number): number接受两个number类型的参数表示年份和月份,返回number类型的当月天数

getThisWeek

getThisWeek(): string[]返回['YYYY-MM-DD','YYYY-MM-DD']格式的本周起始和结束日期

getThisMonth

getThisMonth(): string[]返回['YYYY-MM-DD','YYYY-MM-DD']格式的本月起始和结束日期

EventBus事件总线

示例

import { EventBus } from "@dc/utils";

let eventBus = new EventBus();

let fun1 = function () {
    console.log(1)
}

eventBus.addListener("type1",fun1)

eventBus.dispatchListener("type1") // 1

eventBus.removeListener("type1",fun1)

let fun42 = function (v) {
    console.log(v)
}

eventBus.addListener("type2",fun2)

eventBus.dispatchListener("type2","this is a parameter") // this is a parameter

eventBus.removeListener("type2")

addListener

addListener (type:String, cb:Function) 监听事件

dispatchListener

dispatchListener (type:String, params:any) 触发事件

removeListener

removeListener (type:String, cb:Function) 注销事件,cb不传时,注销该事件下所有回调

About

造一个常用方法库,试水typescript+rollup

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published