From 034ee6d63f0cd6132600e102244c53493f6a2db1 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 24 Nov 2022 20:51:48 +0800 Subject: [PATCH 1/3] fix inaccurate types --- lib/cache.ts | 2 +- lib/permalink.ts | 3 +-- lib/relative_url.ts | 2 +- lib/url_for.ts | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/cache.ts b/lib/cache.ts index 605bae68..4b0de14a 100644 --- a/lib/cache.ts +++ b/lib/cache.ts @@ -21,7 +21,7 @@ export = class Cache { this.cache.delete(id); } - apply(id: string, value) { + apply(id: string, value): T { if (this.has(id)) return this.get(id); if (typeof value === 'function') value = value(); diff --git a/lib/permalink.ts b/lib/permalink.ts index 6b999b57..4e8b18bb 100644 --- a/lib/permalink.ts +++ b/lib/permalink.ts @@ -7,9 +7,8 @@ class Permalink { regex: RegExp; params: string[]; - constructor(rule: string, options: { segments?: any; }) { + constructor(rule: string, options: { segments?: any; } = {}) { if (!rule) { throw new TypeError('rule is required!'); } - options = options || {}; const segments = options.segments || {}; const params = []; const regex = escapeRegExp(rule) diff --git a/lib/relative_url.ts b/lib/relative_url.ts index 8c2080a2..a90fab00 100644 --- a/lib/relative_url.ts +++ b/lib/relative_url.ts @@ -1,6 +1,6 @@ import encodeURL from './encode_url'; import Cache from './cache'; -const cache = new Cache(); +const cache = new Cache(); function relativeUrlHelper(from = '', to = '') { return cache.apply(`${from}-${to}`, () => { diff --git a/lib/url_for.ts b/lib/url_for.ts index 482b8e53..7ab50408 100644 --- a/lib/url_for.ts +++ b/lib/url_for.ts @@ -3,7 +3,7 @@ import encodeURL from './encode_url'; import relative_url from './relative_url'; import prettyUrls from './pretty_urls'; import Cache from './cache'; -const cache = new Cache(); +const cache = new Cache(); function urlForHelper(path = '/', options) { if (/^(#|\/\/|http(s)?:)/.test(path)) return path; From 272adc81f01a48d039c2d89d164d96ee01941e8e Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Fri, 25 Nov 2022 01:12:47 +0800 Subject: [PATCH 2/3] update htmlTag --- lib/html_tag.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/html_tag.ts b/lib/html_tag.ts index c5efc318..4d357a70 100644 --- a/lib/html_tag.ts +++ b/lib/html_tag.ts @@ -15,7 +15,7 @@ function encSrcset(str: string) { } function htmlTag(tag: string, attrs: { - [key: string]: string | boolean; + [key: string]: string | boolean | null | undefined; }, text?: string, escape = true) { if (!tag) throw new TypeError('tag is required!'); From 62ba5040f18ae14bd3d04bff6cbd5c19614b29dc Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Fri, 25 Nov 2022 12:36:04 +0800 Subject: [PATCH 3/3] permalink --- lib/permalink.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/permalink.ts b/lib/permalink.ts index 4e8b18bb..53fdac89 100644 --- a/lib/permalink.ts +++ b/lib/permalink.ts @@ -2,12 +2,18 @@ import escapeRegExp from './escape_regexp'; const rParam = /:(\w*[^_\W])/g; +interface Options { + segments?: { + [key: string]: RegExp | string; + } +} + class Permalink { rule: string; regex: RegExp; params: string[]; - constructor(rule: string, options: { segments?: any; } = {}) { + constructor(rule: string, options: Options = {}) { if (!rule) { throw new TypeError('rule is required!'); } const segments = options.segments || {}; const params = [];