extended-proptypes
Advanced tools
Comparing version 1.0.1 to 1.1.0
121
lib/index.js
"use strict"; | ||
var _primatives = require("./primatives"); | ||
var _collection = require("./validators/collection"); | ||
var primatives = _interopRequireWildcard(_primatives); | ||
var _collection2 = _interopRequireDefault(_collection); | ||
var _collections = require("./collections"); | ||
var _collectionOf = require("./validators/collectionOf"); | ||
var collections = _interopRequireWildcard(_collections); | ||
var _collectionOf2 = _interopRequireDefault(_collectionOf); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
var _color = require("./validators/color"); | ||
module.exports = function (PropTypes) { | ||
Object.keys(primatives).forEach(function (key) { | ||
return PropTypes[key] = primatives[key]; | ||
var _color2 = _interopRequireDefault(_color); | ||
var _cssLength = require("./validators/cssLength"); | ||
var _cssLength2 = _interopRequireDefault(_cssLength); | ||
var _cssSize = require("./validators/cssSize"); | ||
var _cssSize2 = _interopRequireDefault(_cssSize); | ||
var _emailAddress = require("./validators/emailAddress"); | ||
var _emailAddress2 = _interopRequireDefault(_emailAddress); | ||
var _hex = require("./validators/hex"); | ||
var _hex2 = _interopRequireDefault(_hex); | ||
var _iterable = require("./validators/iterable"); | ||
var _iterable2 = _interopRequireDefault(_iterable); | ||
var _iterableOf = require("./validators/iterableOf"); | ||
var _iterableOf2 = _interopRequireDefault(_iterableOf); | ||
var _keyedObject = require("./validators/keyedObject"); | ||
var _keyedObject2 = _interopRequireDefault(_keyedObject); | ||
var _keyedObjectOf = require("./validators/keyedObjectOf"); | ||
var _keyedObjectOf2 = _interopRequireDefault(_keyedObjectOf); | ||
var _locale = require("./validators/locale"); | ||
var _locale2 = _interopRequireDefault(_locale); | ||
var _mongoId = require("./validators/mongoId"); | ||
var _mongoId2 = _interopRequireDefault(_mongoId); | ||
var _mongoIdKeyedObject = require("./validators/mongoIdKeyedObject"); | ||
var _mongoIdKeyedObject2 = _interopRequireDefault(_mongoIdKeyedObject); | ||
var _mongoIdKeyedObjectOf = require("./validators/mongoIdKeyedObjectOf"); | ||
var _mongoIdKeyedObjectOf2 = _interopRequireDefault(_mongoIdKeyedObjectOf); | ||
var _percent = require("./validators/percent"); | ||
var _percent2 = _interopRequireDefault(_percent); | ||
var _stringMatching = require("./validators/stringMatching"); | ||
var _stringMatching2 = _interopRequireDefault(_stringMatching); | ||
var _stringWithLength = require("./validators/stringWithLength"); | ||
var _stringWithLength2 = _interopRequireDefault(_stringWithLength); | ||
var _time = require("./validators/time"); | ||
var _time2 = _interopRequireDefault(_time); | ||
var _uuid = require("./validators/uuid"); | ||
var _uuid2 = _interopRequireDefault(_uuid); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var validators = { | ||
collection: _collection2.default, | ||
collectionOf: _collectionOf2.default, | ||
color: _color2.default, | ||
cssLength: _cssLength2.default, | ||
cssSize: _cssSize2.default, | ||
emailAddress: _emailAddress2.default, | ||
hex: _hex2.default, | ||
iterable: _iterable2.default, | ||
iterableOf: _iterableOf2.default, | ||
keyedObject: _keyedObject2.default, | ||
keyedObjectOf: _keyedObjectOf2.default, | ||
locale: _locale2.default, | ||
mongoId: _mongoId2.default, | ||
mongoIdKeyedObject: _mongoIdKeyedObject2.default, | ||
mongoIdKeyedObjectOf: _mongoIdKeyedObjectOf2.default, | ||
percent: _percent2.default, | ||
stringMatching: _stringMatching2.default, | ||
stringWithLength: _stringWithLength2.default, | ||
time: _time2.default, | ||
uuid: _uuid2.default | ||
}; | ||
function extendWithPropTypes(target) { | ||
Object.keys(validators).forEach(function (name) { | ||
target[name] = validators[name]; | ||
}); | ||
Object.keys(collections).forEach(function (key) { | ||
return PropTypes[key] = collections[key]; | ||
}); | ||
return PropTypes; | ||
}; | ||
} | ||
extendWithPropTypes(extendWithPropTypes); | ||
module.exports = extendWithPropTypes; |
{ | ||
"name": "extended-proptypes", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Useful proptypes for react components", | ||
@@ -14,5 +14,2 @@ "main": "lib/index.js", | ||
"author": "Peter Hayes", | ||
"dependencies": { | ||
"is-plain-object": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
@@ -19,0 +16,0 @@ "babel-cli": "^6.6.5", |
@@ -5,14 +5,24 @@ # Extended Prop Types | ||
## Usage | ||
Call the exported function on the standard React `proptypes` object. | ||
Individual validators can be imported under `/validators`. | ||
```js | ||
import {PropTypes} from "react"; | ||
import ExtendPropTypes from "extended-proptypes"; | ||
import keyedObject from "extended-proptypes/validators/keyedObject"; | ||
ExtendPropTypes(PropTypes); | ||
class MyComponent extends Component { | ||
static propTypes = { | ||
mySpecialObject: keyedObject(/keyregex/).isRequired, | ||
}; | ||
} | ||
``` | ||
New options will now be available on React's `PropTypes` export. | ||
You can also import the whole module and call it on `React.PropTypes`, extending | ||
React's `PropTypes` with all included validators. | ||
```js | ||
import {Component, PropTypes} from "react"; | ||
import {PropTypes} from "react"; | ||
import ExtendedPropTypes from "extended-proptypes"; | ||
// New options will now be available on React's `PropTypes` export. | ||
ExtendedPropTypes(PropTypes); | ||
class MyComponent extends Component { | ||
@@ -23,8 +33,20 @@ | ||
mySatanicString: PropTypes.stringMatching(/^6+$/).isRequired, | ||
myArrayOrObject: PropTypes.iterableOf(PropTypes.bool), | ||
myArrayOrObject: PropTypes.collectionOf(PropTypes.bool), | ||
}; | ||
} | ||
``` | ||
Finally, all validators are properties of the module. | ||
```js | ||
import ExtendedPropTypes from "extended-proptypes"; | ||
class MyComponent extends Component { | ||
static propTypes = { | ||
myEmailAddress: ExtendedPropTypes.emailAddress.isRequired, | ||
}; | ||
} | ||
``` | ||
## New Prop Types | ||
@@ -35,4 +57,6 @@ | ||
### Collections | ||
- `iterable`: An array or an object. | ||
- `iterableOf(validator)`: An array or object whose values match the provided validator. | ||
- `collection`: An array or a plain object. | ||
- `collectionOf(validator)`: An array or a plain object whose values match the provided validator. | ||
- `iterable`: An iterable. Errors if enviroment does not support symbols. | ||
- `iterableOf(validator)`: An iterable whose values match the provided validator. Errors if enviroment does not support symbols. | ||
- `keyedObject(regex)`: An object whose keys match the provided regex. | ||
@@ -44,6 +68,7 @@ - `keyedObjectOf(regex, validator)`: An object whose keys match the provided regex and whose values match the provided validator. | ||
- `stringWithLength(min, max=Infinity)`: A string with length between min and max. | ||
- `hex`: A string consisting of hex characters, with an optional 0x at the beginning. | ||
- `time`: A value parsable by `new Date()`. | ||
- `uuid`: A uuid string. | ||
- `locale`: A locale string, like `en-US` or `jp` | ||
- `emailAddress`: An email address (regex taken from the highest-upvoted SO answer) | ||
- `uuid`: A uuid string (e.g. `123e4567-e89b-12d3-a456-426655440000`). | ||
- `locale`: A locale string, like `en-US` or `jp`. | ||
- `emailAddress`: An email address (regex taken from the highest-upvoted SO answer). | ||
@@ -59,6 +84,2 @@ ### CSS | ||
- `mongoIdKeyedObject`: An object whose keys are mongo ids. | ||
- `mongoIdKeyedObjectOf(validator)`: An object whose keys are mongo ids and whose values match the provided validator. | ||
## Upcoming | ||
- Single exports | ||
- Use without extending | ||
- `mongoIdKeyedObjectOf(validator)`: An object whose keys are mongo ids and whose values match the provided validator. |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
26914
0
36
450
80
1
- Removedis-plain-object@^2.0.1
- Removedis-plain-object@2.0.4(transitive)
- Removedisobject@3.0.1(transitive)