express-ext 0.4.12 → 0.4.15

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/access.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ function allow(access) {
4
+ var ao = access.origin
5
+ if (typeof ao === "string") {
6
+ return function (req, res, next) {
7
+ res.header("Access-Control-Allow-Origin", access.origin)
8
+ res.header("Access-Control-Allow-Credentials", access.credentials)
9
+ res.header("Access-Control-Allow-Methods", access.methods)
10
+ res.setHeader("Access-Control-Allow-Headers", access.headers)
11
+ next()
12
+ }
13
+ } else if (Array.isArray(ao) && ao.length > 0) {
14
+ return function (req, res, next) {
15
+ var origin = req.headers.origin
16
+ if (origin) {
17
+ if (ao.includes(origin)) {
18
+ res.setHeader("Access-Control-Allow-Origin", origin)
19
+ }
20
+ }
21
+ res.header("Access-Control-Allow-Credentials", access.credentials)
22
+ res.header("Access-Control-Allow-Methods", access.methods)
23
+ res.setHeader("Access-Control-Allow-Headers", access.headers)
24
+ next()
25
+ }
26
+ }
27
+ return function (req, res, next) {
28
+ res.header("Access-Control-Allow-Credentials", access.credentials)
29
+ res.header("Access-Control-Allow-Methods", access.methods)
30
+ res.setHeader("Access-Control-Allow-Headers", access.headers)
31
+ next()
32
+ }
33
+ }
34
+ exports.allow = allow
package/lib/index.js CHANGED
@@ -22,6 +22,7 @@ exports.Handler = LowCodeController_1.Controller
22
22
  var resources_1 = require("./resources")
23
23
  var SearchController_1 = require("./SearchController")
24
24
  exports.SearchHandler = SearchController_1.SearchController
25
+ __export(require("./access"))
25
26
  __export(require("./client"))
26
27
  __export(require("./edit"))
27
28
  __export(require("./GenericController"))
@@ -38,38 +39,6 @@ __export(require("./resources"))
38
39
  __export(require("./search"))
39
40
  __export(require("./SearchController"))
40
41
  __export(require("./view"))
