PluginProbe ʕ •ᴥ•ʔ
GPTranslate – Multilingual AI Translation for WordPress: Automatically Translate Websites / 2.12
GPTranslate – Multilingual AI Translation for WordPress: Automatically Translate Websites v2.12
2.33.7 2.33.6 2.33.5 2.33.2 2.32.10 2.33 2.33.1 2.32.6 2.32.7 2.32.8 trunk 2.10.3 2.10.4 2.10.5 2.10.6 2.11 2.12 2.13 2.14 2.14.1 2.15 2.15.1 2.16.1 2.16.2 2.17 2.18 2.18.1 2.18.2 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.25.1 2.25.2 2.26 2.27 2.27.10 2.27.5 2.28 2.28.1 2.29 2.30 2.31 2.32 2.32.5
gptranslate / assets / js / jsonrepair / utils / stringUtils.js
gptranslate / assets / js / jsonrepair / utils Last commit date
JSONRepairError.js 1 year ago JSONRepairError.js.map 1 year ago stringUtils.js 1 year ago stringUtils.js.map 1 year ago
stringUtils.js
161 lines
1 export const codeBackslash = 0x5c; // "\"
2 export const codeSlash = 0x2f; // "/"
3 export const codeAsterisk = 0x2a; // "*"
4 export const codeOpeningBrace = 0x7b; // "{"
5 export const codeClosingBrace = 0x7d; // "}"
6 export const codeOpeningBracket = 0x5b; // "["
7 export const codeClosingBracket = 0x5d; // "]"
8 export const codeOpenParenthesis = 0x28; // "("
9 export const codeCloseParenthesis = 0x29; // ")"
10 export const codeSpace = 0x20; // " "
11 export const codeNewline = 0xa; // "\n"
12 export const codeTab = 0x9; // "\t"
13 export const codeReturn = 0xd; // "\r"
14 export const codeBackspace = 0x08; // "\b"
15 export const codeFormFeed = 0x0c; // "\f"
16 export const codeDoubleQuote = 0x0022; // "
17 export const codePlus = 0x2b; // "+"
18 export const codeMinus = 0x2d; // "-"
19 export const codeQuote = 0x27; // "'"
20 export const codeZero = 0x30; // "0"
21 export const codeNine = 0x39; // "9"
22 export const codeComma = 0x2c; // ","
23 export const codeDot = 0x2e; // "." (dot, period)
24 export const codeColon = 0x3a; // ":"
25 export const codeSemicolon = 0x3b; // ";"
26 export const codeUppercaseA = 0x41; // "A"
27 export const codeLowercaseA = 0x61; // "a"
28 export const codeUppercaseE = 0x45; // "E"
29 export const codeLowercaseE = 0x65; // "e"
30 export const codeUppercaseF = 0x46; // "F"
31 export const codeLowercaseF = 0x66; // "f"
32 const codeNonBreakingSpace = 0xa0;
33 const codeEnQuad = 0x2000;
34 const codeHairSpace = 0x200a;
35 const codeNarrowNoBreakSpace = 0x202f;
36 const codeMediumMathematicalSpace = 0x205f;
37 const codeIdeographicSpace = 0x3000;
38 const codeDoubleQuoteLeft = 0x201c; //
39 const codeDoubleQuoteRight = 0x201d; //
40 const codeQuoteLeft = 0x2018; //
41 const codeQuoteRight = 0x2019; //
42 const codeGraveAccent = 0x0060; // `
43 const codeAcuteAccent = 0x00b4; // ´
44
45 export function isHex(code) {
46 return code >= codeZero && code <= codeNine || code >= codeUppercaseA && code <= codeUppercaseF || code >= codeLowercaseA && code <= codeLowercaseF;
47 }
48 export function isDigit(code) {
49 return code >= codeZero && code <= codeNine;
50 }
51 export function isValidStringCharacter(code) {
52 return code >= 0x20 && code <= 0x10ffff;
53 }
54 export function isDelimiter(char) {
55 return regexDelimiter.test(char);
56 }
57 const regexDelimiter = /^[,:[\]/{}()\n+]$/;
58 export function isDelimiterExceptSlash(char) {
59 return isDelimiter(char) && char !== '/';
60 }
61 export function isStartOfValue(char) {
62 return regexStartOfValue.test(char) || char && isQuote(char.charCodeAt(0));
63 }
64
65 // alpha, number, minus, or opening bracket or brace
66 const regexStartOfValue = /^[[{\w-]$/;
67 export function isControlCharacter(code) {
68 return code === codeNewline || code === codeReturn || code === codeTab || code === codeBackspace || code === codeFormFeed;
69 }
70
71 /**
72 * Check if the given character is a whitespace character like space, tab, or
73 * newline
74 */
75 export function isWhitespace(code) {
76 return code === codeSpace || code === codeNewline || code === codeTab || code === codeReturn;
77 }
78
79 /**
80 * Check if the given character is a special whitespace character, some
81 * unicode variant
82 */
83 export function isSpecialWhitespace(code) {
84 return code === codeNonBreakingSpace || code >= codeEnQuad && code <= codeHairSpace || code === codeNarrowNoBreakSpace || code === codeMediumMathematicalSpace || code === codeIdeographicSpace;
85 }
86
87 /**
88 * Test whether the given character is a quote or double quote character.
89 * Also tests for special variants of quotes.
90 */
91 export function isQuote(code) {
92 // the first check double quotes, since that occurs most often
93 return isDoubleQuoteLike(code) || isSingleQuoteLike(code);
94 }
95
96 /**
97 * Test whether the given character is a double quote character.
98 * Also tests for special variants of double quotes.
99 */
100 export function isDoubleQuoteLike(code) {
101 // the first check double quotes, since that occurs most often
102 return code === codeDoubleQuote || code === codeDoubleQuoteLeft || code === codeDoubleQuoteRight;
103 }
104
105 /**
106 * Test whether the given character is a double quote character.
107 * Does NOT test for special variants of double quotes.
108 */
109 export function isDoubleQuote(code) {
110 return code === codeDoubleQuote;
111 }
112
113 /**
114 * Test whether the given character is a single quote character.
115 * Also tests for special variants of single quotes.
116 */
117 export function isSingleQuoteLike(code) {
118 return code === codeQuote || code === codeQuoteLeft || code === codeQuoteRight || code === codeGraveAccent || code === codeAcuteAccent;
119 }
120
121 /**
122 * Test whether the given character is a single quote character.
123 * Does NOT test for special variants of single quotes.
124 */
125 export function isSingleQuote(code) {
126 return code === codeQuote;
127 }
128
129 /**
130 * Strip last occurrence of textToStrip from text
131 */
132 export function stripLastOccurrence(text, textToStrip) {
133 let stripRemainingText = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
134 const index = text.lastIndexOf(textToStrip);
135 return index !== -1 ? text.substring(0, index) + (stripRemainingText ? '' : text.substring(index + 1)) : text;
136 }
137 export function insertBeforeLastWhitespace(text, textToInsert) {
138 let index = text.length;
139 if (!isWhitespace(text.charCodeAt(index - 1))) {
140 // no trailing whitespaces
141 return text + textToInsert;
142 }
143 while (isWhitespace(text.charCodeAt(index - 1))) {
144 index--;
145 }
146 return text.substring(0, index) + textToInsert + text.substring(index);
147 }
148 export function removeAtIndex(text, start, count) {
149 return text.substring(0, start) + text.substring(start + count);
150 }
151
152 /**
153 * Test whether a string ends with a newline or comma character and optional whitespace
154 */
155 export function endsWithCommaOrNewline(text) {
156 return /[,\n][ \t\r]*$/.test(text);
157 }
158 export function isFunctionName(text) {
159 return /^\w+$/.test(text);
160 }
161 //# sourceMappingURL=stringUtils.js.map