Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fdate

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fdate

Light-weight, faster datetime formatter for modern browsers

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

⏰ fdate

NPM filesize

Light-weight, faster datetime formatter for modern browsers.

fdate is ...

  • formatter of Date
  • 👼 light-weight as a feather (~1kB gzipped!)
  • 🦄 very faster than other datetime libraries (e.g. moment)
  • 🆕 powered by Template literals

Table of Contents

Install

npm i --save fdate
# -- OR --
yarn add fdate

-- OR --

<script src="https://unpkg.com/fdate"></script>

Usage

import fdate from 'fdate';
const render = fdate`${'YYYY'}/${'MM'}/${'DD'}`;
console.log(render(new Date()));
// i18n
const dayOfWeekName = ({ d }) => [...'日月火水木金土'][d];
const render = fdate`${'M'}${'D'}${dayOfWeekName}曜日`;
console.log(render(new Date()));

See examples.

For Webpack

If you use fdate via webpack, please set alias.

{
  resolve: {
    alias: {
      fdate: require.resolve('fdate'),
    },
  },
}

When using at legacy browser (e.g. IE), please setup loader for transpiling.

(However, fdate will be slow at legacy browser. Please consider using other libraries (e.g. fecha, dayjs).

{
  loader: [
    {
      test: /\.js$/,
      exclude: {
        // Pass fdate to babel-loader when building for legacy browser
        include: /(node_modules|bower_components)/,
        exclude: [/node_modules[\//]fdate/],
      },
      use: ['babel-loader'],
    },
  ],
}

Benchmark

See benchmarks for more details.

Basic usage

  • new Date() -> 2000/01/06
Node.js v10.10.0
ops/sec
fdate279,762 ops/sec±1.11%(88 runs sampled)
time-stamp247,083 ops/sec±1.11%(90 runs sampled)
date-fns244,455 ops/sec±1.05%(89 runs sampled)
moment241,140 ops/sec±1.33%(91 runs sampled)
fecha232,466 ops/sec±1.08%(91 runs sampled)
dayjs210,611 ops/sec±0.97%(91 runs sampled)
luxon167,198 ops/sec±1.13%(89 runs sampled)
dateformat96,692 ops/sec±1.05%(86 runs sampled)
Chrome 69.0.3497
ops/sec
fdate573,465 ops/sec±1.42%(60 runs sampled)
time-stamp387,719 ops/sec±2.25%(59 runs sampled)
fecha375,460 ops/sec±0.72%(61 runs sampled)
date-fns342,209 ops/sec±1.25%(61 runs sampled)
moment325,720 ops/sec±1.08%(62 runs sampled)
dayjs244,039 ops/sec±4.33%(59 runs sampled)
luxon167,208 ops/sec±1.36%(60 runs sampled)
dateformat97,894 ops/sec±1.90%(60 runs sampled)
Firefox 62.0.0
ops/sec
fdate1,135,997 ops/sec±2.55%(59 runs sampled)
fecha823,049 ops/sec±3.11%(57 runs sampled)
time-stamp531,863 ops/sec±4.40%(58 runs sampled)
date-fns435,223 ops/sec±3.51%(59 runs sampled)
moment410,513 ops/sec±3.49%(61 runs sampled)
dayjs369,565 ops/sec±2.85%(59 runs sampled)
luxon170,537 ops/sec±2.88%(61 runs sampled)
dateformat63,390 ops/sec±2.26%(63 runs sampled)

Advanced usage

  • new Date() -> 1月6日(木) (written in Japanese)
Node.js v10.10.0
ops/sec
fdate291,909 ops/sec±1.26%(88 runs sampled)
moment258,888 ops/sec±1.62%(89 runs sampled)
fecha245,678 ops/sec±0.99%(93 runs sampled)
date-fns189,735 ops/sec±0.89%(90 runs sampled)
dateformat96,810 ops/sec±0.95%(92 runs sampled)
luxon688 ops/sec±1.18%(85 runs sampled)
Chrome 69.0.3497
ops/sec
fdate536,842 ops/sec±0.82%(65 runs sampled)
fecha394,640 ops/sec±1.58%(62 runs sampled)
moment322,982 ops/sec±1.25%(61 runs sampled)
date-fns254,257 ops/sec±1.00%(63 runs sampled)
dateformat96,633 ops/sec±0.77%(62 runs sampled)
luxon624 ops/sec±1.42%(44 runs sampled)
Firefox 62.0.0
ops/sec
fdate1,208,619 ops/sec±2.43%(63 runs sampled)
fecha827,057 ops/sec±4.89%(57 runs sampled)
moment380,293 ops/sec±3.39%(56 runs sampled)
date-fns317,868 ops/sec±2.57%(61 runs sampled)
dateformat62,233 ops/sec±2.06%(63 runs sampled)
luxon864 ops/sec±2.93%(54 runs sampled)

Bundle size (Webpack)

sizegzipped
time-stamp1.74 KB861 bytes
fdate2.29 KB943 bytes
dateformat3.80 KB1.81 KB
fecha5.50 KB2.18 KB
dayjs7.21 KB2.76 KB
date-fns9.34 KB3.13 KB
moment51.85 KB16.77 KB
luxon60.37 KB18.45 KB

Contribute

PRs accepted.

License

MIT (c) 3846masa

Keywords

FAQs

Package last updated on 19 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc