Giter VIP home page Giter VIP logo

sg-utils's Introduction

sg-utils

JavaScript通用工具类

1、使用实例

JavaScript工具类:util.js用法实例

2、API说明

util.js 文件里面对每个方法的参数做了说明,参照具体方法说明即可。如下:

(function (window) {
    var u = {};

    u.date = {};

    /**
     * @description 获取需要的时间格式
     * @param {Date} time 时间、时间字符串、时间戳
     * @param {String} format 时间格式,默认'YYYY-MM-DD'。如果是'星期WW',则返回(如:'星期日')
     * @return {String} 格式化后的时间
     */
    u.date.format = function (time, format){
        time = time ? new Date(time) : new Date();
        format = format || 'YYYY-MM-DD';
        function tf(i){ return (i < 10 ? '0' : '') + i; }
        return format.replace(/YYYY|MM|DD|hh|mm|ss|WW/g, function(a){
            switch(a){
                case 'YYYY':
                    return tf(time.getFullYear());
                case 'MM':
                    return tf(time.getMonth() + 1);
                case 'DD':
                    return tf(time.getDate());
                case 'mm':
                    return tf(time.getMinutes());
                case 'hh':
                    return tf(time.getHours());
                case 'ss':
                    return tf(time.getSeconds());
                case 'WW':
                    return ['日', '一', '二', '三', '四', '五', '六'][time.getDay()];
            }
        });
    };

    window._util = u;
})(window);

3、npm下载

npm i sg-utils -S

4、github地址

https://github.com/shiguang0116/sg-utils

5、文件说明

sg-utils/
├── example/
│   ├── index.html       util.js用法实例文档
│   └── index.js         util.js的方法调用,可编辑代码,然后在index.html控制台查看输出结果
├── src/
│   ├── util.js         通用工具类,引入该文件即可使用变量_util,及所有方法。建议复制到项目中以便扩展;
│   ├── service.js      服务工具类的基本架构。可复制到项目中以便参考扩展;
│   └── filter.js       过滤器(基于art-template模板)。可复制到项目中以便参考扩展;
└── index.js            项目引用文件

sg-utils's People

Contributors

shiguang0116 avatar

Stargazers

小隆 avatar  avatar  avatar chokees avatar xiaowiba avatar DD avatar dongshenggit1 avatar Continue avatar  avatar  avatar  avatar 糖果 avatar  avatar  avatar Wish avatar  avatar  avatar lifeng avatar zssjs avatar DeanHan avatar  avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.