UNPKG

gatsby-background-image

Version:

Lazy-loading React background-image component with optional support for the blur-up effect.

95 lines (69 loc) 2.47 kB
"use strict"; exports.__esModule = true; exports.toKebabCase = exports.toCamelCase = exports.stringToArray = exports.isString = exports.isObject = exports.isBrowser = exports.hashString = exports.filteredJoin = exports.combineArray = exports.capitalize = void 0; var isBrowser = function isBrowser() { return typeof window !== "undefined" && typeof window.document !== "undefined"; }; exports.isBrowser = isBrowser; var isString = function isString(value) { return Object.prototype.toString.call(value) === '[object String]'; }; exports.isString = isString; var isObject = function isObject(value) { return Object.prototype.toString.call(value) === '[object Object]'; }; exports.isObject = isObject; var toCamelCase = function toCamelCase(str) { return isString(str) && str.indexOf('-') !== -1 && str.toLowerCase().replace(/(?:^\w|-|[A-Z]|\b\w)/g, function (letter, index) { return index === 0 ? letter.toLowerCase() : letter.toUpperCase(); }).replace(/\s|\W+/g, '') || str; }; exports.toCamelCase = toCamelCase; var toKebabCase = function toKebabCase(str) { return isString(str) && str.replace(/\s|\W+/g, '').replace(/[A-Z]/g, function (match) { return "-" + match.toLowerCase(); }); }; exports.toKebabCase = toKebabCase; var capitalize = function capitalize(str) { return (str === null || str === void 0 ? void 0 : str.charAt(0).toUpperCase()) + str.slice(1); }; exports.capitalize = capitalize; var stringToArray = function stringToArray(str, delimiter) { if (delimiter === void 0) { delimiter = " "; } if (str instanceof Array) { return str; } if (isString(str)) { if (str.includes(delimiter)) { return str.split(delimiter); } return [str]; } return false; }; exports.stringToArray = stringToArray; var hashString = function hashString(str) { return isString(str) && [].reduce.call(str, function (hash, item) { hash = (hash << 5) - hash + item.charCodeAt(0); return hash | 0; }, 0); }; exports.hashString = hashString; var filteredJoin = function filteredJoin(arrayToJoin) { return arrayToJoin.filter(function (item) { return item !== ""; }).join(); }; exports.filteredJoin = filteredJoin; var combineArray = function combineArray(fromArray, toArray) { if (!Array.isArray(fromArray)) { return [fromArray]; } return fromArray.map(function (item, index) { return item || toArray && toArray[index]; }); }; exports.combineArray = combineArray;