UNPKG

@material-ui/core

Version:

React components that implement Google's Material Design.

35 lines (31 loc) 1.17 kB
import warning from 'warning'; // It should to be noted that this function isn't equivalent to `text-transform: capitalize`. // // A strict capitalization should uppercase the first letter of each word a the sentence. // We only handle the first word. export function capitalize(string) { if (process.env.NODE_ENV !== 'production' && typeof string !== 'string') { throw new Error('Material-UI: capitalize(string) expects a string argument.'); } return string.charAt(0).toUpperCase() + string.slice(1); } /** * Safe chained function * * Will only create a new function if needed, * otherwise will pass back existing functions or null. * * @param {function} functions to chain * @returns {function|null} */ export function createChainedFunction(...funcs) { return funcs.reduce((acc, func) => { if (func == null) { return acc; } process.env.NODE_ENV !== "production" ? warning(typeof func === 'function', 'Material-UI: invalid Argument Type, must only provide functions, undefined, or null.') : void 0; return function chainedFunction(...args) { acc.apply(this, args); func.apply(this, args); }; }, () => {}); }