interface  Date{
    addHours(h:number);
    addMinutes(m:number);
    format(str):string
}

interface String{
    trim():string;
    solrFormat():string;
}

interface Array<T> {
    clear();
    removeByIndex(index:number);
    remove(fn:(t:T)=>boolean);
}

(function(){

    Date.prototype.addHours= function(h:number) {
        this.setTime(this.getTime() + (h*60*60*1000));
        return this;
    } ;
    Date.prototype.addMinutes= function(m:number) {
        this.setTime(this.getTime() + (m*60*1000));
        return this;
    } ;
    Date.prototype.format=function(fmt:string="yyyy-MM-dd hh:mm:ss"):string {
        let date=this;
        if(!date){
            return date;
        }
        if (fmt === undefined || fmt === "" || fmt === null) {
            fmt = "yyyy-MM-dd hh:mm:ss";
        }

        let o = {
            "M+": date.getMonth() + 1,                 //月份
            "d+": date.getDate(),                    //
            "h+": date.getHours(),                   //小时
            "m+": date.getMinutes(),                 //
            "s+": date.getSeconds(),                 //
            "q+": Math.floor((date.getMonth() + 3) / 3), //季度
            "S": date.getMilliseconds()             //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (let 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;
    };
    if(!String.prototype.trim){
        String.prototype.trim=function () {
            return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '')||"";
        }
    }
    String.prototype.solrFormat=function () {
       if(!this){
         return this;
       }
       let str= this.replace(/[\(\)\{\}\[\]\^\*&%#$@!<>?=:'"]/g,"");
       str=this.replace(/-/,"\\-");
       return str.replace(/[\ +]/g,"\\ ")
    };
    Array.prototype.clear=function () {
        this.splice(0,this.length);
    }
    Array.prototype.removeByIndex= function(index:number) {
        this.splice(index,1);
    };
    Array.prototype.remove= function(fn:(t:any)=>boolean) {
        let items = this.filter(fn);
        let that=this;
        items.forEach(function (item) {
            let index = that.indexOf(item);
            this.removeByIndex(index);
        })
    };
})();

 

d.ts  declare file
declare  interface  Date{
    addHours(h:number);
    addMinutes(m:number);
    format(str):string
}

declare interface String{
    trim();
    solrFormat():string;
}

declare interface   Array<T> {
    clear();
    removeByIndex(index:number);
    remove(fn:(t:T)=>boolean);
}

 

posted @ 2017-09-06 15:52 N1900 阅读(264) 评论(0) 推荐(0) 编辑
该文被密码保护。 阅读全文
posted @ 2017-09-05 17:25 N1900 阅读(1) 评论(0) 推荐(0) 编辑
摘要: html ts jquery drag extends 阅读全文
posted @ 2017-09-05 17:14 N1900 阅读(495) 评论(0) 推荐(0) 编辑
摘要: angular.module('app').filter('trustHtml', ($sce) => { return (html) => { if(typeof(html)=="object"){ return html; } return $sce.trustAsHtml(html||""); } }); request({'url'... 阅读全文
posted @ 2017-04-01 18:39 N1900 阅读(254) 评论(0) 推荐(0) 编辑
摘要: Install the latest version of NodeJS from their website (e.g. 6.X.X). Open the Node.js command prompt as administrator. Run: npm cache clean Run: npm 阅读全文
posted @ 2017-03-24 23:35 N1900 阅读(428) 评论(0) 推荐(0) 编辑
摘要: angular.module('app').directive('ScrollTrigger', () => { return { restrict: "A", link:function ($scope,$element,$attrs,$controller) { function debounce(fn, delay) { ... 阅读全文
posted @ 2017-03-15 13:40 N1900 阅读(4196) 评论(0) 推荐(0) 编辑
摘要: function debounce(fn, delay) { // 持久化一个定时器 timer let timer = null; // 闭包函数可以访问 timer return function() { // 通过 'this' 和 'arguments' // 获得函数的作用域和参数 let context = this; let ... 阅读全文
posted @ 2017-03-13 23:40 N1900 阅读(1541) 评论(0) 推荐(0) 编辑
摘要: index.js test.js 运行 阅读全文
posted @ 2016-11-26 23:35 N1900 阅读(451) 评论(0) 推荐(0) 编辑
摘要: function copyTextToClipboard(text) { var copyFrom = $(''); copyFrom.text(text); $('body').append(copyFrom); copyFrom.select(); ... 阅读全文
posted @ 2016-09-26 14:02 N1900 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 效果如下 ally and horifffffffffffffffffffffffffffally. ally and horifffffffffffffffffffffffffffally. ally and horifffffffffffffffffffffffffffally. // <![C 阅读全文
posted @ 2016-07-20 21:48 N1900 阅读(356) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示