inferno-shared
Version:
Helpers functions for Inferno
84 lines (81 loc) • 2.05 kB
JavaScript
;
var ERROR_MSG = 'a runtime error occured! Use Inferno in development environment to find the error.';
var isArray = Array.isArray;
function isStringOrNumber(o) {
var type = typeof o;
return type === 'string' || type === 'number';
}
function isNullOrUndef(o) {
return o === void 0 || o === null;
}
function isInvalid(o) {
return o === null || o === false || o === true || o === void 0;
}
function isFunction(o) {
return typeof o === 'function';
}
function isString(o) {
return typeof o === 'string';
}
function isNumber(o) {
return typeof o === 'number';
}
function isNull(o) {
return o === null;
}
function isUndefined(o) {
return o === void 0;
}
function throwError(message) {
if (!message) {
message = ERROR_MSG;
}
throw new Error("Inferno Error: " + message);
}
function warning(message) {
console.error(message);
}
var KNOWN_STATICS = {
childContextTypes: true,
contextType: true,
contextTypes: true,
defaultProps: true,
displayName: true,
getDefaultProps: true,
getDerivedStateFromError: true,
getDerivedStateFromProps: true,
mixins: true,
propTypes: true,
type: true,
// KNOWN STATICS
name: true,
length: true,
prototype: true,
caller: true,
callee: true,
arguments: true,
arity: true
};
function hoistStaticProperties(targetComponent, sourceComponent) {
// don't hoist over string (html) components
var keys = Object.getOwnPropertyNames(sourceComponent);
for (var i = 0; i < keys.length; ++i) {
var key = keys[i];
if (!KNOWN_STATICS[key]) {
targetComponent[key] = sourceComponent[key];
}
}
}
exports.ERROR_MSG = ERROR_MSG;
exports.hoistStaticProperties = hoistStaticProperties;
exports.isArray = isArray;
exports.isFunction = isFunction;
exports.isInvalid = isInvalid;
exports.isNull = isNull;
exports.isNullOrUndef = isNullOrUndef;
exports.isNumber = isNumber;
exports.isString = isString;
exports.isStringOrNumber = isStringOrNumber;
exports.isUndefined = isUndefined;
exports.throwError = throwError;
exports.warning = warning;