41
- function allow(access) {
42
- var ao = access.origin
43
- if (typeof ao === "string") {
44
- return function (req, res, next) {
45
- res.header("Access-Control-Allow-Origin", access.origin)
46
- res.header("Access-Control-Allow-Credentials", access.credentials)
47
- res.header("Access-Control-Allow-Methods", access.methods)
48
- res.setHeader("Access-Control-Allow-Headers", access.headers)
49
- next()
50
- }
51
- } else if (Array.isArray(ao) && ao.length > 0) {
52
- return function (req, res, next) {
53
- var origin = req.headers.origin
54
- if (origin) {
55
- if (ao.includes(origin)) {
56
- res.setHeader("Access-Control-Allow-Origin", origin)
57
- }
58
- }
59
- res.header("Access-Control-Allow-Credentials", access.credentials)
60
- res.header("Access-Control-Allow-Methods", access.methods)
61
- res.setHeader("Access-Control-Allow-Headers", access.headers)
62
- next()
63
- }
64
- }
65
- return function (req, res, next) {
66
- res.header("Access-Control-Allow-Credentials", access.credentials)
67
- res.header("Access-Control-Allow-Methods", access.methods)
68
- res.setHeader("Access-Control-Allow-Headers", access.headers)
69
- next()
70
- }
71
- }
72
- exports.allow = allow
73
42
  var SavedController = (function () {
74
43
  function SavedController(log, service, item, id) {
75
44
  this.log = log
@@ -400,22 +369,45 @@ function escapeHTML(input) {
400
369
  })
401
370
  }
402
371
  exports.escapeHTML = escapeHTML
403
- function generateChip(v, noClose) {
372
+ function generateChip(value, text, noClose, hasStar) {
404
373
  var s = noClose ? "" : '<span class="close" onclick="removeChip(event)"></span>'
405
- return '<div class="chip">' + escapeHTML(v) + s + "</div>"
374
+ var t = hasStar ? '<i className="star highlight"></i>' : ""
375
+ return '<div class="chip" data-value="' + escapeHTML(value) + '">' + escapeHTML(text) + t + s + "</div>"
406
376
  }
407
377
  exports.generateChip = generateChip
378
+ function generateTags(v, noClose) {
379
+ return !v
380
+ ? ""
381
+ : "" +
382
+ v
383
+ .map(function (s) {
384
+ return generateChip(s, s, noClose)
385
+ })
386
+ .join("")
387
+ }
388
+ exports.generateTags = generateTags
408
389
  function generateChips(v, noClose) {
409
390
  return !v
410
391
  ? ""
411
392
  : "" +
412
393
  v
413
394
  .map(function (s) {
414
- return generateChip(s, noClose)
395
+ return generateChip(s.value, s.text, noClose)
415
396
  })
416
397
  .join("")
417
398
  }
418
399
  exports.generateChips = generateChips
400
+ function generateStarChips(v, value, text, star, noClose) {
401
+ return !v
402
+ ? ""
403
+ : "" +
404
+ v
405
+ .map(function (s) {
406
+ return generateChip(s[value], s[text], noClose, s[star] === true)
407
+ })
408
+ .join("")
409
+ }
410
+ exports.generateStarChips = generateStarChips
419
411
  var s = "string"
420
412
  var o = "object"
421
413
  function escape(obj) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-ext",
3
- "version": "0.4.12",
3
+ "version": "0.4.15",
4
4
  "description": "express-ext",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/access.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { NextFunction } from "express"
2
+ import { ParamsDictionary, Request, Response } from "express-serve-static-core"
3
+ import { ParsedQs } from "qs"
4
+
5
+ export interface AccessConfig {
6
+ origin?: string | string[]
7
+ credentials?: string | string[]
8
+ methods?: string | string[]
9
+ headers: number | string | ReadonlyArray<string>
10
+ }
11
+ export type AccessControlAllowConfig = AccessConfig
12
+ export function allow(
13
+ access: AccessConfig,
14
+ ): (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>, next: NextFunction) => void {
15
+ const ao = access.origin
16
+ if (typeof ao === "string") {
17
+ return (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>, next: NextFunction) => {
18
+ res.header("Access-Control-Allow-Origin", access.origin)
19
+ res.header("Access-Control-Allow-Credentials", access.credentials)
20
+ res.header("Access-Control-Allow-Methods", access.methods)
21
+ res.setHeader("Access-Control-Allow-Headers", access.headers)
22
+ next()
23
+ }
24
+ } else if (Array.isArray(ao) && ao.length > 0) {
25
+ return (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>, next: NextFunction) => {
26
+ const origin = req.headers.origin
27
+ if (origin) {
28
+ if (ao.includes(origin)) {
29
+ res.setHeader("Access-Control-Allow-Origin", origin)
30
+ }
31
+ }
32
+ res.header("Access-Control-Allow-Credentials", access.credentials)
33
+ res.header("Access-Control-Allow-Methods", access.methods)
34
+ res.setHeader("Access-Control-Allow-Headers", access.headers)
35
+ next()
36
+ }
37
+ }
38
+ return (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>, next: NextFunction) => {
39
+ res.header("Access-Control-Allow-Credentials", access.credentials)
40
+ res.header("Access-Control-Allow-Methods", access.methods)
41
+ res.setHeader("Access-Control-Allow-Headers", access.headers)
42
+ next()
43
+ }
44
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NextFunction, Request, Response } from "express"
1
+ import { Request, Response } from "express"
2
2
  import { GenericController } from "./GenericController"
3
3
  import { GenericSearchController } from "./GenericSearchController"
4
4
  import { HealthController } from "./HealthController"
@@ -23,6 +23,7 @@ export {
23
23
  SearchController as SearchHandler,
24
24
  }
25
25
 
26
+ export * from "./access"
26
27
  export * from "./client"
27
28
  export * from "./edit"
28
29
  export * from "./GenericController"
@@ -41,44 +42,6 @@ export * from "./search"
41
42
  export * from "./SearchController"
42
43
  export * from "./view"
43
44
 
44
- export interface AccessConfig {
45
- origin?: string | string[]
46
- credentials?: string | string[]
47
- methods?: string | string[]
48
- headers: number | string | ReadonlyArray<string>
49
- }
50
- export type AccessControlAllowConfig = AccessConfig
51
- export function allow(access: AccessConfig): (req: Request, res: Response, next: NextFunction) => void {
52
- const ao = access.origin
53
- if (typeof ao === "string") {
54
- return (req: Request, res: Response, next: NextFunction) => {
55
- res.header("Access-Control-Allow-Origin", access.origin)
56
- res.header("Access-Control-Allow-Credentials", access.credentials)
57
- res.header("Access-Control-Allow-Methods", access.methods)
58
- res.setHeader("Access-Control-Allow-Headers", access.headers)
59
- next()
60
- }
61
- } else if (Array.isArray(ao) && ao.length > 0) {
62
- return (req: Request, res: Response, next: NextFunction) => {
63
- const origin = req.headers.origin
64
- if (origin) {
65
- if (ao.includes(origin)) {
66
- res.setHeader("Access-Control-Allow-Origin", origin)
67
- }
68
- }
69
- res.header("Access-Control-Allow-Credentials", access.credentials)
70
- res.header("Access-Control-Allow-Methods", access.methods)
71
- res.setHeader("Access-Control-Allow-Headers", access.headers)
72
- next()
73
- }
74
- }
75
- return (req: Request, res: Response, next: NextFunction) => {
76
- res.header("Access-Control-Allow-Credentials", access.credentials)
77
- res.header("Access-Control-Allow-Methods", access.methods)
78
- res.setHeader("Access-Control-Allow-Headers", access.headers)
79
- next()
80
- }
81
- }
82
45
  export interface SavedService<T> {
83
46
  load(id: string): Promise<T[]>
84
47
  save(id: string, itemId: string): Promise<number>
@@ -384,12 +347,23 @@ export function escapeHTML(input: string): string {
384
347
  return map[char]
385
348
  })
386
349
  }
387
- export function generateChip(v: string, noClose?: boolean): string {
350
+ export function generateChip(value: string, text: string, noClose?: boolean, hasStar?: boolean): string {
388
351
  const s = noClose ? "" : `<span class="close" onclick="removeChip(event)"></span>`
389
- return `<div class="chip">${escapeHTML(v)}${s}</div>`
352
+ const t = hasStar ? `<i className="star highlight"></i>` : ""
353
+ return `<div class="chip" data-value="${escapeHTML(value)}">${escapeHTML(text)}${t}${s}</div>`
354
+ }
355
+ export function generateTags(v?: string[] | null, noClose?: boolean): string {
356
+ return !v ? "" : `${v.map((s) => generateChip(s, s, noClose)).join("")}`
357
+ }
358
+ export interface Item {
359
+ value: string
360
+ text: string
361
+ }
362
+ export function generateChips(v?: Item[] | null, noClose?: boolean): string {
363
+ return !v ? "" : `${v.map((s) => generateChip(s.value, s.text, noClose)).join("")}`
390
364
  }
391
- export function generateChips(v?: string[] | null, noClose?: boolean): string {
392
- return !v ? "" : `${v.map((s) => generateChip(s, noClose)).join("")}`
365
+ export function generateStarChips(v: any[] | null | undefined, value: string, text: string, star: string, noClose?: boolean): string {
366
+ return !v ? "" : `${v.map((s) => generateChip(s[value], s[text], noClose, s[star] === true)).join("")}`
393
367
  }
394
368
 
395
369
  const s = "string"