| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- /**
- * DevExtreme (core/utils/string.js)
- * Version: 19.1.16
- * Build date: Tue Oct 18 2022
- *
- * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
- * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
- */
- "use strict";
- function _typeof(obj) {
- "@babel/helpers - typeof";
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) {
- return typeof obj
- } : function(obj) {
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
- }, _typeof(obj)
- }
- var typeUtils = require("./type");
- var encodeHtml = function() {
- var encodeRegExp = [new RegExp("&", "g"), new RegExp('"', "g"), new RegExp("'", "g"), new RegExp("<", "g"), new RegExp(">", "g")];
- return function(str) {
- return String(str).replace(encodeRegExp[0], "&").replace(encodeRegExp[1], """).replace(encodeRegExp[2], "'").replace(encodeRegExp[3], "<").replace(encodeRegExp[4], ">")
- }
- }();
- var splitQuad = function(raw) {
- switch (_typeof(raw)) {
- case "string":
- return raw.split(/\s+/, 4);
- case "object":
- return [raw.x || raw.h || raw.left, raw.y || raw.v || raw.top, raw.x || raw.h || raw.right, raw.y || raw.v || raw.bottom];
- case "number":
- return [raw];
- default:
- return raw
- }
- };
- var quadToObject = function(raw) {
- var quad = splitQuad(raw);
- var left = parseInt(quad && quad[0], 10);
- var top = parseInt(quad && quad[1], 10);
- var right = parseInt(quad && quad[2], 10);
- var bottom = parseInt(quad && quad[3], 10);
- if (!isFinite(left)) {
- left = 0
- }
- if (!isFinite(top)) {
- top = left
- }
- if (!isFinite(right)) {
- right = left
- }
- if (!isFinite(bottom)) {
- bottom = top
- }
- return {
- top: top,
- right: right,
- bottom: bottom,
- left: left
- }
- };
- var stringFormat = function() {
- var s = arguments[0];
- var values = [].slice.call(arguments).slice(1);
- var replaceDollarCount;
- var reg;
- var value;
- if (typeUtils.isFunction(s)) {
- return s.apply(this, values)
- }
- for (var i = 0; i < values.length; i++) {
- reg = new RegExp("\\{" + i + "\\}", "gm");
- value = values[i];
- if ("string" === typeUtils.type(value) && value.indexOf("$") >= 0) {
- replaceDollarCount = "$".replace("$", "$$").length;
- value = value.replace("$", 1 === replaceDollarCount ? "$$$$" : "$$")
- }
- s = s.replace(reg, value)
- }
- return s
- };
- var replaceAll = function() {
- var quote = function(str) {
- return (str + "").replace(/([+*?.[^\]$(){}><|=!:])/g, "\\$1")
- };
- return function(text, searchToken, replacementToken) {
- return text.replace(new RegExp("(" + quote(searchToken) + ")", "gi"), replacementToken)
- }
- }();
- var isEmpty = function() {
- var SPACE_REGEXP = /\s/g;
- return function(text) {
- return !text || !text.replace(SPACE_REGEXP, "")
- }
- }();
- exports.encodeHtml = encodeHtml;
- exports.quadToObject = quadToObject;
- exports.format = stringFormat;
- exports.replaceAll = replaceAll;
- exports.isEmpty = isEmpty;
|