Comparing version 0.14.4 to 1.0.0
113
index.js
(function (global, factory) { | ||
if (typeof define === 'function' && define.amd) { | ||
define('PropTypes', ['exports', 'module'], factory); | ||
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') { | ||
factory(exports, module); | ||
if (typeof define === "function" && define.amd) { | ||
define('PropTypes', ['exports'], factory); | ||
} else if (typeof exports !== "undefined") { | ||
factory(exports); | ||
} else { | ||
@@ -10,15 +10,41 @@ var mod = { | ||
}; | ||
factory(mod.exports, mod); | ||
factory(mod.exports); | ||
global.PropTypes = mod.exports; | ||
} | ||
})(this, function (exports, module) { | ||
})(this, function (exports) { | ||
/** | ||
* Copyright 2013-2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactPropTypes | ||
*/ | ||
'use strict'; | ||
var REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol['for'] && Symbol['for']('react.element') || 0xeac7; | ||
// The Symbol used to tag the ReactElement type. If there is no native Symbol | ||
// nor polyfill, then a plain number is used for performance. | ||
exports.__esModule = true; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element') || 0xeac7; | ||
var ReactElement = {}; | ||
/** | ||
* @param {?object} object | ||
* @return {boolean} True if `object` is a valid component. | ||
* @final | ||
*/ | ||
ReactElement.isValidElement = function (object) { | ||
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE; | ||
return (typeof object === 'undefined' ? 'undefined' : _typeof(object)) === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE; | ||
}; | ||
@@ -41,3 +67,3 @@ | ||
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; | ||
var FAUX_ITERATOR_SYMBOL = '@@iterator'; | ||
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. | ||
function getIteratorFn(maybeIterable) { | ||
@@ -50,2 +76,49 @@ var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); | ||
/** | ||
* Collection of methods that allow declaration and validation of props that are | ||
* supplied to React components. Example usage: | ||
* | ||
* var Props = require('ReactPropTypes'); | ||
* var MyArticle = React.createClass({ | ||
* propTypes: { | ||
* // An optional string prop named "description". | ||
* description: Props.string, | ||
* | ||
* // A required enum prop named "category". | ||
* category: Props.oneOf(['News','Photos']).isRequired, | ||
* | ||
* // A prop named "dialog" that requires an instance of Dialog. | ||
* dialog: Props.instanceOf(Dialog).isRequired | ||
* }, | ||
* render: function() { ... } | ||
* }); | ||
* | ||
* A more formal specification of how these methods are used: | ||
* | ||
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) | ||
* decl := ReactPropTypes.{type}(.isRequired)? | ||
* | ||
* Each and every declaration produces a function with the same signature. This | ||
* allows the creation of custom validation functions. For example: | ||
* | ||
* var MyLink = React.createClass({ | ||
* propTypes: { | ||
* // An optional string or URI prop named "href". | ||
* href: function(props, propName, componentName) { | ||
* var propValue = props[propName]; | ||
* if (propValue != null && typeof propValue !== 'string' && | ||
* !(propValue instanceof URI)) { | ||
* return new Error( | ||
* 'Expected a string or an URI for ' + propName + ' in ' + | ||
* componentName | ||
* ); | ||
* } | ||
* } | ||
* }, | ||
* render: function() {...} | ||
* }); | ||
* | ||
* @internal | ||
*/ | ||
var ANONYMOUS = '<<anonymous>>'; | ||
@@ -100,3 +173,5 @@ | ||
var locationName = ReactPropTypeLocationNames[location]; | ||
// `propValue` being instance of, say, date/regexp, pass the 'object' | ||
// check, but we can offer a more precise error message here rather than | ||
// 'of type `object`'. | ||
var preciseType = getPreciseType(propValue); | ||
@@ -257,3 +332,3 @@ | ||
function isNode(propValue) { | ||
switch (typeof propValue) { | ||
switch (typeof propValue === 'undefined' ? 'undefined' : _typeof(propValue)) { | ||
case 'number': | ||
@@ -284,2 +359,3 @@ case 'string': | ||
} else { | ||
// Iterator will provide entry [k,v] tuples rather than values. | ||
while (!(step = iterator.next()).done) { | ||
@@ -305,2 +381,3 @@ var entry = step.value; | ||
function isSymbol(propType, propValue) { | ||
// Native Symbol. | ||
if (propType === 'symbol') { | ||
@@ -310,2 +387,3 @@ return true; | ||
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' | ||
if (propValue['@@toStringTag'] === 'Symbol') { | ||
@@ -315,2 +393,3 @@ return true; | ||
// Fallback for non-spec compliant Symbols which are polyfilled. | ||
if (typeof Symbol === 'function' && propValue instanceof Symbol) { | ||
@@ -323,4 +402,5 @@ return true; | ||
// Equivalent of `typeof` but with special handling for array and regexp. | ||
function getPropType(propValue) { | ||
var propType = typeof propValue; | ||
var propType = typeof propValue === 'undefined' ? 'undefined' : _typeof(propValue); | ||
if (Array.isArray(propValue)) { | ||
@@ -330,2 +410,5 @@ return 'array'; | ||
if (propValue instanceof RegExp) { | ||
// Old webkits (at least until Android 4.0) return 'function' rather than | ||
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/ | ||
// passes PropTypes.object. | ||
return 'object'; | ||
@@ -339,2 +422,4 @@ } | ||
// This handles more types than `getPropType`. Only used for error messages. | ||
// See `createPrimitiveTypeChecker`. | ||
function getPreciseType(propValue) { | ||
@@ -352,2 +437,3 @@ var propType = getPropType(propValue); | ||
// Returns class name of the object, if any. | ||
function getClassName(propValue) { | ||
@@ -360,5 +446,4 @@ if (!propValue.constructor || !propValue.constructor.name) { | ||
module.exports = ReactPropTypes; | ||
exports.default = ReactPropTypes; | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "proptypes", | ||
"amdName": "PropTypes", | ||
"version": "0.14.4", | ||
"version": "1.0.0", | ||
"description": "React's PropTypes, packaged up as a standalone module.", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "babel -f $npm_package_main -m umd --module-id $npm_package_amdName -s -o $npm_package_main < src/index.js", | ||
"build": "babel --module-id $npm_package_amdName -s -d . src", | ||
"release": "npm run -s build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish" | ||
@@ -14,3 +14,5 @@ }, | ||
"index.js", | ||
"index.js.map" | ||
"index.js.map", | ||
"disabled.js", | ||
"disabled.js.map" | ||
], | ||
@@ -24,4 +26,5 @@ "repository": { | ||
"devDependencies": { | ||
"babel": "^5.8.29" | ||
"babel-cli": "^6.23.0", | ||
"babel-preset-env": "^1.2.1" | ||
} | ||
} |
@@ -10,16 +10,16 @@ # proptypes | ||
### Usage | ||
## Usage | ||
```js | ||
function check(props, propTypes) { | ||
for (let prop in propTypes) { | ||
if (propTypes.hasOwnProperty(prop)) { | ||
let err = propTypes[prop](props, prop, 'name', 'prop'); | ||
if (err) { | ||
console.warn(err); | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
for (let prop in propTypes) { | ||
if (propTypes.hasOwnProperty(prop)) { | ||
let err = propTypes[prop](props, prop, 'name', 'prop'); | ||
if (err) { | ||
console.warn(err); | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
@@ -38,7 +38,43 @@ | ||
## Production build | ||
### License | ||
### Disabling | ||
With webpack: | ||
```js | ||
module.exports = { | ||
resolve: { | ||
alias: { | ||
proptypes: 'proptypes/disabled', | ||
} | ||
} | ||
}; | ||
``` | ||
### Removing the definitions with React | ||
When you are using this package with React like API, you might want to save bandwidth by removing the definitions. | ||
You can use [babel-plugin-transform-react-remove-prop-types](https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types) for that use case, for instance: | ||
```js | ||
// In | ||
const Baz = (props) => ( | ||
<div {...props} /> | ||
); | ||
Baz.propTypes = { | ||
className: PropTypes.string | ||
}; | ||
// Out | ||
const Baz = (props) => ( | ||
<div {...props} /> | ||
); | ||
``` | ||
## License | ||
BSD | ||
[PropTypes]: https://github.com/facebook/react/blob/master/src/isomorphic/classic/types/ReactPropTypes.js |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
61086
9
892
0
79
2