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

formatjs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

formatjs

JavaScript date format tester.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.1K
decreased by-27.69%
Maintainers
1
Weekly downloads
 
Created
Source

formatjs

JavaScript date format tester.

Build Status

Very lightweight (~2k min & gzip) utility function for testing if the string matches the date format. It has only one public function test which takes 2 parameters (string and format|formats) and returns true if string matches or false if it doesn't.

See the example below:

test('12/04', 'YYYY/MM');   // false, doesn't match
test('2012/04', 'YYYY/MM'); // true, match

You can pass multiple formats at once:

test('12/04', ['YYYY/MM', 'YYYY/MM/DD']);   // false, doesn't match
test('2012/04', ['YYYY/MM', 'YYYY/MM/DD']); // true, match

Available format tokens

                Token

Month           M           1 2              ... 11 12
                Mo	        1st 2nd          ... 11th 12th
                MM	        01 02            ... 11 12
                MMM	        Jan Feb          ... Nov Dec
                MMMM	    January February ... November December
Day of Month    D	        1 2              ... 30 30
                Do	        1st 2nd          ... 30th 31st
                DD	        01 02            ... 30 31
Day of Year     DDD	        1 2              ... 364 365
                DDDo	    1st 2nd          ... 364th 365th
                DDDD	    001 002          ... 364 365
Day of Week     d	        0 1              ... 5 6
                do	        0th 1st          ... 5th 6th
                ddd	        Sun Mon          ... Fri Sat
                dddd	    Sunday Monday    ... Friday Saturday
Week of Year    w	        1 2              ... 52 53
                wo	        1st 2nd          ... 52nd 53rd
                ww	        01 02            ... 52 53
Year            YY	        70 71            ... 29 30
                YYYY	    1970 1971        ... 2029 2030
Hour            H	        0 1              ... 22 23
                HH	        00 01            ... 22 23
                h	        1 2              ... 11 12
                hh	        01 02            ... 11 12
Minute          m	        0 1              ... 58 59
                mm	        00 01            ... 58 59
Second          s	        0 1              ... 58 59
                ss	        00 01            ... 58 59

Getting Started

On the server

Install the module with: npm install formatjs

var FormatJS = require('formatjs');
var format = new FormatJS();
format.test('12/04', 'YYYY/MM');   // false
format.test('2012/04', 'YYYY/MM'); // true

In the browser

Download the production version or the development version.

In your web page:

<script src="dist/formatjs.min.js"></script>
<script>
var format = new FormatJS();
format.test('12/04', 'YYYY/MM');   // false
format.test('2012/04', 'YYYY/MM'); // true
</script>

In your web page using AMD loader:

<script>
require(['FormatJS'], function(FormatJS) {
    var format = new FormatJS();
    format.test('12/04', 'YYYY/MM');   // false
    format.test('2012/04', 'YYYY/MM'); // true
});
</script>

Contributing

Install Node.js.
Install CoffeeScript with: npm install -g coffee-script.
Install grunt with npm install -g grunt.
Install dependencies with: npm install.

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Test your code using grunt.

Also, please don't edit files in the "dist" subdirectory as they are generated via grunt. You'll find source code in the "src" subdirectory!

License

Copyright (c) 2012 nowamasa
Licensed under the MIT license.

Keywords

FAQs

Package last updated on 04 Jul 2012

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