qsu 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +28 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -121,15 +121,27 @@ export default class Qsu {
|
|
|
121
121
|
* String
|
|
122
122
|
* */
|
|
123
123
|
static removeSpecialChar(str, withoutSpace) {
|
|
124
|
+
if (!str) {
|
|
125
|
+
return '';
|
|
126
|
+
}
|
|
124
127
|
return str.replace(new RegExp(`[^a-zA-Z가-힣ㄱ-ㅎㅏ-ㅣ0-9\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f${withoutSpace ? ' ' : ''}]`, 'gi'), '');
|
|
125
128
|
}
|
|
126
129
|
static removeNewLine(str, replaceTo = '') {
|
|
130
|
+
if (!str) {
|
|
131
|
+
return '';
|
|
132
|
+
}
|
|
127
133
|
return str.replace(/(\r\n|\n|\r)/gm, replaceTo).trim();
|
|
128
134
|
}
|
|
129
135
|
static capitalizeFirst(str) {
|
|
136
|
+
if (!str) {
|
|
137
|
+
return '';
|
|
138
|
+
}
|
|
130
139
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
131
140
|
}
|
|
132
141
|
static capitalizeEachWords(str, natural) {
|
|
142
|
+
if (!str) {
|
|
143
|
+
return '';
|
|
144
|
+
}
|
|
133
145
|
const splitStr = str.trim().toLowerCase().split(' ');
|
|
134
146
|
for (let i = 0, iLen = splitStr.length; i < iLen; i += 1) {
|
|
135
147
|
if (!natural || !this.contains(splitStr[i], [
|
|
@@ -142,9 +154,15 @@ export default class Qsu {
|
|
|
142
154
|
return this.capitalizeFirst(splitStr.join(' '));
|
|
143
155
|
}
|
|
144
156
|
static strNumberOf(str, search) {
|
|
157
|
+
if (!str) {
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
145
160
|
return (str.match(new RegExp(search, 'g')) || []).length;
|
|
146
161
|
}
|
|
147
162
|
static strShuffle(str) {
|
|
163
|
+
if (!str) {
|
|
164
|
+
return '';
|
|
165
|
+
}
|
|
148
166
|
return [...str].sort(() => Math.random() - 0.5).join('');
|
|
149
167
|
}
|
|
150
168
|
static strRandom(length, additionalCharacters) {
|
|
@@ -160,6 +178,9 @@ export default class Qsu {
|
|
|
160
178
|
return result;
|
|
161
179
|
}
|
|
162
180
|
static strBlindRandom(str, blindLength, blindStr = '*') {
|
|
181
|
+
if (!str) {
|
|
182
|
+
return '';
|
|
183
|
+
}
|
|
163
184
|
let currentStr = str;
|
|
164
185
|
let hideCount = 0;
|
|
165
186
|
let tempIdx = 0;
|
|
@@ -176,16 +197,19 @@ export default class Qsu {
|
|
|
176
197
|
return currentStr;
|
|
177
198
|
}
|
|
178
199
|
static truncate(str, length, ellipsis = '') {
|
|
179
|
-
let convStr = str;
|
|
180
200
|
if (!str) {
|
|
181
201
|
return '';
|
|
182
202
|
}
|
|
203
|
+
let convStr = str;
|
|
183
204
|
if (str.length > length) {
|
|
184
205
|
convStr = str.substring(0, length) + ellipsis;
|
|
185
206
|
}
|
|
186
207
|
return convStr;
|
|
187
208
|
}
|
|
188
209
|
static split(str, ...splitter) {
|
|
210
|
+
if (!str) {
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
189
213
|
const splitters = splitter.length > 0 && typeof splitter[0] === 'object' ? splitter[0] : splitter;
|
|
190
214
|
const splitterLength = splitters.length;
|
|
191
215
|
let charPattern = '';
|
|
@@ -257,6 +281,9 @@ export default class Qsu {
|
|
|
257
281
|
return Buffer.from(encodedStr, 'base64').toString('utf8');
|
|
258
282
|
}
|
|
259
283
|
static strUnique(str) {
|
|
284
|
+
if (!str) {
|
|
285
|
+
return '';
|
|
286
|
+
}
|
|
260
287
|
return [...new Set(str)].join('');
|
|
261
288
|
}
|
|
262
289
|
/*
|