react-moment-proptypes
Advanced tools
Comparing version 0.0.5 to 0.1.0
76
index.js
var moment = require('moment'); | ||
function momentObj(props, propName, componentName, location) { | ||
var propValue = props[propName]; | ||
if (! moment.isMoment(propValue)) { | ||
var propType = typeof propValue; | ||
return new Error( | ||
'Invalid ' + location + '`' + propName + '` of type `' + propType + '` ' + | ||
'supplied to `' + componentName + '`, expected `Moment`.' | ||
); | ||
} | ||
return null; | ||
var ANONYMOUS = '<<anonymous>>'; | ||
var ReactPropTypeLocationNames = { | ||
prop : 'prop', | ||
context : 'context', | ||
childContext : 'child context', | ||
}; | ||
function momentString(props, propName, componentName, location) { | ||
var propValue = props[propName]; | ||
if (moment.utc(propValue).format() === 'Invalid date') { | ||
var propType = typeof propValue; | ||
return new Error( | ||
'Invalid ' + location + '`' + propName + '` of type `' + propType + '` ' + | ||
'supplied to `' + componentName + '`, expected `Moment`.' | ||
); | ||
function createMomentChecker(validator) { | ||
function propValidator(isRequired, props, propName, componentName, location, propFullName) { | ||
if (isRequired) { | ||
var locationName = ReactPropTypeLocationNames[ location ]; | ||
componentName = componentName || ANONYMOUS; | ||
propFullName = propFullName || propName; | ||
return new Error( | ||
'Required ' + locationName + ' `' + propFullName + | ||
'` was not specified in `' + | ||
componentName + '`.' | ||
); | ||
} | ||
var propValue = props[ propName ]; | ||
if (typeof propValue === 'undefined') { | ||
return null; | ||
} | ||
if (validator(propValue)) { | ||
var propType = typeof propValue; | ||
return new Error( | ||
'Invalid ' + location + ' `' + propName + '` of type `' + propType + '` ' + | ||
'supplied to `' + componentName + '`, expected `Moment`.' | ||
); | ||
} | ||
return null; | ||
} | ||
return null; | ||
}; | ||
var requiredPropValidator = propValidator.bind(null, false); | ||
requiredPropValidator.isRequired = propValidator.bind(null, true); | ||
return requiredPropValidator; | ||
} | ||
module.exports = { | ||
momentObj : momentObj, | ||
momentString : momentString, | ||
momentObj : createMomentChecker(function(value) { | ||
return !moment.isMoment(value); | ||
}), | ||
momentString : createMomentChecker(function(value) { | ||
return moment.utc(value).format() === 'Invalid date'; | ||
}), | ||
}; | ||
{ | ||
"name": "react-moment-proptypes", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "React proptype for moment module", | ||
"keywords": [ | ||
"moment", | ||
"react", | ||
"props", | ||
"proptypes" | ||
], | ||
"main": "index.js", | ||
"repository": { | ||
"type" : "git", | ||
"url" : "git@github.com:CalebMorris/react-moment-proptypes.git" | ||
"type": "git", | ||
"url": "git@github.com:CalebMorris/react-moment-proptypes.git" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"clean": "rm -Rf ./coverage", | ||
"test": "./node_modules/.bin/mocha --recursive --compilers js:babel/register", | ||
"lint": "./node_modules/.bin/eslint --ext .js .", | ||
"lint-quiet": "./node_modules/.bin/eslint --ext .js --quiet .", | ||
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --recursive --compilers js:babel/register" | ||
}, | ||
@@ -20,3 +30,11 @@ "author": { | ||
"moment": ">=1.5.0" | ||
}, | ||
"devDependencies": { | ||
"babel": "^5.6.23", | ||
"chai": "^2.3.0", | ||
"eslint": "^0.24.0", | ||
"istanbul": "^0.3.13", | ||
"mocha": "^2.2.1", | ||
"react": "^0.13.3" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
11675
7
152
2
6