@poppinss/utils 4.0.4 → 6.0.0-0
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/README.md +661 -873
- package/build/index.d.ts +16 -10
- package/build/index.js +21 -53
- package/build/lodash/main.cjs +37 -0
- package/build/src/{Helpers/base64.d.ts → base64.d.ts} +7 -23
- package/build/src/{Helpers/base64.js → base64.js} +9 -22
- package/build/src/compose.d.ts +17 -0
- package/build/src/compose.js +3 -0
- package/build/src/{defineStaticProperty.d.ts → define_static_property.d.ts} +2 -6
- package/build/src/define_static_property.js +21 -0
- package/build/src/exception.d.ts +16 -0
- package/build/src/exception.js +29 -0
- package/build/src/flatten.d.ts +1 -1
- package/build/src/flatten.js +4 -13
- package/build/src/fs_import_all.d.ts +3 -0
- package/build/src/fs_import_all.js +28 -0
- package/build/src/fs_read_all.d.ts +3 -0
- package/build/src/fs_read_all.js +55 -0
- package/build/src/is_script_file.d.ts +1 -0
- package/build/src/is_script_file.js +12 -0
- package/build/src/json/main.d.ts +7 -0
- package/build/src/json/main.js +6 -0
- package/build/src/json/safe_parse.d.ts +2 -0
- package/build/src/json/safe_parse.js +7 -0
- package/build/src/json/safe_stringify.d.ts +2 -0
- package/build/src/json/safe_stringify.js +18 -0
- package/build/src/message_builder.d.ts +5 -0
- package/build/src/message_builder.js +43 -0
- package/build/src/natural_sort.d.ts +1 -0
- package/build/src/natural_sort.js +3 -0
- package/build/src/object_builder.d.ts +10 -0
- package/build/src/object_builder.js +31 -0
- package/build/src/{Helpers/safeEqual.d.ts → safe_equal.d.ts} +1 -4
- package/build/src/safe_equal.js +14 -0
- package/build/src/slash.d.ts +1 -5
- package/build/src/slash.js +1 -24
- package/build/src/string/bytes.d.ts +6 -0
- package/build/src/string/bytes.js +12 -0
- package/build/src/string/change_case.d.ts +13 -0
- package/build/src/string/change_case.js +75 -0
- package/build/src/string/excerpt.d.ts +4 -0
- package/build/src/string/excerpt.js +10 -0
- package/build/src/string/interpolate.d.ts +1 -0
- package/build/src/{Helpers → string}/interpolate.js +1 -22
- package/build/src/string/main.d.ts +46 -0
- package/build/src/string/main.js +42 -0
- package/build/src/string/milliseconds.d.ts +5 -0
- package/build/src/string/milliseconds.js +16 -0
- package/build/src/string/ordinal.d.ts +1 -0
- package/build/src/string/ordinal.js +21 -0
- package/build/src/string/pluralize.d.ts +12 -0
- package/build/src/string/pluralize.js +12 -0
- package/build/src/string/random.d.ts +1 -0
- package/build/src/string/random.js +7 -0
- package/build/src/string/seconds.d.ts +5 -0
- package/build/src/string/seconds.js +16 -0
- package/build/src/string/slugify.d.ts +2 -0
- package/build/src/string/slugify.js +2 -0
- package/build/src/string/to_sentence.d.ts +5 -0
- package/build/src/string/to_sentence.js +13 -0
- package/build/src/string/truncate.d.ts +4 -0
- package/build/src/string/truncate.js +10 -0
- package/build/src/types.d.ts +14 -0
- package/build/src/types.js +1 -0
- package/lodash/lodash.types.d.ts +44 -0
- package/package.json +70 -82
- package/build/helpers.d.ts +0 -1
- package/build/helpers.js +0 -25
- package/build/src/Exception.d.ts +0 -17
- package/build/src/Exception.js +0 -68
- package/build/src/Helpers/MessageBuilder.d.ts +0 -28
- package/build/src/Helpers/MessageBuilder.js +0 -97
- package/build/src/Helpers/ObjectBuilder.d.ts +0 -46
- package/build/src/Helpers/ObjectBuilder.js +0 -75
- package/build/src/Helpers/compose.d.ts +0 -21
- package/build/src/Helpers/compose.js +0 -20
- package/build/src/Helpers/fsReadAll.d.ts +0 -4
- package/build/src/Helpers/fsReadAll.js +0 -23
- package/build/src/Helpers/index.d.ts +0 -14
- package/build/src/Helpers/index.js +0 -62
- package/build/src/Helpers/interpolate.d.ts +0 -7
- package/build/src/Helpers/requireAll.d.ts +0 -8
- package/build/src/Helpers/requireAll.js +0 -65
- package/build/src/Helpers/resolveDir.d.ts +0 -5
- package/build/src/Helpers/resolveDir.js +0 -46
- package/build/src/Helpers/resolveFrom.d.ts +0 -5
- package/build/src/Helpers/resolveFrom.js +0 -27
- package/build/src/Helpers/safeEqual.js +0 -42
- package/build/src/Helpers/string.d.ts +0 -124
- package/build/src/Helpers/string.js +0 -328
- package/build/src/Helpers/types.d.ts +0 -86
- package/build/src/Helpers/types.js +0 -161
- package/build/src/ManagerConfigValidator.d.ts +0 -20
- package/build/src/ManagerConfigValidator.js +0 -55
- package/build/src/defineStaticProperty.js +0 -57
- package/build/src/esmRequire.d.ts +0 -5
- package/build/src/esmRequire.js +0 -20
- package/build/src/esmResolver.d.ts +0 -1
- package/build/src/esmResolver.js +0 -15
- package/build/src/fast-safe-stringify.d.ts +0 -2
- package/build/src/fast-safe-stringify.js +0 -101
- package/build/src/isScriptFile.d.ts +0 -5
- package/build/src/isScriptFile.js +0 -28
- package/build/src/lodash.d.ts +0 -13
- package/build/src/lodash.js +0 -39
- package/build/src/safeParse.d.ts +0 -5
- package/build/src/safeParse.js +0 -42
- package/build/src/safeStringify.d.ts +0 -5
- package/build/src/safeStringify.js +0 -39
- package/types/lodash.types.d.ts +0 -65
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @poppinss/utils
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
-
}
|
|
16
|
-
Object.defineProperty(o, k2, desc);
|
|
17
|
-
}) : (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
o[k2] = m[k];
|
|
20
|
-
}));
|
|
21
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
-
}) : function(o, v) {
|
|
24
|
-
o["default"] = v;
|
|
25
|
-
});
|
|
26
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
27
|
-
if (mod && mod.__esModule) return mod;
|
|
28
|
-
var result = {};
|
|
29
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
30
|
-
__setModuleDefault(result, mod);
|
|
31
|
-
return result;
|
|
32
|
-
};
|
|
33
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
34
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
35
|
-
};
|
|
36
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.generateRandom = exports.toMs = exports.toBytes = exports.ordinalize = exports.isEmpty = exports.prettyMs = exports.prettyBytes = exports.toSentence = exports.encodeSymbols = exports.escapeHTML = exports.condenseWhitespace = exports.excerpt = exports.truncate = exports.singularize = exports.pluralize = exports.noCase = exports.dotCase = exports.sentenceCase = exports.capitalCase = exports.pascalCase = exports.dashCase = exports.snakeCase = exports.camelCase = exports.defineUncountableRule = exports.defineIrregularRule = exports.titleCase = exports.toSlug = void 0;
|
|
38
|
-
const ms_1 = __importDefault(require("ms"));
|
|
39
|
-
const truncatise_1 = __importDefault(require("truncatise"));
|
|
40
|
-
const crypto_1 = require("crypto");
|
|
41
|
-
const he_1 = __importDefault(require("he"));
|
|
42
|
-
const changeCase = __importStar(require("change-case"));
|
|
43
|
-
const bytes_1 = __importDefault(require("bytes"));
|
|
44
|
-
const pluralize_1 = require("pluralize");
|
|
45
|
-
var slugify_1 = require("slugify");
|
|
46
|
-
Object.defineProperty(exports, "toSlug", { enumerable: true, get: function () { return __importDefault(slugify_1).default; } });
|
|
47
|
-
const SMALL_WORDS = /\b(?:an?d?|a[st]|because|but|by|en|for|i[fn]|neither|nor|o[fnr]|only|over|per|so|some|tha[tn]|the|to|up|upon|vs?\.?|versus|via|when|with|without|yet)\b/i;
|
|
48
|
-
const TOKENS = /[^\s:–—-]+|./g;
|
|
49
|
-
const WHITESPACE = /\s/;
|
|
50
|
-
const IS_MANUAL_CASE = /.(?=[A-Z]|\..)/;
|
|
51
|
-
const ALPHANUMERIC_PATTERN = /[A-Za-z0-9\u00C0-\u00FF]/;
|
|
52
|
-
/**
|
|
53
|
-
* The method is a copy/paste from the "title-case" package. They have
|
|
54
|
-
* a dependency on "tslib", which I don't want.
|
|
55
|
-
*/
|
|
56
|
-
function titleCase(input) {
|
|
57
|
-
let output = '';
|
|
58
|
-
let result;
|
|
59
|
-
while ((result = TOKENS.exec(input)) !== null) {
|
|
60
|
-
const { 0: token, index } = result;
|
|
61
|
-
if (!IS_MANUAL_CASE.test(token) &&
|
|
62
|
-
(!SMALL_WORDS.test(token) || index === 0 || index + token.length === input.length) &&
|
|
63
|
-
(input.charAt(index + token.length) !== ':' ||
|
|
64
|
-
WHITESPACE.test(input.charAt(index + token.length + 1)))) {
|
|
65
|
-
output += token.replace(ALPHANUMERIC_PATTERN, (char) => char.toUpperCase());
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
output += token;
|
|
69
|
-
}
|
|
70
|
-
return output;
|
|
71
|
-
}
|
|
72
|
-
exports.titleCase = titleCase;
|
|
73
|
-
/**
|
|
74
|
-
* Normalizes base64 string by removing special chars and padding
|
|
75
|
-
*/
|
|
76
|
-
function normalizeBase64(value) {
|
|
77
|
-
return value.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Define an irregular rule
|
|
81
|
-
*/
|
|
82
|
-
function defineIrregularRule(singleValue, pluralValue) {
|
|
83
|
-
(0, pluralize_1.addIrregularRule)(singleValue, pluralValue);
|
|
84
|
-
}
|
|
85
|
-
exports.defineIrregularRule = defineIrregularRule;
|
|
86
|
-
/**
|
|
87
|
-
* Define uncountable rule
|
|
88
|
-
*/
|
|
89
|
-
function defineUncountableRule(word) {
|
|
90
|
-
(0, pluralize_1.addUncountableRule)(word);
|
|
91
|
-
}
|
|
92
|
-
exports.defineUncountableRule = defineUncountableRule;
|
|
93
|
-
/**
|
|
94
|
-
* Convert string to camelcase
|
|
95
|
-
*/
|
|
96
|
-
function camelCase(value) {
|
|
97
|
-
return changeCase.camelCase(value);
|
|
98
|
-
}
|
|
99
|
-
exports.camelCase = camelCase;
|
|
100
|
-
/**
|
|
101
|
-
* Convert string to snakecase
|
|
102
|
-
*/
|
|
103
|
-
function snakeCase(value) {
|
|
104
|
-
return changeCase.snakeCase(value);
|
|
105
|
-
}
|
|
106
|
-
exports.snakeCase = snakeCase;
|
|
107
|
-
/**
|
|
108
|
-
* Convert string to dashcase
|
|
109
|
-
*/
|
|
110
|
-
function dashCase(value, options) {
|
|
111
|
-
if (options && options.capitalize) {
|
|
112
|
-
return changeCase.headerCase(value);
|
|
113
|
-
}
|
|
114
|
-
return changeCase.paramCase(value);
|
|
115
|
-
}
|
|
116
|
-
exports.dashCase = dashCase;
|
|
117
|
-
/**
|
|
118
|
-
* Convert string to pascal case
|
|
119
|
-
*/
|
|
120
|
-
function pascalCase(value) {
|
|
121
|
-
return changeCase.pascalCase(value);
|
|
122
|
-
}
|
|
123
|
-
exports.pascalCase = pascalCase;
|
|
124
|
-
/**
|
|
125
|
-
* Convert string to capital case
|
|
126
|
-
*/
|
|
127
|
-
function capitalCase(value) {
|
|
128
|
-
return changeCase.capitalCase(value);
|
|
129
|
-
}
|
|
130
|
-
exports.capitalCase = capitalCase;
|
|
131
|
-
/**
|
|
132
|
-
* Convert string to sentence case
|
|
133
|
-
*/
|
|
134
|
-
function sentenceCase(value) {
|
|
135
|
-
return changeCase.sentenceCase(value);
|
|
136
|
-
}
|
|
137
|
-
exports.sentenceCase = sentenceCase;
|
|
138
|
-
/**
|
|
139
|
-
* Convert string to dot case
|
|
140
|
-
*/
|
|
141
|
-
function dotCase(value) {
|
|
142
|
-
return changeCase.dotCase(value);
|
|
143
|
-
}
|
|
144
|
-
exports.dotCase = dotCase;
|
|
145
|
-
/**
|
|
146
|
-
* Remove all sort of casing from the string
|
|
147
|
-
*/
|
|
148
|
-
function noCase(value) {
|
|
149
|
-
return changeCase.noCase(value);
|
|
150
|
-
}
|
|
151
|
-
exports.noCase = noCase;
|
|
152
|
-
/**
|
|
153
|
-
* Pluralize a word
|
|
154
|
-
*/
|
|
155
|
-
function pluralize(word) {
|
|
156
|
-
return (0, pluralize_1.plural)(word);
|
|
157
|
-
}
|
|
158
|
-
exports.pluralize = pluralize;
|
|
159
|
-
/**
|
|
160
|
-
* Singularize a word
|
|
161
|
-
*/
|
|
162
|
-
function singularize(word) {
|
|
163
|
-
return (0, pluralize_1.singular)(word);
|
|
164
|
-
}
|
|
165
|
-
exports.singularize = singularize;
|
|
166
|
-
/**
|
|
167
|
-
* Truncate a sentence till a give limit of characters
|
|
168
|
-
*/
|
|
169
|
-
function truncate(sentence, charactersLimit, options) {
|
|
170
|
-
return (0, truncatise_1.default)(sentence, {
|
|
171
|
-
TruncateLength: charactersLimit,
|
|
172
|
-
/**
|
|
173
|
-
* Do not complete words when "completeWords" is not explicitly set
|
|
174
|
-
* to true
|
|
175
|
-
*/
|
|
176
|
-
Strict: options && options.completeWords === true ? false : true,
|
|
177
|
-
StripHTML: false,
|
|
178
|
-
TruncateBy: 'characters',
|
|
179
|
-
Suffix: options && options.suffix,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
exports.truncate = truncate;
|
|
183
|
-
/**
|
|
184
|
-
* Same as truncate, but strips out the HTML
|
|
185
|
-
*/
|
|
186
|
-
function excerpt(sentence, charactersLimit, options) {
|
|
187
|
-
return (0, truncatise_1.default)(sentence, {
|
|
188
|
-
TruncateLength: charactersLimit,
|
|
189
|
-
/**
|
|
190
|
-
* Do not complete words when "completeWords" is not explicitly set
|
|
191
|
-
* to true
|
|
192
|
-
*/
|
|
193
|
-
Strict: options && options.completeWords === true ? false : true,
|
|
194
|
-
StripHTML: true,
|
|
195
|
-
TruncateBy: 'characters',
|
|
196
|
-
Suffix: options && options.suffix,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
exports.excerpt = excerpt;
|
|
200
|
-
/**
|
|
201
|
-
* Condenses multiple whitespaces from a string
|
|
202
|
-
*/
|
|
203
|
-
function condenseWhitespace(value) {
|
|
204
|
-
return value.trim().replace(/\s{2,}/g, ' ');
|
|
205
|
-
}
|
|
206
|
-
exports.condenseWhitespace = condenseWhitespace;
|
|
207
|
-
/**
|
|
208
|
-
* Escape HTML entities
|
|
209
|
-
*/
|
|
210
|
-
function escapeHTML(value, options) {
|
|
211
|
-
value = he_1.default.escape(value);
|
|
212
|
-
if (options && options.encodeSymbols) {
|
|
213
|
-
value = encodeSymbols(value, { allowUnsafeSymbols: true });
|
|
214
|
-
}
|
|
215
|
-
return value;
|
|
216
|
-
}
|
|
217
|
-
exports.escapeHTML = escapeHTML;
|
|
218
|
-
/**
|
|
219
|
-
* Encode symbols that aren’t printable ASCII symbols
|
|
220
|
-
*/
|
|
221
|
-
function encodeSymbols(value, options) {
|
|
222
|
-
return he_1.default.encode(value, options);
|
|
223
|
-
}
|
|
224
|
-
exports.encodeSymbols = encodeSymbols;
|
|
225
|
-
/**
|
|
226
|
-
* Convert array of values to a sentence
|
|
227
|
-
*/
|
|
228
|
-
function toSentence(values, options) {
|
|
229
|
-
/**
|
|
230
|
-
* Empty array
|
|
231
|
-
*/
|
|
232
|
-
if (values.length === 0) {
|
|
233
|
-
return '';
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Just one item
|
|
237
|
-
*/
|
|
238
|
-
if (values.length === 1) {
|
|
239
|
-
return values[0];
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Giving some love to two items, so that one can use oxford comma's
|
|
243
|
-
*/
|
|
244
|
-
if (values.length === 2) {
|
|
245
|
-
return `${values[0]}${options?.pairSeparator || ' and '}${values[1]}`;
|
|
246
|
-
}
|
|
247
|
-
const normalized = Object.assign({ separator: ', ', lastSeparator: ', and ' }, options);
|
|
248
|
-
/**
|
|
249
|
-
* Make sentence
|
|
250
|
-
*/
|
|
251
|
-
return `${values.slice(0, -1).join(normalized.separator)}${normalized.lastSeparator}${values[values.length - 1]}`;
|
|
252
|
-
}
|
|
253
|
-
exports.toSentence = toSentence;
|
|
254
|
-
/**
|
|
255
|
-
* Convert a number to a human readable string
|
|
256
|
-
*/
|
|
257
|
-
function prettyBytes(value, options) {
|
|
258
|
-
return bytes_1.default.format(value, options);
|
|
259
|
-
}
|
|
260
|
-
exports.prettyBytes = prettyBytes;
|
|
261
|
-
/**
|
|
262
|
-
* Convert milliseconds to a human readable string
|
|
263
|
-
*/
|
|
264
|
-
function prettyMs(value, options) {
|
|
265
|
-
return (0, ms_1.default)(value, options);
|
|
266
|
-
}
|
|
267
|
-
exports.prettyMs = prettyMs;
|
|
268
|
-
/**
|
|
269
|
-
* Find if a string is empty. Including any number of whitespaces
|
|
270
|
-
*/
|
|
271
|
-
function isEmpty(value) {
|
|
272
|
-
return value.trim().length === 0;
|
|
273
|
-
}
|
|
274
|
-
exports.isEmpty = isEmpty;
|
|
275
|
-
/**
|
|
276
|
-
* Ordinalize a give number or string
|
|
277
|
-
*/
|
|
278
|
-
function ordinalize(value) {
|
|
279
|
-
const transformedValue = Math.abs(typeof value === 'string' ? parseInt(value) : value);
|
|
280
|
-
if (!Number.isFinite(transformedValue) || Number.isNaN(transformedValue)) {
|
|
281
|
-
throw new Error('Cannot ordinalize NAN or infinite numbers');
|
|
282
|
-
}
|
|
283
|
-
const percent = transformedValue % 100;
|
|
284
|
-
if (percent >= 10 && percent <= 20) {
|
|
285
|
-
return `${value}th`;
|
|
286
|
-
}
|
|
287
|
-
const decimal = transformedValue % 10;
|
|
288
|
-
switch (decimal) {
|
|
289
|
-
case 1:
|
|
290
|
-
return `${value}st`;
|
|
291
|
-
case 2:
|
|
292
|
-
return `${value}nd`;
|
|
293
|
-
case 3:
|
|
294
|
-
return `${value}rd`;
|
|
295
|
-
default:
|
|
296
|
-
return `${value}th`;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
exports.ordinalize = ordinalize;
|
|
300
|
-
/**
|
|
301
|
-
* Converts unit expression to bytes
|
|
302
|
-
*/
|
|
303
|
-
function toBytes(value) {
|
|
304
|
-
if (typeof value === 'number') {
|
|
305
|
-
return value;
|
|
306
|
-
}
|
|
307
|
-
return bytes_1.default.parse(value);
|
|
308
|
-
}
|
|
309
|
-
exports.toBytes = toBytes;
|
|
310
|
-
/**
|
|
311
|
-
* Converts time expression to milliseconds
|
|
312
|
-
*/
|
|
313
|
-
function toMs(value) {
|
|
314
|
-
if (typeof value === 'number') {
|
|
315
|
-
return value;
|
|
316
|
-
}
|
|
317
|
-
return (0, ms_1.default)(value);
|
|
318
|
-
}
|
|
319
|
-
exports.toMs = toMs;
|
|
320
|
-
/**
|
|
321
|
-
* Generates a random string for a given size
|
|
322
|
-
*/
|
|
323
|
-
function generateRandom(size) {
|
|
324
|
-
const bits = (size + 1) * 6;
|
|
325
|
-
const buffer = (0, crypto_1.randomBytes)(Math.ceil(bits / 8));
|
|
326
|
-
return normalizeBase64(buffer.toString('base64')).slice(0, size);
|
|
327
|
-
}
|
|
328
|
-
exports.generateRandom = generateRandom;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/**
|
|
3
|
-
* Lookup the type for a given value
|
|
4
|
-
*/
|
|
5
|
-
export declare function lookup(value: any): 'undefined' | 'null' | 'boolean' | 'buffer' | 'number' | 'string' | 'arguments' | 'object' | 'date' | 'array' | 'regexp' | 'error' | 'function' | 'class' | 'generatorfunction' | 'symbol' | 'map' | 'weakmap' | 'set' | 'weakset' | 'int8array' | 'uint8array' | 'uint8clampedarray' | 'int16array' | 'uint16array' | 'int32array' | 'uint32array' | 'float32array' | 'float64array';
|
|
6
|
-
/**
|
|
7
|
-
* Find if a given value is undefined
|
|
8
|
-
*/
|
|
9
|
-
export declare function isUndefined(value: any): value is undefined;
|
|
10
|
-
/**
|
|
11
|
-
* Find if a given value is null
|
|
12
|
-
*/
|
|
13
|
-
export declare function isNull(value: any): value is null;
|
|
14
|
-
/**
|
|
15
|
-
* Find if a given value is a boolean
|
|
16
|
-
*/
|
|
17
|
-
export declare function isBoolean(value: any): value is boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Find if a given value is a buffer
|
|
20
|
-
*/
|
|
21
|
-
export declare function isBuffer(value: any): value is Buffer;
|
|
22
|
-
/**
|
|
23
|
-
* Find if a given value is a number
|
|
24
|
-
*/
|
|
25
|
-
export declare function isNumber(value: any): value is number;
|
|
26
|
-
/**
|
|
27
|
-
* Find if a given value is a string
|
|
28
|
-
*/
|
|
29
|
-
export declare function isString(value: any): value is string;
|
|
30
|
-
/**
|
|
31
|
-
* Find if a given value is function arguments
|
|
32
|
-
*/
|
|
33
|
-
export declare function isArguments(value: any): boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Find if a given value is a plain object
|
|
36
|
-
*/
|
|
37
|
-
export declare function isObject(value: any): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Find if a given value is a date instance
|
|
40
|
-
*/
|
|
41
|
-
export declare function isDate(value: any): value is Date;
|
|
42
|
-
/**
|
|
43
|
-
* Find if a given value is an array
|
|
44
|
-
*/
|
|
45
|
-
export declare function isArray(value: any): value is any[];
|
|
46
|
-
/**
|
|
47
|
-
* Find if a given value is an regularExpression
|
|
48
|
-
*/
|
|
49
|
-
export declare function isRegexp(value: any): value is RegExp;
|
|
50
|
-
/**
|
|
51
|
-
* Find if a given value is an instance of Error class
|
|
52
|
-
*/
|
|
53
|
-
export declare function isError(value: any): boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Find if a given value is a Function
|
|
56
|
-
*/
|
|
57
|
-
export declare function isFunction(value: any): value is Function;
|
|
58
|
-
/**
|
|
59
|
-
* Find if a given value is a class. Uses regular expression, since there
|
|
60
|
-
* is no way to natively distinguish a class and a function in Javascript
|
|
61
|
-
*/
|
|
62
|
-
export declare function isClass(value: any): boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Find if a value is an integer or not
|
|
65
|
-
*/
|
|
66
|
-
export declare function isInteger(value: number): value is number;
|
|
67
|
-
/**
|
|
68
|
-
* Find if a value is float value or not. The values with more than
|
|
69
|
-
* zero remainder returns true
|
|
70
|
-
*/
|
|
71
|
-
export declare function isFloat(value: number): value is number;
|
|
72
|
-
/**
|
|
73
|
-
* Find if the value has given decimal place or not.
|
|
74
|
-
*
|
|
75
|
-
* Since there is no direct way in Javascript to check for decimal place. We make
|
|
76
|
-
* use of regex to find it out.
|
|
77
|
-
*
|
|
78
|
-
* Numeric values are converted to string by calling `value.toString()` before
|
|
79
|
-
* testing it against the regex.
|
|
80
|
-
*
|
|
81
|
-
* If this method returns `true`, then you can safely parse the string with `parseFloat`
|
|
82
|
-
* method.
|
|
83
|
-
*/
|
|
84
|
-
export declare function isDecimal(value: string | number, options?: {
|
|
85
|
-
decimalPlaces?: string;
|
|
86
|
-
}): boolean;
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @poppinss/utils
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.isDecimal = exports.isFloat = exports.isInteger = exports.isClass = exports.isFunction = exports.isError = exports.isRegexp = exports.isArray = exports.isDate = exports.isObject = exports.isArguments = exports.isString = exports.isNumber = exports.isBuffer = exports.isBoolean = exports.isNull = exports.isUndefined = exports.lookup = void 0;
|
|
15
|
-
const kind_of_1 = __importDefault(require("kind-of"));
|
|
16
|
-
const toString = Function.prototype.toString;
|
|
17
|
-
/**
|
|
18
|
-
* Lookup the type for a given value
|
|
19
|
-
*/
|
|
20
|
-
function lookup(value) {
|
|
21
|
-
const kind = (0, kind_of_1.default)(value);
|
|
22
|
-
if (kind === 'function' && /^class\s/.test(toString.call(value))) {
|
|
23
|
-
return 'class';
|
|
24
|
-
}
|
|
25
|
-
return kind;
|
|
26
|
-
}
|
|
27
|
-
exports.lookup = lookup;
|
|
28
|
-
/**
|
|
29
|
-
* Find if a given value is undefined
|
|
30
|
-
*/
|
|
31
|
-
function isUndefined(value) {
|
|
32
|
-
return lookup(value) === 'undefined';
|
|
33
|
-
}
|
|
34
|
-
exports.isUndefined = isUndefined;
|
|
35
|
-
/**
|
|
36
|
-
* Find if a given value is null
|
|
37
|
-
*/
|
|
38
|
-
function isNull(value) {
|
|
39
|
-
return lookup(value) === 'null';
|
|
40
|
-
}
|
|
41
|
-
exports.isNull = isNull;
|
|
42
|
-
/**
|
|
43
|
-
* Find if a given value is a boolean
|
|
44
|
-
*/
|
|
45
|
-
function isBoolean(value) {
|
|
46
|
-
return lookup(value) === 'boolean';
|
|
47
|
-
}
|
|
48
|
-
exports.isBoolean = isBoolean;
|
|
49
|
-
/**
|
|
50
|
-
* Find if a given value is a buffer
|
|
51
|
-
*/
|
|
52
|
-
function isBuffer(value) {
|
|
53
|
-
return lookup(value) === 'buffer';
|
|
54
|
-
}
|
|
55
|
-
exports.isBuffer = isBuffer;
|
|
56
|
-
/**
|
|
57
|
-
* Find if a given value is a number
|
|
58
|
-
*/
|
|
59
|
-
function isNumber(value) {
|
|
60
|
-
return lookup(value) === 'number';
|
|
61
|
-
}
|
|
62
|
-
exports.isNumber = isNumber;
|
|
63
|
-
/**
|
|
64
|
-
* Find if a given value is a string
|
|
65
|
-
*/
|
|
66
|
-
function isString(value) {
|
|
67
|
-
return lookup(value) === 'string';
|
|
68
|
-
}
|
|
69
|
-
exports.isString = isString;
|
|
70
|
-
/**
|
|
71
|
-
* Find if a given value is function arguments
|
|
72
|
-
*/
|
|
73
|
-
function isArguments(value) {
|
|
74
|
-
return lookup(value) === 'arguments';
|
|
75
|
-
}
|
|
76
|
-
exports.isArguments = isArguments;
|
|
77
|
-
/**
|
|
78
|
-
* Find if a given value is a plain object
|
|
79
|
-
*/
|
|
80
|
-
function isObject(value) {
|
|
81
|
-
return lookup(value) === 'object';
|
|
82
|
-
}
|
|
83
|
-
exports.isObject = isObject;
|
|
84
|
-
/**
|
|
85
|
-
* Find if a given value is a date instance
|
|
86
|
-
*/
|
|
87
|
-
function isDate(value) {
|
|
88
|
-
return lookup(value) === 'date';
|
|
89
|
-
}
|
|
90
|
-
exports.isDate = isDate;
|
|
91
|
-
/**
|
|
92
|
-
* Find if a given value is an array
|
|
93
|
-
*/
|
|
94
|
-
function isArray(value) {
|
|
95
|
-
return lookup(value) === 'array';
|
|
96
|
-
}
|
|
97
|
-
exports.isArray = isArray;
|
|
98
|
-
/**
|
|
99
|
-
* Find if a given value is an regularExpression
|
|
100
|
-
*/
|
|
101
|
-
function isRegexp(value) {
|
|
102
|
-
return lookup(value) === 'regexp';
|
|
103
|
-
}
|
|
104
|
-
exports.isRegexp = isRegexp;
|
|
105
|
-
/**
|
|
106
|
-
* Find if a given value is an instance of Error class
|
|
107
|
-
*/
|
|
108
|
-
function isError(value) {
|
|
109
|
-
return lookup(value) === 'error';
|
|
110
|
-
}
|
|
111
|
-
exports.isError = isError;
|
|
112
|
-
/**
|
|
113
|
-
* Find if a given value is a Function
|
|
114
|
-
*/
|
|
115
|
-
function isFunction(value) {
|
|
116
|
-
return lookup(value) === 'function';
|
|
117
|
-
}
|
|
118
|
-
exports.isFunction = isFunction;
|
|
119
|
-
/**
|
|
120
|
-
* Find if a given value is a class. Uses regular expression, since there
|
|
121
|
-
* is no way to natively distinguish a class and a function in Javascript
|
|
122
|
-
*/
|
|
123
|
-
function isClass(value) {
|
|
124
|
-
return lookup(value) === 'class';
|
|
125
|
-
}
|
|
126
|
-
exports.isClass = isClass;
|
|
127
|
-
/**
|
|
128
|
-
* Find if a value is an integer or not
|
|
129
|
-
*/
|
|
130
|
-
function isInteger(value) {
|
|
131
|
-
return Number.isInteger(value);
|
|
132
|
-
}
|
|
133
|
-
exports.isInteger = isInteger;
|
|
134
|
-
/**
|
|
135
|
-
* Find if a value is float value or not. The values with more than
|
|
136
|
-
* zero remainder returns true
|
|
137
|
-
*/
|
|
138
|
-
function isFloat(value) {
|
|
139
|
-
return value !== (value | 0);
|
|
140
|
-
}
|
|
141
|
-
exports.isFloat = isFloat;
|
|
142
|
-
/**
|
|
143
|
-
* Find if the value has given decimal place or not.
|
|
144
|
-
*
|
|
145
|
-
* Since there is no direct way in Javascript to check for decimal place. We make
|
|
146
|
-
* use of regex to find it out.
|
|
147
|
-
*
|
|
148
|
-
* Numeric values are converted to string by calling `value.toString()` before
|
|
149
|
-
* testing it against the regex.
|
|
150
|
-
*
|
|
151
|
-
* If this method returns `true`, then you can safely parse the string with `parseFloat`
|
|
152
|
-
* method.
|
|
153
|
-
*/
|
|
154
|
-
function isDecimal(value, options) {
|
|
155
|
-
if (typeof value === 'number') {
|
|
156
|
-
value = value.toString();
|
|
157
|
-
}
|
|
158
|
-
const decimalPlaces = (options && options.decimalPlaces) || '1,';
|
|
159
|
-
return new RegExp(`^[-+]?([0-9]+)?(\\.[0-9]{${decimalPlaces}})$`).test(value);
|
|
160
|
-
}
|
|
161
|
-
exports.isDecimal = isDecimal;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A simple class to raise consistent exceptions for invalid config
|
|
3
|
-
* for driver based implementations.
|
|
4
|
-
*/
|
|
5
|
-
export declare class ManagerConfigValidator {
|
|
6
|
-
private config;
|
|
7
|
-
private serviceName;
|
|
8
|
-
private configLocation;
|
|
9
|
-
constructor(config: any, serviceName: string, configLocation: string);
|
|
10
|
-
/**
|
|
11
|
-
* Validates that the default key name is defined inside the config
|
|
12
|
-
* for a given module/service
|
|
13
|
-
*/
|
|
14
|
-
validateDefault(keyName: string): void;
|
|
15
|
-
/**
|
|
16
|
-
* Validates that the list to ensure that is is defined and the default
|
|
17
|
-
* key name is also part of the list.
|
|
18
|
-
*/
|
|
19
|
-
validateList(listName: string, keyName: string): void;
|
|
20
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @poppinss/utils
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.ManagerConfigValidator = void 0;
|
|
12
|
-
const Exception_1 = require("./Exception");
|
|
13
|
-
/**
|
|
14
|
-
* A simple class to raise consistent exceptions for invalid config
|
|
15
|
-
* for driver based implementations.
|
|
16
|
-
*/
|
|
17
|
-
class ManagerConfigValidator {
|
|
18
|
-
constructor(config, serviceName, configLocation) {
|
|
19
|
-
this.config = config;
|
|
20
|
-
this.serviceName = serviceName;
|
|
21
|
-
this.configLocation = configLocation;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Validates that the default key name is defined inside the config
|
|
25
|
-
* for a given module/service
|
|
26
|
-
*/
|
|
27
|
-
validateDefault(keyName) {
|
|
28
|
-
if (!this.config[keyName]) {
|
|
29
|
-
throw new Exception_1.Exception([
|
|
30
|
-
`Invalid "${this.serviceName}" config. Missing value for "${keyName}".`,
|
|
31
|
-
`Make sure to set it inside the "${this.configLocation}" file`,
|
|
32
|
-
].join(' '));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Validates that the list to ensure that is is defined and the default
|
|
37
|
-
* key name is also part of the list.
|
|
38
|
-
*/
|
|
39
|
-
validateList(listName, keyName) {
|
|
40
|
-
if (!this.config[listName]) {
|
|
41
|
-
throw new Exception_1.Exception([
|
|
42
|
-
`Invalid "${this.serviceName}" config. Missing value for "${listName}".`,
|
|
43
|
-
`Make sure to set it inside the "${this.configLocation}" file`,
|
|
44
|
-
].join(' '));
|
|
45
|
-
}
|
|
46
|
-
const defaultValue = this.config[keyName];
|
|
47
|
-
if (!this.config[listName][defaultValue]) {
|
|
48
|
-
throw new Exception_1.Exception([
|
|
49
|
-
`Invalid "${this.serviceName}" config. "${defaultValue}" is not defined inside "${listName}".`,
|
|
50
|
-
`Make sure to set it inside the "${this.configLocation}" file`,
|
|
51
|
-
].join(' '));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.ManagerConfigValidator = ManagerConfigValidator;
|