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

moment-random

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moment-random - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

10

package.json
{
"name": "moment-random",
"version": "1.0.3",
"author": "Ivan Mrvelj <sk8raid@gmail.com>",
"version": "1.0.4",
"author": "Ivan Mrvelj <ivan.mrvelj@protonmail.com>",
"description": "Generates a random momentjs object",

@@ -41,8 +41,8 @@ "license": "MIT",

"babel-jest": "^19.0.0",
"babel-preset-env": "^1.4.0",
"babel-preset-env": "^1.7.0",
"eslint": "^3.9.1",
"eslint-plugin-jest": "^19.0.1",
"husky": "^0.13.3",
"jest": "^19.0.2",
"moment": "^2.18.1",
"jest": "^23.0.0",
"moment": "^2.20.1",
"rimraf": "^2.6.1"

@@ -49,0 +49,0 @@ },

@@ -11,3 +11,3 @@ const moment = require('moment');

function momentRandom(end = moment(), start) {
const endMoment = moment(end);
const endTime = +moment(end);
const randomNumber = (to, from = 0) =>

@@ -17,12 +17,11 @@ Math.floor(Math.random() * (to - from) + from);

if (start) {
const startMoment = moment(start);
if (startMoment.unix() > endMoment.unix()) {
const startTime = +moment(start);
if (startTime > endTime) {
throw new Error('End date is before start date!');
}
return moment.unix(randomNumber(endMoment.unix(), startMoment.unix()));
} else {
return moment.unix(randomNumber(endMoment.unix()));
return moment(randomNumber(endTime, startTime));
}
return moment(randomNumber(endTime));
}
module.exports = momentRandom;
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