express-ext 0.3.2 → 0.3.4
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/lib/index.js +63 -0
- package/package.json +1 -1
- package/src/index.ts +91 -31
package/lib/index.js
CHANGED
|
@@ -305,6 +305,17 @@ var UserReactionController = (function () {
|
|
|
305
305
|
exports.UserReactionController = UserReactionController;
|
|
306
306
|
exports.ReactController = UserReactionController;
|
|
307
307
|
exports.ReactionController = UserReactionController;
|
|
308
|
+
function checked(s, v) {
|
|
309
|
+
if (s) {
|
|
310
|
+
if (Array.isArray(s)) {
|
|
311
|
+
return s.includes(v);
|
|
312
|
+
} else {
|
|
313
|
+
return s === v;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
exports.checked = checked;
|
|
308
319
|
function addSeconds(date, number) {
|
|
309
320
|
var d = new Date(date);
|
|
310
321
|
d.setSeconds(d.getSeconds() + number);
|
|
@@ -335,3 +346,55 @@ function toMap(errors) {
|
|
|
335
346
|
return errorMap;
|
|
336
347
|
}
|
|
337
348
|
exports.toMap = toMap;
|
|
349
|
+
var map = {
|
|
350
|
+
'&': '&',
|
|
351
|
+
'<': '<',
|
|
352
|
+
'>': '>',
|
|
353
|
+
'"': '"',
|
|
354
|
+
"'": ''',
|
|
355
|
+
'`': '`',
|
|
356
|
+
};
|
|
357
|
+
function escapeHtml(input) {
|
|
358
|
+
return input.replace(/[&<>"'`]/g, function (char) {
|
|
359
|
+
return map[char];
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
var s = 'string';
|
|
363
|
+
var o = 'object';
|
|
364
|
+
function escapeHTML(obj) {
|
|
365
|
+
if (!obj || typeof obj !== s) {
|
|
366
|
+
return obj;
|
|
367
|
+
}
|
|
368
|
+
var keys = Object.keys(obj);
|
|
369
|
+
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
370
|
+
var key = keys_1[_i];
|
|
371
|
+
var v = obj[key];
|
|
372
|
+
if (typeof v === s) {
|
|
373
|
+
obj[key] = escapeHtml(v);
|
|
374
|
+
} else if (Array.isArray(v) && v.length > 0) {
|
|
375
|
+
var v1 = v[0];
|
|
376
|
+
if (typeof v1 === o && !(v1 instanceof Date)) {
|
|
377
|
+
for (var _a = 0, v_1 = v; _a < v_1.length; _a++) {
|
|
378
|
+
var item = v_1[_a];
|
|
379
|
+
escapeHTML(item);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
} else if (typeof v === o && !(v instanceof Date)) {
|
|
383
|
+
escapeHTML(obj[key]);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return obj;
|
|
387
|
+
}
|
|
388
|
+
function escapeArray(arrs) {
|
|
389
|
+
if (!arrs) {
|
|
390
|
+
return arrs;
|
|
391
|
+
}
|
|
392
|
+
if (arrs.length > 0) {
|
|
393
|
+
for (var _i = 0, arrs_1 = arrs; _i < arrs_1.length; _i++) {
|
|
394
|
+
var obj = arrs_1[_i];
|
|
395
|
+
escapeHTML(obj);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return arrs;
|
|
399
|
+
}
|
|
400
|
+
exports.escapeArray = escapeArray;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -8,37 +8,38 @@ import { LoadSearchController } from './LoadSearchController';
|
|
|
8
8
|
import { LogController } from './LogController';
|
|
9
9
|
import { Controller, Service } from './LowCodeController';
|
|
10
10
|
import { ErrorMessage } from './metadata';
|
|
11
|
+
import { StringMap } from './resources';
|
|
11
12
|
import { SearchController } from './SearchController';
|
|
12
13
|
|
|
13
14
|
export { HealthController as HealthHandler, LoadController as LoadHandler, LogController as LogHandler, LoadController as ViewHandler };
|
|
14
15
|
// export {LoadController as ViewController};
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
export {
|
|
18
|
+
GenericController as GenericHandler,
|
|
19
|
+
GenericSearchController as GenericSearchHandler,
|
|
20
|
+
Controller as Handler,
|
|
21
|
+
LoadSearchController as LoadSearchHandler,
|
|
22
|
+
Service as LowCodeService,
|
|
23
|
+
SearchController as SearchHandler,
|
|
24
|
+
};
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
export * from './client';
|
|
27
|
+
export * from './edit';
|
|
28
|
+
export * from './GenericController';
|
|
29
|
+
export * from './GenericSearchController';
|
|
30
|
+
export * from './health';
|
|
31
|
+
export * from './HealthController';
|
|
32
|
+
export * from './http';
|
|
33
|
+
export * from './LoadController';
|
|
34
|
+
export * from './LoadSearchController';
|
|
35
|
+
export * from './log';
|
|
36
|
+
export * from './LogController';
|
|
37
|
+
export * from './LowCodeController';
|
|
38
|
+
export * from './metadata';
|
|
39
|
+
export * from './resources';
|
|
40
|
+
export * from './search';
|
|
41
|
+
export * from './SearchController';
|
|
42
|
+
export * from './view';
|
|
42
43
|
|
|
43
44
|
export interface AccessConfig {
|
|
44
45
|
origin?: string | string[];
|
|
@@ -292,6 +293,16 @@ export class UserReactionController {
|
|
|
292
293
|
export const ReactController = UserReactionController;
|
|
293
294
|
export const ReactionController = UserReactionController;
|
|
294
295
|
|
|
296
|
+
export function checked(s: string[] | string | undefined, v: string): boolean | undefined {
|
|
297
|
+
if (s) {
|
|
298
|
+
if (Array.isArray(s)) {
|
|
299
|
+
return s.includes(v);
|
|
300
|
+
} else {
|
|
301
|
+
return s === v;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
295
306
|
export function addSeconds(date: Date, number: number): Date {
|
|
296
307
|
const d = new Date(date);
|
|
297
308
|
d.setSeconds(d.getSeconds() + number);
|
|
@@ -308,16 +319,65 @@ export function addDays(d: Date, n: number): Date {
|
|
|
308
319
|
return newDate;
|
|
309
320
|
}
|
|
310
321
|
export interface ErrorMap {
|
|
311
|
-
[key: string]: ErrorMessage
|
|
322
|
+
[key: string]: ErrorMessage;
|
|
312
323
|
}
|
|
313
324
|
export function toMap(errors: ErrorMessage[]): ErrorMap {
|
|
314
|
-
const errorMap: ErrorMap = {}
|
|
325
|
+
const errorMap: ErrorMap = {};
|
|
315
326
|
if (!errors) {
|
|
316
|
-
return errorMap
|
|
327
|
+
return errorMap;
|
|
317
328
|
}
|
|
318
329
|
for (let i = 0; i < errors.length; i++) {
|
|
319
|
-
errors[i].invalid =
|
|
320
|
-
errorMap[errors[i].field] = errors[i]
|
|
330
|
+
errors[i].invalid = 'invalid';
|
|
331
|
+
errorMap[errors[i].field] = errors[i];
|
|
332
|
+
}
|
|
333
|
+
return errorMap;
|
|
334
|
+
}
|
|
335
|
+
const map: StringMap = {
|
|
336
|
+
'&': '&',
|
|
337
|
+
'<': '<',
|
|
338
|
+
'>': '>',
|
|
339
|
+
'"': '"',
|
|
340
|
+
"'": ''',
|
|
341
|
+
'`': '`',
|
|
342
|
+
};
|
|
343
|
+
function escapeHtml(input: string): string {
|
|
344
|
+
return input.replace(/[&<>"'`]/g, function (char) {
|
|
345
|
+
return map[char];
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const s = 'string';
|
|
350
|
+
const o = 'object';
|
|
351
|
+
function escapeHTML(obj: any): any {
|
|
352
|
+
if (!obj || typeof obj !== s) {
|
|
353
|
+
return obj;
|
|
354
|
+
}
|
|
355
|
+
const keys = Object.keys(obj);
|
|
356
|
+
for (const key of keys) {
|
|
357
|
+
const v = obj[key];
|
|
358
|
+
if (typeof v === s) {
|
|
359
|
+
obj[key] = escapeHtml(v);
|
|
360
|
+
} else if (Array.isArray(v) && v.length > 0) {
|
|
361
|
+
const v1 = v[0];
|
|
362
|
+
if (typeof v1 === o && !(v1 instanceof Date)) {
|
|
363
|
+
for (const item of v) {
|
|
364
|
+
escapeHTML(item);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
} else if (typeof v === o && !(v instanceof Date)) {
|
|
368
|
+
escapeHTML(obj[key]);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return obj;
|
|
372
|
+
}
|
|
373
|
+
export function escapeArray<T>(arrs: T[]): T[] {
|
|
374
|
+
if (!arrs) {
|
|
375
|
+
return arrs;
|
|
376
|
+
}
|
|
377
|
+
if (arrs.length > 0) {
|
|
378
|
+
for (const obj of arrs) {
|
|
379
|
+
escapeHTML(obj);
|
|
380
|
+
}
|
|
321
381
|
}
|
|
322
|
-
return
|
|
382
|
+
return arrs;
|
|
323
383
|
}
|