chai-moment-string

Validates a string to have valid date time format with moment

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
chai-moment-string
001.0.05 years ago5 years agoMinified + gzip package size for chai-moment-string in KB

Readme

chai-moment-string
chai plugin for validating a string with an expected moment format
Build Status Downloads

Usage

Browser

<script src="chai.js"></script>
<script src="chai-moment-string.js"></script>

Server

var chai = require('chai');
chai.use(require('chai-moment-string'));

Assertions

  • momentFormat
  • strict(chained by momentFormat)

momentFormat

// Without locale
expect('2018-01-26').to.momentFormat('YYYY-MM-DD');
// With locale
expect('2012 juillet').to.momentFormat('YYYY MMMM', 'fr');

strict

// Without locale
expect('2018-01-26').to.momentFormat.strict('YYYY-MM-DD');
// With locale
expect('2012 juillet').to.momentFormat.strict('YYYY MMMM', 'fr');

See more for the strict parsing: https://momentjs.com/guides/#/parsing/strict-mode/