Permalink
Browse files

Make moment a peer dependency

  • Loading branch information...
jd20 committed Feb 4, 2019
1 parent 6a79bb3 commit 933144746c4debd70521ba3fc49ae5df94d1d603
Showing with 21 additions and 9 deletions.
  1. +18 −1 index.js
  2. +3 −3 package.json
  3. +0 −5 yarn.lock
@@ -1,4 +1,12 @@
var moment = require('moment')
// Optionally require moment (only needed for the conversion helpers)
var moment = null
try {
moment = require.resolve('moment')
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e
}
}

var reDate = /^(\d{4})-(\d{2})-(\d{2})$/
var reTime = /^(\d{2}):(\d{2})$/
@@ -63,14 +71,23 @@ function _str (y, m, d) {
}

function coerce (dt) {
if (!moment) {
throw new Error("Cannot find module 'moment': please install manually to use the conversion helpers")
}
return moment.isMoment(dt) ? dt.format('YYYY-MM-DD') : dt
}

function coerceTime (dt) {
if (!moment) {
throw new Error("Cannot find module 'moment': please install manually to use the conversion helpers")
}
return moment.isMoment(dt) ? dt.format('HH:mm') : dt
}

function format (dt) {
if (!moment) {
throw new Error("Cannot find module 'moment': please install manually to use the conversion helpers")
}
return moment(dt, 'YYYY-MM-DD', true).format('L')
}

@@ -1,6 +1,6 @@
{
"name": "timetable-fns",
"version": "0.1.13",
"version": "0.1.14",
"description": "Useful date and time utility functions for working with timetables.",
"main": "index.js",
"scripts": {
@@ -18,8 +18,8 @@
"author": "JD",
"license": "ISC",
"private": false,
"dependencies": {
"moment": "^2.24.0"
"peerDependencies": {
"moment": "^2.0.0"
},
"devDependencies": {
"benchmark": "^2.1.4",

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 9331447

Please sign in to comment.