UNPKG

shineout

Version:
77 lines (76 loc) 2.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.capitalize = capitalize; exports.getDirectionIconName = getDirectionIconName; exports.getRTLPosition = getRTLPosition; exports.removeProtocol = removeProtocol; exports.substitute = substitute; var _hooks = require("@sheinx/hooks"); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } var devUseWarning = _hooks.util.devUseWarning; function capitalize(str) { if (typeof str !== 'string') { devUseWarning.error('str should be a string'); } return str && str[0].toUpperCase() + str.slice(1); } function substitute(str, obj) { if (typeof str === 'string') { if (str.indexOf('{') < 0) { return str; } return str.replace(/\\?\{([^{}]+)\}/g, function (match, name) { if (match.charAt(0) === '\\') { return match.slice(1); } return obj[name] === null || obj[name] === undefined ? '' : obj[name]; }); } if (typeof str === 'function') { var val = str(obj); if (val === obj && _typeof(val) === 'object') { val = Object.assign({}, obj); } return val; } return ''; } function removeProtocol(url) { if (url.indexOf('http') !== 0) return url; try { var _URL = new URL(url), href = _URL.href, protocol = _URL.protocol; return href.slice(protocol.length); } catch (error) { return url; } } function getRTLPosition(position) { if (!position) return position; // position.replace('left', 'right').replace('right', 'left') if (position.indexOf('left') !== -1) { return position.replace('left', 'right'); } if (position.indexOf('right') !== -1) { return position.replace('right', 'left'); } return position; } function getDirectionIconName() { var mode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'left'; var double = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var rtl = true; if (mode === 'left') { if (rtl) { return double ? 'ArrowRightDouble' : 'AngleRight'; } return double ? 'ArrowLeftDouble' : 'AngleLeft'; } if (rtl) { return double ? 'ArrowLeftDouble' : 'AngleLeft'; } return double ? 'ArrowRightDouble' : 'AngleRight'; }