<commit_before># react-immutable-proptypes

[![npm package](https://img.shields.io/npm/v/react-immutable-proptypes.svg?style=flat)](https://www.npmjs.org/package/react-immutable-proptypes) [![Code Climate](https://codeclimate.com/github/HurricaneJames/react-immutable-proptypes/badges/gpa.svg)](https://codeclimate.com/github/HurricaneJames/react-immutable-proptypes) [![Test Coverage](https://codeclimate.com/github/HurricaneJames/react-immutable-proptypes/badges/coverage.svg)](https://codeclimate.com/github/HurricaneJames/react-immutable-proptypes)

PropType validators that work with Immutable.js.

## Version Updates
0.1.3 updated package.json to support React v0.11.0+ (including 0.13.1). Thanks [<NAME>](https://github.com/okonet)!


## About

I got tired of seeing `React.PropTypes.instanceOf(Immutable.List)` or `React.PropTypes.instanceOf(Immutable.Map)` as PropTypes for components that should be specifying an `Immutable.List` **_of_** something or an `Immutable.Map` **shape**. A little *"googling"* came up empty, unless you want to use Flow, which I do not. So, I wrote `react-immutable-proptypes`.

Usage is simple, they work with and like any `React.PropType.*` validator.

    var ImmutablePropTypes = require('react-immutable-proptypes');
    var MyReactComponent = React.createClass({
      // ...
      propTypes: {
        myRequiredImmutableList: ImmutablePropTypes.listOf(
          ImmutablePropTypes.shape({
            someNumberProp: React.PropTypes.number.isRequired
          })
        ).isRequired
      }
      // ...
    });


## Installation

Installing via [npmjs](https://www.npmjs.com/package/react-immutable-proptypes)

    npm install --save react-immutable-proptypes


## API

React-Immutable-PropTypes has just two validators that cover 100% of my use cases, and probably 99% of everybody's use cases.

* `ImmutablePropTypes.listOf` is based on `React.PropTypes.array` and is specific to `Immutable.List`.

* `ImmutablePropTypes.shape` is based on `React.PropTypes.shape` and will try to work with any `Immutable.Iterable`. In practice, I would recommend limiting this to `Immutable.Map` or `Immutable.OrderedMap`. However, it is possible to abuse `shape` to validate an array via `Immutable.List`.

        // ...
        aList: ImmutablePropTypes.shape({
          0: React.PropTypes.number.isRequired,
          1: React.PropTypes.string.isRequired,
          2: React.PropTypes.string
        })
        // ...
        <SomeComponent aList={new Immutable.List([1, '2'])} />

    That said, don't do this. Please, just... don't.<commit_msg>updated with doc on new mapOf validator<commit_after># react-immutable-proptypes

[![npm package](https://img.shields.io/npm/v/react-immutable-proptypes.svg?style=flat)](https://www.npmjs.org/package/react-immutable-proptypes) [![Code Climate](https://codeclimate.com/github/HurricaneJames/react-immutable-proptypes/badges/gpa.svg)](https://codeclimate.com/github/HurricaneJames/react-immutable-proptypes) [![Test Coverage](https://codeclimate.com/github/HurricaneJames/react-immutable-proptypes/badges/coverage.svg)](https://codeclimate.com/github/HurricaneJames/react-immutable-proptypes)

PropType validators that work with Immutable.js.

## Version Updates
0.1.3 updated package.json to support React v0.11.0+ (including 0.13.1). Thanks [<NAME>](https://github.com/okonet)!


## About

I got tired of seeing `React.PropTypes.instanceOf(Immutable.List)` or `React.PropTypes.instanceOf(Immutable.Map)` as PropTypes for components that should be specifying an `Immutable.List` **_of_** something or an `Immutable.Map` **shape**. A little *"googling"* came up empty, unless you want to use Flow, which I do not. So, I wrote `react-immutable-proptypes`.

Usage is simple, they work with and like any `React.PropType.*` validator.

    var ImmutablePropTypes = require('react-immutable-proptypes');
    var MyReactComponent = React.createClass({
      // ...
      propTypes: {
        myRequiredImmutableList: ImmutablePropTypes.listOf(
          ImmutablePropTypes.shape({
            someNumberProp: React.PropTypes.number.isRequired
          })
        ).isRequired
      }
      // ...
    });


## Installation

Installing via [npmjs](https://www.npmjs.com/package/react-immutable-proptypes)

    npm install --save react-immutable-proptypes


## API

React-Immutable-PropTypes has just two validators that cover 100% of my use cases, and probably 99% of everybody's use cases.

* `ImmutablePropTypes.listOf` is based on `React.PropTypes.array` and is specific to `Immutable.List`.

* `ImmutablePropTypes.mapOf` is basically the same as `listOf`, but it is specific to `Immutable.Map`. I am open to creating an `ImmutablePropTypes.iterableOf` that would validate against any `Immutable.Iterable` if anybody wants it.

* `ImmutablePropTypes.shape` is based on `React.PropTypes.shape` and will try to work with any `Immutable.Iterable`. In practice, I would recommend limiting this to `Immutable.Map` or `Immutable.OrderedMap`. However, it is possible to abuse `shape` to validate an array via `Immutable.List`.

        // ...
        aList: ImmutablePropTypes.shape({
          0: React.PropTypes.number.isRequired,
          1: React.PropTypes.string.isRequired,
          2: React.PropTypes.string
        })
        // ...
        <SomeComponent aList={new Immutable.List([1, '2'])} />

    That said, don't do this. Please, just... don't.
{'fraction_non_alphanumeric': 0.12700165654334622, 'fraction_numerical': 0.007730535615681944, 'mean_word_length': 3.696629213483146, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 16, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '841878', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1696, 'n_words': 417}