Giter Site home page Giter Site logo

moment-lite.js's Introduction

moment-lite.js

一直很喜欢 moment.js,但是它有时候太臃肿了(好比语言包问题),而且不够函数式(moment().add(1, 'days')的副作用...),所以我就写了个非常轻量级的 moment-lite.js

后来同事告诉说已经有一个很好的 moment.js 替代品了:https://date-fns.org/。Well...也没有关系,就当自己练手吧。我设计的 API 跟它们都不太一样。

目标:

  • 好用的 API
  • 无副作用
  • 轻量级

Info

Usage

import moment from 'moment-lite';

const now = moment();
console.log(now.format('YYYY-MM-DD HH:mm:ss'));

APIs

const now = moment();

/**
 * moment.prototype.format
 * 格式化日期
 */
const str = now.format('YYYY-MM-DD');

/**
 * moment.prototype.add(num, unit)
 * 增加日期
 */
const oneMonthLater = now.add(30, 'days');

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.