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

react-moment-proptypes

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-moment-proptypes - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

src/core.js

17

package.json
{
"name": "react-moment-proptypes",
"version": "1.4.0",
"version": "1.5.0",
"description": "React proptype for moment module",

@@ -19,6 +19,7 @@ "keywords": [

"coveralls": "cat ./coverage/lcov.info | coveralls",
"test": "./node_modules/.bin/mocha --recursive --compilers js:babel/register --require ./test/setup.js",
"test-all": "npm run test-1.6 && npm run test-1.7 && rm -Rf ./node_modules/moment/ && npm i && npm test",
"test": "./node_modules/.bin/mocha --recursive --compilers js:babel/register",
"test-all": "npm run test-1.6 && npm run test-1.7 && npm run test-latest",
"test-1.6": "rm -Rf ./node_modules/moment/ && npm i moment@1.6.0 && npm test",
"test-1.7": "rm -Rf ./node_modules/moment/ && npm i moment@1.7.0 && npm test",
"test-latest": "rm -Rf ./node_modules/moment/ && npm i moment@latest && npm test",
"lint": "./node_modules/.bin/eslint --ext .js .",

@@ -44,9 +45,11 @@ "lint-quiet": "./node_modules/.bin/eslint --ext .js --quiet .",

"coveralls": "^2.11.6",
"enzyme": "^2.9.1",
"eslint": "^0.24.0",
"istanbul": "^0.3.13",
"jsdom": "^6.5.1",
"mocha": "^2.2.1",
"react": "^0.14.6",
"react-addons-test-utils": "^0.14.6"
"mocha": "^3.4.2",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-test-renderer": "^15.6.1",
"sinon": "^2.3.6"
}
}

@@ -41,5 +41,5 @@ # react-moment-proptypes

Tests were approached with `jsdom` and React's test utility renderer
Tests were approached with `enzyme` and React's test utility renderer
- `npm test` for running unit tests
- `npm test` for running unit and integration tests
- `npm run coverage` for current test coverage

@@ -46,0 +46,0 @@

var moment = require('moment');
var momentValidationWrapper = require('./moment-validation-wrapper');
var core = require('./core');

@@ -8,92 +9,5 @@ moment.createFromInputFallback = function(config) {

var ANONYMOUS = '<<anonymous>>';
var ReactPropTypeLocationNames = {
prop : 'prop',
context : 'context',
childContext : 'child context',
};
function createInvalidRequiredErrorMessage(propName, componentName, value) {
return new Error(
'The prop `' + propName + '` is marked as required in `' + componentName + '`, but its value is `' + value + '`.'
);
}
function createMomentChecker(type, typeValidator, validator, momentType) {
function propValidator(
isRequired, // Bound parameter to indicate with the propType is required
predicate, // Bound parameter to allow user to add dynamic validation
props,
propName,
componentName,
location,
propFullName
) {
var propValue = props[ propName ];
var propType = typeof propValue;
var isPropValueUndefined = typeof propValue === 'undefined';
var isPropValueNull = propValue === null;
if (isRequired) {
componentName = componentName || ANONYMOUS;
propFullName = propFullName || propName;
if (isPropValueUndefined) {
return createInvalidRequiredErrorMessage(propFullName, componentName, 'undefined');
} else if (isPropValueNull) {
return createInvalidRequiredErrorMessage(propFullName, componentName, 'null');
}
}
if (isPropValueUndefined || isPropValueNull) {
return null;
}
if (typeValidator && !typeValidator(propValue)) {
return new Error(
'Invalid input type: `' + propName + '` of type `' + propType + '` ' +
'supplied to `' + componentName + '`, expected `' + type + '`.'
);
}
if (! validator(propValue)) {
return new Error(
'Invalid ' + location + ' `' + propName + '` of type `' + propType + '` ' +
'supplied to `' + componentName + '`, expected `' + momentType + '`.'
);
}
if (predicate && ! predicate(propValue)) {
var predicateName = predicate.name || ANONYMOUS;
return new Error(
'Invalid ' + location + ' `' + propName + '` of type `' + propType + '` ' +
'supplied to `' + componentName + '`. Failed to succeed with predicate `' +
predicateName + '`.'
);
}
return null;
}
var requiredPropValidator = propValidator.bind(null, false, null);
requiredPropValidator.isRequired = propValidator.bind(null, true, null);
requiredPropValidator.withPredicate = function predicateApplication(predicate) {
if (typeof predicate !== 'function') {
throw new Error('`predicate` must be a function');
}
var basePropValidator = propValidator.bind(null, false, predicate);
basePropValidator.isRequired = propValidator.bind(null, true, predicate);
return basePropValidator;
};
return requiredPropValidator;
}
module.exports = {
momentObj : createMomentChecker(
momentObj : core.createMomentChecker(
'object',

@@ -109,3 +23,3 @@ function(obj) {

momentString : createMomentChecker(
momentString : core.createMomentChecker(
'string',

@@ -121,3 +35,3 @@ function(str) {

momentDurationObj : createMomentChecker(
momentDurationObj : core.createMomentChecker(
'object',

@@ -124,0 +38,0 @@ function(obj) {

var moment = require('moment');
function isValidMoment(testMoment) {
if (typeof moment.isMoment === 'function' && !moment.isMoment(testMoment)) {
return false;
}
/* istanbul ignore else */
if (typeof testMoment.isValid === 'function') {

@@ -9,3 +14,4 @@ // moment 1.7.0+

return ! isNaN(testMoment);
/* istanbul ignore next */
return !isNaN(testMoment);
}

@@ -15,2 +21,2 @@

isValidMoment : isValidMoment,
}
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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