{"size": 1671, "ext": "js", "max_stars_repo_path": "node_modules/react-intl/lib/components/injectIntl.js", "max_stars_repo_name": "ShinKano/ssi-codecamp", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "node_modules/react-intl/lib/components/injectIntl.js", "max_issues_repo_name": "ShinKano/ssi-codecamp", "max_issues_repo_issues_event_min_datetime": "2020-12-29T15:49:05.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-29T15:49:05.000Z", "max_forks_repo_path": "node_modules/react-intl/lib/components/injectIntl.js", "max_forks_repo_name": "ShinKano/ssi-codecamp", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 49.1470588235, "max_line_length": 170, "alphanum_fraction": 0.7193297427}
import * as React from 'react';
import * as hoistNonReactStatics_ from 'hoist-non-react-statics';
// Since rollup cannot deal with namespace being a function,
// this is to interop with TypeScript since `invariant`
// does not export a default
// https://github.com/rollup/rollup/issues/1267
const hoistNonReactStatics = hoistNonReactStatics_.default || hoistNonReactStatics_;
import { invariantIntlContext } from '../utils';
function getDisplayName(Component) {
    return Component.displayName || Component.name || 'Component';
}
// TODO: We should provide initial value here
const IntlContext = React.createContext(null);
const { Consumer: IntlConsumer, Provider: IntlProvider } = IntlContext;
export const Provider = IntlProvider;
export const Context = IntlContext;
export default function injectIntl(WrappedComponent, options) {
    const { intlPropName = 'intl', forwardRef = false, enforceContext = true } = options || {};
    const WithIntl = props => (React.createElement(IntlConsumer, null, (intl) => {
        if (enforceContext) {
            invariantIntlContext(intl);
        }
        return (React.createElement(WrappedComponent, Object.assign({}, props, {
            [intlPropName]: intl,
        }, { ref: forwardRef ? props.forwardedRef : null })));
    }));
    WithIntl.displayName = `injectIntl(${getDisplayName(WrappedComponent)})`;
    WithIntl.WrappedComponent = WrappedComponent;
    if (forwardRef) {
        return hoistNonReactStatics(React.forwardRef((props, ref) => (React.createElement(WithIntl, Object.assign({}, props, { forwardedRef: ref })))), WrappedComponent);
    }
    return hoistNonReactStatics(WithIntl, WrappedComponent);
}
