Comparing version 0.8.30 to 0.8.31
@@ -10,3 +10,5 @@ 'use strict'; | ||
var PromiseLib = Promise; | ||
var utilsDate = require('./date'); | ||
/** | ||
@@ -118,154 +120,2 @@ * @desc: 模拟sleep. | ||
/** | ||
* @desc: 获取时间的string. | ||
* @param time: ms. | ||
* @param fmt: 格式化, 默认为 'HH:mm:ss' | ||
* 年(y)、月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) | ||
* 'yyyy-MM-dd hh:mm:ss.S' ==> 2006-07-02 08:09:04.423 | ||
* 'yyyy-MM-dd E HH:mm:ss' ==> 2009-03-10 星期二 20:09:04 | ||
* 'yyyy-M-d h:m:s.S' ==> 2006-7-2 8:9:4.18 | ||
* @param weekFmt: 星期的文字格式, 默认为 {'0':'星期天', '1': '星期一', ..., '6':'星期六'} | ||
* @return: string. | ||
*/ | ||
function getTimeString(time, fmt, weekFmt) | ||
{ | ||
if (typeof time !== "number") | ||
return ""; | ||
fmt = fmt || 'HH:mm:ss'; | ||
var t = new Date(time); | ||
var o = { | ||
"M+" : t.getMonth()+1, //月份 | ||
"d+" : t.getDate(), //日 | ||
"h+" : t.getHours()%12 == 0 ? 12 : t.getHours()%12, //小时 | ||
"H+" : t.getHours(), //小时 | ||
"m+" : t.getMinutes(), //分 | ||
"s+" : t.getSeconds(), //秒 | ||
"q+" : Math.floor((t.getMonth()+3)/3), //季度 | ||
"S" : t.getMilliseconds() //毫秒 | ||
}; | ||
var week = weekFmt || { | ||
"0" : "星期天", | ||
"1" : "星期一", | ||
"2" : "星期二", | ||
"3" : "星期三", | ||
"4" : "星期四", | ||
"5" : "星期五", | ||
"6" : "星期六", | ||
}; | ||
if(/(y+)/.test(fmt)){ | ||
fmt=fmt.replace(RegExp.$1, (t.getFullYear()+"").substr(4 - RegExp.$1.length)); | ||
} | ||
if(/(E+)/.test(fmt)){ | ||
fmt=fmt.replace(RegExp.$1, week[t.getDay()+""]); | ||
} | ||
for(var k in o){ | ||
if(new RegExp("("+ k +")").test(fmt)){ | ||
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); | ||
} | ||
} | ||
return fmt; | ||
}; | ||
exports.getTimeString = getTimeString; | ||
/** | ||
* @desc: 获取指定时间距离现在的时间描述. | ||
* 例如, 昨天, 1小时前等. | ||
* @param time: ms. 小于当前时间, 大于当前时间将显示为 '刚刚'; | ||
* @param strFmt: 需要显示的文字. | ||
* 默认为 { | ||
* now: '刚刚', // 3秒钟以内将显示此信息. | ||
* second: '秒前', | ||
* minute: '分钟前', | ||
* hour: '小时前', | ||
* day_yesterday: '昨天', | ||
* day: '天前', | ||
* month: '个月前', // 6个月内将显示此信息. | ||
* time: 'yyyy-M-d h:m:s' // 超过6个月将使用此格式格式化时间 | ||
* } | ||
* @return: string. | ||
*/ | ||
exports.getTimeStringFromNow = function(time, strFmt) | ||
{ | ||
strFmt = strFmt || {}; | ||
strFmt.now = strFmt.now || '刚刚'; | ||
strFmt.second = strFmt.second || '秒前'; | ||
strFmt.minute = strFmt.minute || '分钟前'; | ||
strFmt.hour = strFmt.hour || '小时前'; | ||
strFmt.day_yesterday = strFmt.day_yesterday || '昨天'; | ||
strFmt.day = strFmt.day || '天前'; | ||
strFmt.month = strFmt.month || '个月前'; | ||
strFmt.time = strFmt.time || 'yyyy-M-d h:m:s'; | ||
var now = Math.ceil(Date.now()/1000); | ||
time = Math.ceil(time/1000); | ||
if (now > time) | ||
{ | ||
var s = now - time; | ||
if (s < 3) { | ||
return strFmt.now; | ||
} | ||
if (s < 60) { | ||
return s.toString()+strFmt.second; | ||
} | ||
if (s < 60*60) { | ||
return Math.ceil(s/60).toString()+strFmt.minute; | ||
} | ||
if (s < 60*60*24) { | ||
return Math.ceil(s/60/60).toString()+strFmt.hour; | ||
} | ||
if (s < 60*60*24*30) { | ||
var dNow = new Date(now*1000); | ||
dNow.setHours(0, 0, 1); | ||
if (dNow.getTime()-time <= 60*60*24) { | ||
return strFmt.day_yesterday; | ||
} | ||
return Math.ceil(s/60/60/24).toString()+strFmt.day; | ||
} | ||
if (s < 60*60*24*30*6) { | ||
return Math.ceil(s/60/60/24/30).toString()+strFmt.month; | ||
} | ||
return getTimeString(time, strFmt.time); | ||
} | ||
return strFmt.now; | ||
} | ||
/** | ||
* @desc: getDate('2012-05-09') | ||
* @return: Date. | ||
*/ | ||
exports.getDate = function(strDate) { | ||
var date = new Date( | ||
parseInt(strDate.substr(0, 4)), | ||
parseInt(strDate.substr(5, 2), 10)-1, | ||
parseInt(strDate.substr(8, 2))); | ||
return date; | ||
} | ||
/** | ||
* @desc: getDate2('20120509') | ||
* @return: Date. | ||
*/ | ||
exports.getDate2 = function(strDate) { | ||
var date = new Date( | ||
parseInt(strDate.substr(0, 4)), | ||
parseInt(strDate.substr(4, 2), 10)-1, | ||
parseInt(strDate.substr(6, 2))); | ||
return date; | ||
} | ||
/** | ||
* @desc: 合并多个map. | ||
@@ -299,1 +149,8 @@ * @return: {} | ||
/** | ||
* date. | ||
*/ | ||
exports.getTimeString = utilsDate.getTimeString; | ||
exports.getTimeStringFromNow = utilsDate.getTimeStringFromNow; | ||
exports.getDate = utilsDate.getDate; | ||
exports.getDate2 = utilsDate.getDate2; |
@@ -11,4 +11,4 @@ | ||
var elems; | ||
var tag = 0; // 0-tag, 1-id, 2-class, 3-name. | ||
var nametag; | ||
var tag = 0; // 0-tag, 1-id, 2-class. | ||
var nameattr, nameattrVal; | ||
@@ -18,2 +18,3 @@ // :checked, :disabled | ||
name = selector[0]; | ||
name = stringUtils.trim(name); | ||
selector = selector[1]; | ||
@@ -25,2 +26,17 @@ if (selector) { | ||
} | ||
// attri. | ||
if (name.indexOf('[') > 0) { | ||
var iblace = name.indexOf('['); | ||
nameattr = name.substring(iblace+1, name.length-1); | ||
nameattr = nameattr.split('='); | ||
if (nameattr.length != 2) { | ||
throw new Error('Syntax error, unrecognized expression: ' + name); | ||
} | ||
nameattrVal = nameattr[1]; | ||
if (nameattrVal.indexOf('\'') >= 0 || nameattrVal.indexOf('"') >= 0) | ||
nameattrVal = nameattrVal.substring(1, nameattrVal.length-1); | ||
nameattr = nameattr[0]; | ||
name = name.substr(0, iblace); | ||
} | ||
@@ -35,16 +51,2 @@ if (name[0] == '.') { | ||
} | ||
else if (name.indexOf('[') > 0) { | ||
tag = 3; | ||
var iblace = name.indexOf('['); | ||
nametag = name.substring(iblace+1, name.length-1); | ||
name = name.substr(0, iblace); | ||
if (name !== 'input') { | ||
throw new Error('only support `input[name=xxx]` selector'); | ||
} | ||
nametag = nametag.split('='); | ||
if (nametag.length != 2 || nametag[0] != 'name') { | ||
throw new Error('only support `input[name=xxx]` selector'); | ||
} | ||
nametag = nametag[1].substr(1, nametag[1].length-2); | ||
} | ||
@@ -63,6 +65,14 @@ if (!parentNodes || parentNodes.length == 0) { | ||
} | ||
else { | ||
elems = window.document.getElementsByName(nametag); | ||
} | ||
// attrvalue. | ||
if (nameattr) { | ||
var tt_elems = elems; | ||
elems = []; | ||
for (var i = 0; i < tt_elems.length; i++) { | ||
if (tt_elems[i].getAttribute(nameattr) === nameattrVal) { | ||
elems.push(tt_elems[i]); | ||
} | ||
} | ||
} // if. | ||
if (selector) { | ||
@@ -113,2 +123,9 @@ var tt_elems = elems; | ||
// attrvalue. | ||
if (add && nameattr) { | ||
if (node[j].getAttribute(nameattr) !== nameattrVal) { | ||
add = false; | ||
} | ||
} | ||
if (add) { | ||
@@ -133,8 +150,2 @@ if (2 == tag) { | ||
} | ||
else { | ||
if (node[j].nodeName.toUpperCase() == 'INPUT' && node[j].getAttribute('name') == nametag) { | ||
elems.push(node[j]); | ||
continue; | ||
} | ||
} | ||
} // if. | ||
@@ -141,0 +152,0 @@ |
@@ -52,2 +52,3 @@ | ||
febs.date = require('./date'); | ||
febs.utils = require('./utils'); | ||
@@ -54,0 +55,0 @@ febs.string = require('./string'); |
@@ -75,2 +75,3 @@ febs 库是一些常用的工具的合集; | ||
- [dom](#dom) | ||
- [date](#date) | ||
- [utils](#utils) | ||
@@ -129,2 +130,101 @@ - [string](#string) | ||
# date | ||
date库包含了一些常用的时间操作库, 如验证时间对象是否有效等. | ||
```js | ||
/** | ||
* @desc: 判断是否是有效时间. | ||
*/ | ||
febs.date.isValidate(date: Date): boolean; | ||
/** | ||
* @desc: 获取时间的string. | ||
* @param time: ms. | ||
* @param fmt: 格式化, 默认为 'HH:mm:ss' | ||
* 年(y)、月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) | ||
* 'yyyy-MM-dd hh:mm:ss.S' ==> 2006-07-02 08:09:04.423 | ||
* 'yyyy-MM-dd E HH:mm:ss' ==> 2009-03-10 星期二 20:09:04 | ||
* 'yyyy-M-d h:m:s.S' ==> 2006-7-2 8:9:4.18 | ||
* @param weekFmt: 星期的文字格式, 默认为 {'0':'星期天', '1': '星期一', ..., '6':'星期六'} | ||
* @return: string. | ||
*/ | ||
febs.date.getTimeString(time: number, fmt: string, weekFmt: WeekFmt): string; | ||
/** | ||
* @desc: 获取时间的协调世界时间 string. | ||
* @param time: ms. (本地时间) | ||
* @param fmt: 格式化, 默认为 'HH:mm:ss' | ||
* 年(y)、月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) | ||
* 'yyyy-MM-dd hh:mm:ss.S' ==> 2006-07-02 08:09:04.423 | ||
* 'yyyy-MM-dd E HH:mm:ss' ==> 2009-03-10 星期二 20:09:04 | ||
* 'yyyy-M-d h:m:s.S' ==> 2006-7-2 8:9:4.18 | ||
* @param weekFmt: 星期的文字格式, 默认为 {'0':'星期天', '1': '星期一', ..., '6':'星期六'} | ||
* @return: string. | ||
*/ | ||
febs.date.getTimeStringUTC(timeUTC: number, fmt: string, weekFmt: WeekFmt): string; | ||
/** | ||
* @desc: 获取指定时间距离现在的时间描述. | ||
* 例如, 昨天, 1小时前等. | ||
* @param time: ms. 小于当前时间, 大于当前时间将显示为 '刚刚'; | ||
* @param strFmt: 需要显示的文字. | ||
* 默认为 { | ||
* now: '刚刚', // 3秒钟以内将显示此信息. | ||
* second: '秒前', | ||
* minute: '分钟前', | ||
* hour: '小时前', | ||
* day_yesterday: '昨天', | ||
* day: '天前', | ||
* month: '个月前', // 6个月内将显示此信息. | ||
* time: 'yyyy-M-d h:m:s' // 超过6个月将使用此格式格式化时间 | ||
* } | ||
* @return: string. | ||
*/ | ||
febs.date.getTimeStringFromNow(time: number, strFmt: string): string; | ||
/** | ||
* @desc: getDate('2012-05-09') | ||
* @return: Date. | ||
*/ | ||
febs.date.getDate(strDate: string): Date | ||
/** | ||
* @desc: 通过世界时间获取date. getDateUTC('2012-05-09') | ||
* @param strDateUTC: 世界日期字符串. '2012-05-09' | ||
* @return: Date. | ||
*/ | ||
febs.date.getDateUTC(strDateUTC: string): Date; | ||
/** | ||
* @desc: getDate2('20120509') | ||
* @return: Date. | ||
*/ | ||
febs.date.getDate2(strDate: string): Date; | ||
/** | ||
* @desc: 通过世界时间获取date. getDate2UTC('20120509') | ||
* @param strDateUTC: 世界日期字符串. '20120509' | ||
* @return: Date. | ||
*/ | ||
febs.date.getDate2UTC(strDateUTC: string): Date; | ||
/** | ||
* @desc: 通过世界时间获取date. getTimeUTC('2012-05-09 11:10:12') | ||
* @param strTimeUTC: 世界时间字符串. '2012-05-09 11:10:12' | ||
* @return: Date. | ||
*/ | ||
febs.date.getTimeUTC(strTimeUTC: string): Date; | ||
/** | ||
* @desc: 通过世界时间获取date. getTime2UTC('20120509111012') | ||
* @param strTimeUTC: 世界日期字符串. '20120509111012' | ||
* @return: Date. | ||
*/ | ||
febs.date.getTime2UTC(strTimeUTC: string): Date; | ||
``` | ||
# utils | ||
@@ -131,0 +231,0 @@ |
@@ -9,4 +9,4 @@ // Type definitions for febs | ||
export function requestAnimationFrame(cb:(tm:number)=>void):any; | ||
export function cancelAnimationFrame(timer:any):void; | ||
export function requestAnimationFrame(cb: (tm: number) => void): any; | ||
export function cancelAnimationFrame(timer: any): void; | ||
} | ||
@@ -37,2 +37,99 @@ | ||
// | ||
// date. | ||
export namespace date { | ||
/** | ||
* @desc: 判断是否是有效时间. | ||
*/ | ||
function isValidate(date: Date): boolean; | ||
/** | ||
* @desc: 获取时间的string. | ||
* @param time: ms. | ||
* @param fmt: 格式化, 默认为 'HH:mm:ss' | ||
* 年(y)、月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) | ||
* 'yyyy-MM-dd hh:mm:ss.S' ==> 2006-07-02 08:09:04.423 | ||
* 'yyyy-MM-dd E HH:mm:ss' ==> 2009-03-10 星期二 20:09:04 | ||
* 'yyyy-M-d h:m:s.S' ==> 2006-7-2 8:9:4.18 | ||
* @param weekFmt: 星期的文字格式, 默认为 {'0':'星期天', '1': '星期一', ..., '6':'星期六'} | ||
* @return: string. | ||
*/ | ||
function getTimeString(time: number, fmt: string, weekFmt: WeekFmt): string; | ||
/** | ||
* @desc: 获取指定时间距离现在的时间描述. | ||
* 例如, 昨天, 1小时前等. | ||
* @param time: ms. 小于当前时间, 大于当前时间将显示为 '刚刚'; | ||
* @param strFmt: 需要显示的文字. | ||
* 默认为 { | ||
* now: '刚刚', // 3秒钟以内将显示此信息. | ||
* second: '秒前', | ||
* minute: '分钟前', | ||
* hour: '小时前', | ||
* day_yesterday: '昨天', | ||
* day: '天前', | ||
* month: '个月前', // 6个月内将显示此信息. | ||
* time: 'yyyy-M-d h:m:s' // 超过6个月将使用此格式格式化时间 | ||
* } | ||
* @return: string. | ||
*/ | ||
function getTimeStringFromNow(time: number, strFmt: string): string; | ||
/** | ||
* @desc: getDate('2012-05-09') | ||
* @return: Date. | ||
*/ | ||
function getDate(strDate: string): Date | ||
/** | ||
* @desc: getDate2('20120509') | ||
* @return: Date. | ||
*/ | ||
function getDate2(strDate: string): Date; | ||
/** | ||
* @desc: 获取时间的协调世界时间 string. | ||
* @param time: ms. (本地时间) | ||
* @param fmt: 格式化, 默认为 'HH:mm:ss' | ||
* 年(y)、月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) | ||
* 'yyyy-MM-dd hh:mm:ss.S' ==> 2006-07-02 08:09:04.423 | ||
* 'yyyy-MM-dd E HH:mm:ss' ==> 2009-03-10 星期二 20:09:04 | ||
* 'yyyy-M-d h:m:s.S' ==> 2006-7-2 8:9:4.18 | ||
* @param weekFmt: 星期的文字格式, 默认为 {'0':'星期天', '1': '星期一', ..., '6':'星期六'} | ||
* @return: string. | ||
*/ | ||
function getTimeStringUTC(timeUTC: number, fmt: string, weekFmt: WeekFmt): string; | ||
/** | ||
* @desc: 通过世界时间获取date. getDateUTC('2012-05-09') | ||
* @param strDateUTC: 世界日期字符串. '2012-05-09' | ||
* @return: Date. | ||
*/ | ||
function getDateUTC(strDateUTC: string): Date; | ||
/** | ||
* @desc: 通过世界时间获取date. getDate2UTC('20120509') | ||
* @param strDateUTC: 世界日期字符串. '20120509' | ||
* @return: Date. | ||
*/ | ||
function getDate2UTC(strDateUTC: string): Date; | ||
/** | ||
* @desc: 通过世界时间获取date. getTimeUTC('2012-05-09 11:10:12') | ||
* @param strTimeUTC: 世界时间字符串. '2012-05-09 11:10:12' | ||
* @return: Date. | ||
*/ | ||
function getTimeUTC(strTimeUTC: string): Date; | ||
/** | ||
* @desc: 通过世界时间获取date. getTime2UTC('20120509111012') | ||
* @param strTimeUTC: 世界日期字符串. '20120509111012' | ||
* @return: Date. | ||
*/ | ||
function getTime2UTC(strTimeUTC: string): Date; | ||
} | ||
// | ||
// utils. | ||
@@ -183,4 +280,4 @@ export namespace utils { | ||
function trim(str: string) : string; | ||
function trim(str: string): string; | ||
/** | ||
@@ -190,3 +287,3 @@ * @desc: 对字符串中的 <> 标签进行转义为 <, > | ||
*/ | ||
function escapeHtml(str:string): string; | ||
function escapeHtml(str: string): string; | ||
} | ||
@@ -218,3 +315,3 @@ | ||
*/ | ||
function md5(str: string|Buffer): string; | ||
function md5(str: string | Buffer): string; | ||
@@ -225,3 +322,3 @@ /** | ||
*/ | ||
function sha1(str: string|Buffer): string; | ||
function sha1(str: string | Buffer): string; | ||
@@ -233,3 +330,3 @@ /** | ||
*/ | ||
function base64_encode(arrByte: Array<number>|Buffer): string; | ||
function base64_encode(arrByte: Array<number> | Buffer): string; | ||
/** | ||
@@ -251,3 +348,3 @@ * @desc: base64解码. | ||
*/ | ||
function ajax(cfg:any):{abort:()=>void} | ||
function ajax(cfg: any): { abort: () => void } | ||
@@ -280,12 +377,12 @@ /** | ||
function fetch(url: string, option: { | ||
method?:string, // 请求方法 get, post, delete 等. | ||
mode?:string|'no-cors'|'cors'|'same-origin', // 'no-cors', 'same-origin'等; (可忽略) | ||
headers?:any, // 请求header, 例如: | ||
// { | ||
// "Content-Type": "application/json", | ||
// "Accept": 'application/json', | ||
// } | ||
body?:string, // 请求内容. | ||
timeout?:number, // 超时 (ms), 默认为5000, | ||
credentials?:'include'|null|undefined, // 携带了credentials='include'则服务器需设置Access-Control-Allow-Credentials | ||
method?: string, // 请求方法 get, post, delete 等. | ||
mode?: string | 'no-cors' | 'cors' | 'same-origin', // 'no-cors', 'same-origin'等; (可忽略) | ||
headers?: any, // 请求header, 例如: | ||
// { | ||
// "Content-Type": "application/json", | ||
// "Accept": 'application/json', | ||
// } | ||
body?: string, // 请求内容. | ||
timeout?: number, // 超时 (ms), 默认为5000, | ||
credentials?: 'include' | null | undefined, // 携带了credentials='include'则服务器需设置Access-Control-Allow-Credentials | ||
}): Promise<any>; | ||
@@ -310,12 +407,12 @@ /** | ||
function jsonp(url: string, option: { | ||
method?:string, // 请求方法 get, post, delete 等. | ||
mode?:string|'no-cors'|'cors'|'same-origin', // 'no-cors', 'same-origin'等; (可忽略) | ||
headers?:any, // 请求header, 例如: | ||
// { | ||
// "Content-Type": "application/json", | ||
// "Accept": 'application/json', | ||
// } | ||
body?:string, // 请求内容. | ||
timeout?:number, // 超时 (ms), 默认为5000, | ||
credentials?:'include'|null|undefined, // 携带了credentials='include'则服务器需设置Access-Control-Allow-Credentials | ||
method?: string, // 请求方法 get, post, delete 等. | ||
mode?: string | 'no-cors' | 'cors' | 'same-origin', // 'no-cors', 'same-origin'等; (可忽略) | ||
headers?: any, // 请求header, 例如: | ||
// { | ||
// "Content-Type": "application/json", | ||
// "Accept": 'application/json', | ||
// } | ||
body?: string, // 请求内容. | ||
timeout?: number, // 超时 (ms), 默认为5000, | ||
credentials?: 'include' | null | undefined, // 携带了credentials='include'则服务器需设置Access-Control-Allow-Credentials | ||
}): Promise<any>; | ||
@@ -339,10 +436,10 @@ } | ||
*/ | ||
constructor(selector?:SELECTOR); | ||
constructor(selector?: SELECTOR); | ||
get(index:number): any; | ||
get(index: number): any; | ||
/** | ||
* @desc: hasClass | ||
*/ | ||
hasClass( cName:string ): boolean; | ||
hasClass(cName: string): boolean; | ||
@@ -352,3 +449,3 @@ /** | ||
*/ | ||
addClass( cName:string ): dom; | ||
addClass(cName: string): dom; | ||
@@ -358,3 +455,3 @@ /** | ||
*/ | ||
removeClass( cName:string ): dom; | ||
removeClass(cName: string): dom; | ||
@@ -364,3 +461,3 @@ /** | ||
*/ | ||
toggleClass( cName:string ): dom; | ||
toggleClass(cName: string): dom; | ||
@@ -375,3 +472,3 @@ /** | ||
*/ | ||
append(selector?:SELECTOR): dom; | ||
append(selector?: SELECTOR): dom; | ||
@@ -381,3 +478,3 @@ /** | ||
*/ | ||
appendTo(selector?:SELECTOR): dom; | ||
appendTo(selector?: SELECTOR): dom; | ||
@@ -387,3 +484,3 @@ /** | ||
*/ | ||
prepend(selector?:SELECTOR): dom; | ||
prepend(selector?: SELECTOR): dom; | ||
@@ -393,3 +490,3 @@ /** | ||
*/ | ||
prependTo(selector?:SELECTOR): dom; | ||
prependTo(selector?: SELECTOR): dom; | ||
@@ -399,3 +496,3 @@ /** | ||
*/ | ||
before(selector?:SELECTOR): dom; | ||
before(selector?: SELECTOR): dom; | ||
@@ -405,3 +502,3 @@ /** | ||
*/ | ||
insertBefore(selector?:SELECTOR): dom; | ||
insertBefore(selector?: SELECTOR): dom; | ||
@@ -411,3 +508,3 @@ /** | ||
*/ | ||
after(selector?:SELECTOR): dom; | ||
after(selector?: SELECTOR): dom; | ||
@@ -417,3 +514,3 @@ /** | ||
*/ | ||
insertAfter(selector?:SELECTOR): dom; | ||
insertAfter(selector?: SELECTOR): dom; | ||
@@ -423,3 +520,3 @@ /** | ||
*/ | ||
attr(attrName:any, value:any): string; | ||
attr(attrName: any, value: any): string; | ||
@@ -429,3 +526,3 @@ /** | ||
*/ | ||
removeAttr(name:any): dom; | ||
removeAttr(name: any): dom; | ||
@@ -440,3 +537,3 @@ /** | ||
*/ | ||
html(v:string): string; | ||
html(v: string): string; | ||
@@ -447,3 +544,3 @@ | ||
*/ | ||
text(v:string): string; | ||
text(v: string): string; | ||
@@ -453,3 +550,3 @@ /** | ||
*/ | ||
val(v:string): string; | ||
val(v: string): string; | ||
@@ -460,12 +557,12 @@ | ||
*/ | ||
css(name:string, value:string): string; | ||
css(name: string, value: string): string; | ||
/** | ||
* html. | ||
*/ | ||
parent(selector?:SELECTOR) : dom; | ||
parents(selector?:SELECTOR) : dom; | ||
children(selector?:SELECTOR) : dom; | ||
prev(selector?:SELECTOR) : dom; | ||
next(selector?:SELECTOR) : dom; | ||
parent(selector?: SELECTOR): dom; | ||
parents(selector?: SELECTOR): dom; | ||
children(selector?: SELECTOR): dom; | ||
prev(selector?: SELECTOR): dom; | ||
next(selector?: SELECTOR): dom; | ||
@@ -476,5 +573,5 @@ | ||
*/ | ||
on(eventname:string, foo:any): dom; | ||
bind(eventname:string, foo:any): dom; | ||
live(eventname:string, foo:any): dom; | ||
on(eventname: string, foo: any): dom; | ||
bind(eventname: string, foo: any): dom; | ||
live(eventname: string, foo: any): dom; | ||
@@ -484,5 +581,5 @@ /** | ||
*/ | ||
off(eventname:string, foo?:any): dom; | ||
unbind(eventname:string, foo?:any): dom; | ||
die(eventname:string, foo?:any): dom; | ||
off(eventname: string, foo?: any): dom; | ||
unbind(eventname: string, foo?: any): dom; | ||
die(eventname: string, foo?: any): dom; | ||
@@ -492,3 +589,3 @@ /** | ||
*/ | ||
one(event:string, f:any): dom; | ||
one(event: string, f: any): dom; | ||
@@ -498,27 +595,27 @@ /** | ||
*/ | ||
trigger(eventname:string, extraParameters?:any): dom; | ||
trigger(eventname: string, extraParameters?: any): dom; | ||
ready(f?:any):dom; | ||
unload(f?:any):dom; | ||
blur(f?:any):dom; | ||
change(f?:any):dom; | ||
click(f?:any):dom; | ||
dblclick(f?:any):dom; | ||
error(f?:any):dom; | ||
keydown(f?:any):dom; | ||
keypress(f?:any):dom; | ||
keyup(f?:any):dom; | ||
load(f?:any):dom; | ||
mousedown(f?:any):dom; | ||
mouseenter(f?:any):dom; | ||
mouseleave(f?:any):dom; | ||
mousemove(f?:any):dom; | ||
mouseout(f?:any):dom; | ||
mouseover(f?:any):dom; | ||
mouseup(f?:any):dom; | ||
scroll(f?:any):dom; | ||
select(f?:any):dom; | ||
submit(f?:any):dom; | ||
ready(f?: any): dom; | ||
unload(f?: any): dom; | ||
blur(f?: any): dom; | ||
change(f?: any): dom; | ||
click(f?: any): dom; | ||
dblclick(f?: any): dom; | ||
error(f?: any): dom; | ||
keydown(f?: any): dom; | ||
keypress(f?: any): dom; | ||
keyup(f?: any): dom; | ||
load(f?: any): dom; | ||
mousedown(f?: any): dom; | ||
mouseenter(f?: any): dom; | ||
mouseleave(f?: any): dom; | ||
mousemove(f?: any): dom; | ||
mouseout(f?: any): dom; | ||
mouseover(f?: any): dom; | ||
mouseup(f?: any): dom; | ||
scroll(f?: any): dom; | ||
select(f?: any): dom; | ||
submit(f?: any): dom; | ||
[index:number]: dom; | ||
[index: number]: dom; | ||
} | ||
@@ -532,3 +629,3 @@ | ||
*/ | ||
function getViewPort():{width:number, height:number}; | ||
function getViewPort(): { width: number, height: number }; | ||
@@ -539,3 +636,3 @@ /** | ||
*/ | ||
function getDocumentPort():{width:number, height:number}; | ||
function getDocumentPort(): { width: number, height: number }; | ||
@@ -546,3 +643,3 @@ /** | ||
*/ | ||
function getDocumentOffset():{top:number, left:number}; | ||
function getDocumentOffset(): { top: number, left: number }; | ||
@@ -553,3 +650,3 @@ /** | ||
*/ | ||
function getElementOffset(e:any):{left:number, top:number}; | ||
function getElementOffset(e: any): { left: number, top: number }; | ||
} | ||
@@ -559,10 +656,10 @@ | ||
export function $(n:any):dom; | ||
export function $(n: any): dom; | ||
export namespace $ { | ||
var fn:any; | ||
var fn: any; | ||
function extend(...args:any[]):dom; | ||
function extend(deep: true, ...args:any[]):dom; | ||
function extend(...args: any[]): dom; | ||
function extend(deep: true, ...args: any[]): dom; | ||
} | ||
} |
@@ -86,3 +86,3 @@ { | ||
"name": "febs", | ||
"version": "0.8.30" | ||
"version": "0.8.31" | ||
} |
100
README.md
@@ -69,2 +69,3 @@ febs 库是一些常用的工具的合集; | ||
- 通用于客户端与服务端的库如下 | ||
- [date](#date) | ||
- [utils](#utils) | ||
@@ -103,3 +104,102 @@ - [string](#string) | ||
# date | ||
date库包含了一些常用的时间操作库, 如验证时间对象是否有效等. | ||
```js | ||
/** | ||
* @desc: 判断是否是有效时间. | ||
*/ | ||
febs.date.isValidate(date: Date): boolean; | ||
/** | ||
* @desc: 获取时间的string. | ||
* @param time: ms. | ||
* @param fmt: 格式化, 默认为 'HH:mm:ss' | ||
* 年(y)、月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) | ||
* 'yyyy-MM-dd hh:mm:ss.S' ==> 2006-07-02 08:09:04.423 | ||
* 'yyyy-MM-dd E HH:mm:ss' ==> 2009-03-10 星期二 20:09:04 | ||
* 'yyyy-M-d h:m:s.S' ==> 2006-7-2 8:9:4.18 | ||
* @param weekFmt: 星期的文字格式, 默认为 {'0':'星期天', '1': '星期一', ..., '6':'星期六'} | ||
* @return: string. | ||
*/ | ||
febs.date.getTimeString(time: number, fmt: string, weekFmt: WeekFmt): string; | ||
/** | ||
* @desc: 获取时间的协调世界时间 string. | ||
* @param time: ms. (本地时间) | ||
* @param fmt: 格式化, 默认为 'HH:mm:ss' | ||
* 年(y)、月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) | ||
* 'yyyy-MM-dd hh:mm:ss.S' ==> 2006-07-02 08:09:04.423 | ||
* 'yyyy-MM-dd E HH:mm:ss' ==> 2009-03-10 星期二 20:09:04 | ||
* 'yyyy-M-d h:m:s.S' ==> 2006-7-2 8:9:4.18 | ||
* @param weekFmt: 星期的文字格式, 默认为 {'0':'星期天', '1': '星期一', ..., '6':'星期六'} | ||
* @return: string. | ||
*/ | ||
febs.date.getTimeStringUTC(timeUTC: number, fmt: string, weekFmt: WeekFmt): string; | ||
/** | ||
* @desc: 获取指定时间距离现在的时间描述. | ||
* 例如, 昨天, 1小时前等. | ||
* @param time: ms. 小于当前时间, 大于当前时间将显示为 '刚刚'; | ||
* @param strFmt: 需要显示的文字. | ||
* 默认为 { | ||
* now: '刚刚', // 3秒钟以内将显示此信息. | ||
* second: '秒前', | ||
* minute: '分钟前', | ||
* hour: '小时前', | ||
* day_yesterday: '昨天', | ||
* day: '天前', | ||
* month: '个月前', // 6个月内将显示此信息. | ||
* time: 'yyyy-M-d h:m:s' // 超过6个月将使用此格式格式化时间 | ||
* } | ||
* @return: string. | ||
*/ | ||
febs.date.getTimeStringFromNow(time: number, strFmt: string): string; | ||
/** | ||
* @desc: getDate('2012-05-09') | ||
* @return: Date. | ||
*/ | ||
febs.date.getDate(strDate: string): Date | ||
/** | ||
* @desc: 通过世界时间获取date. getDateUTC('2012-05-09') | ||
* @param strDateUTC: 世界日期字符串. '2012-05-09' | ||
* @return: Date. | ||
*/ | ||
febs.date.getDateUTC(strDateUTC: string): Date; | ||
/** | ||
* @desc: getDate2('20120509') | ||
* @return: Date. | ||
*/ | ||
febs.date.getDate2(strDate: string): Date; | ||
/** | ||
* @desc: 通过世界时间获取date. getDate2UTC('20120509') | ||
* @param strDateUTC: 世界日期字符串. '20120509' | ||
* @return: Date. | ||
*/ | ||
febs.date.getDate2UTC(strDateUTC: string): Date; | ||
/** | ||
* @desc: 通过世界时间获取date. getTimeUTC('2012-05-09 11:10:12') | ||
* @param strTimeUTC: 世界时间字符串. '2012-05-09 11:10:12' | ||
* @return: Date. | ||
*/ | ||
febs.date.getTimeUTC(strTimeUTC: string): Date; | ||
/** | ||
* @desc: 通过世界时间获取date. getTime2UTC('20120509111012') | ||
* @param strTimeUTC: 世界日期字符串. '20120509111012' | ||
* @return: Date. | ||
*/ | ||
febs.date.getTime2UTC(strTimeUTC: string): Date; | ||
``` | ||
# utils | ||
@@ -106,0 +206,0 @@ |
@@ -8,2 +8,3 @@ | ||
exports.utils = require('./utils'); | ||
exports.date = require('../browser/libs/date'); | ||
exports.net = require('./net'); | ||
@@ -10,0 +11,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2433668
62
25005
874
4