Skip to content

Commit bc338bf

Browse files
committed
deno
1 parent 464c821 commit bc338bf

File tree

10 files changed

+82
-31
lines changed

10 files changed

+82
-31
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,4 @@ dist
114114
.yarn/build-state.yml
115115
.yarn/install-state.gz
116116
.pnp.*
117+
#.vscode/settings.json

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"deno.enable": true,
3+
"deno.lint": true,
4+
"deno.unstable": true,
5+
"deno.config": "deno.json",
6+
"deno.importMap": "import_map.json"
7+
}

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
# leetcode-test
22

33
#### 介绍
4+
45
leetcode测试
56

67
#### 软件架构
7-
软件架构说明
88

9+
软件架构说明
910

1011
#### 安装教程
1112

12-
1. xxxx
13-
2. xxxx
14-
3. xxxx
13+
1. xxxx
14+
2. xxxx
15+
3. xxxx
1516

1617
#### 使用说明
1718

18-
1. xxxx
19-
2. xxxx
20-
3. xxxx
19+
1. 测试
20+
21+
```
22+
./test.cmd
23+
```
2124

2225
#### 参与贡献
2326

24-
1. Fork 本仓库
25-
2. 新建 Feat_xxx 分支
26-
3. 提交代码
27-
4. 新建 Pull Request
27+
1. Fork 本仓库
28+
2. 新建 Feat_xxx 分支
29+
3. 提交代码
30+
4. 新建 Pull Request

deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "importMap": "import_map.json" }

deps.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { assert } from "asserts";
2+
export { assert };

fmt.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deno fmt

html-entity-parser/index.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
/*https://leetcode-cn.com/problems/html-entity-parser/*/
2-
export default entityParser;
3-
4-
function entityParser(text: string): string {
5-
return text.replace(entityRegExp,replacer);
6-
};
7-
const replacer=(a:string)=>{
8-
const value=translator.get(a);
9-
return value??a;
10-
}
11-
const translator=new Map<string,string>([
12-
["&quot;","\""],
13-
["&apos;","\'"],
14-
["&amp;","\&"],
15-
["&gt;","\>"],
16-
["&lt;","\<"],
17-
["&frasl;","\/"],
18-
19-
]);
20-
const entityRegExp=/\&[a-z]+\;/g;
1+
/*https://leetcode-cn.com/problems/html-entity-parser/*/
2+
export default entityParser;
3+
4+
function entityParser(text: string): string {
5+
return text.replace(entityRegExp, replacer);
6+
}
7+
const replacer = (a: string) => {
8+
const value = translator.get(a);
9+
return value ?? a;
10+
};
11+
const translator = new Map<string, string>([
12+
["&quot;", '"'],
13+
["&apos;", "'"],
14+
["&amp;", "&"],
15+
["&gt;", ">"],
16+
["&lt;", "<"],
17+
["&frasl;", "/"],
18+
]);
19+
const entityRegExp = /\&[a-z]+\;/g;

html-entity-parser/test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { assert } from "../deps.ts";
2+
import entityParser from "./index.ts";
3+
4+
Deno.test("html-entity-parser", () => {
5+
const testData: { input: string; output: string }[] = [
6+
{
7+
input: "&amp; is an HTML entity but &ambassador; is not.",
8+
output: "& is an HTML entity but &ambassador; is not.",
9+
},
10+
{
11+
input: "and I quote: &quot;...&quot;",
12+
output: 'and I quote: "..."',
13+
},
14+
{
15+
input: "Stay home! Practice on Leetcode :)",
16+
output: "Stay home! Practice on Leetcode :)",
17+
},
18+
{
19+
input: "x &gt; y &amp;&amp; x &lt; y is always false",
20+
output: "x > y && x < y is always false",
21+
},
22+
{
23+
input: "leetcode.com&frasl;problemset&frasl;all",
24+
output: "leetcode.com/problemset/all",
25+
},
26+
];
27+
28+
assert(
29+
testData.every(({ input, output }) => entityParser(input) === output),
30+
);
31+
});

import_map.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"imports": {
3+
"asserts": "https://deno.land/[email protected]/testing/asserts.ts"
4+
}
5+
}

test.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deno test --config deno.json

0 commit comments

Comments
 (0)