ventojs 0.7.3 → 0.8.1

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.
Files changed (127) hide show
  1. package/README.md +6 -4
  2. package/esm/mod.d.ts +1 -0
  3. package/esm/mod.js +5 -0
  4. package/esm/plugins/echo.d.ts +2 -0
  5. package/esm/plugins/echo.js +13 -0
  6. package/esm/plugins/include.js +2 -2
  7. package/esm/plugins/layout.js +1 -1
  8. package/esm/plugins/unescape.d.ts +2 -0
  9. package/esm/plugins/unescape.js +16 -0
  10. package/esm/src/environment.d.ts +3 -2
  11. package/esm/src/environment.js +13 -5
  12. package/esm/src/tokenizer.d.ts +1 -1
  13. package/esm/src/tokenizer.js +13 -25
  14. package/package.json +4 -2
  15. package/script/_dnt.shims.d.ts +5 -0
  16. package/script/_dnt.shims.js +65 -0
  17. package/script/deps/deno.land/std@0.201.0/assert/assert.d.ts +2 -0
  18. package/script/deps/deno.land/std@0.201.0/assert/assert.js +12 -0
  19. package/script/deps/deno.land/std@0.201.0/assert/assertion_error.d.ts +4 -0
  20. package/script/deps/deno.land/std@0.201.0/assert/assertion_error.js +11 -0
  21. package/script/deps/deno.land/std@0.201.0/path/_basename.d.ts +16 -0
  22. package/script/deps/deno.land/std@0.201.0/path/_basename.js +83 -0
  23. package/script/deps/deno.land/std@0.201.0/path/_constants.d.ts +39 -0
  24. package/script/deps/deno.land/std@0.201.0/path/_constants.js +49 -0
  25. package/script/deps/deno.land/std@0.201.0/path/_dirname.d.ts +10 -0
  26. package/script/deps/deno.land/std@0.201.0/path/_dirname.js +137 -0
  27. package/script/deps/deno.land/std@0.201.0/path/_extname.d.ts +12 -0
  28. package/script/deps/deno.land/std@0.201.0/path/_extname.js +126 -0
  29. package/script/deps/deno.land/std@0.201.0/path/_format.d.ts +11 -0
  30. package/script/deps/deno.land/std@0.201.0/path/_format.js +40 -0
  31. package/script/deps/deno.land/std@0.201.0/path/_from_file_url.d.ts +25 -0
  32. package/script/deps/deno.land/std@0.201.0/path/_from_file_url.js +51 -0
  33. package/script/deps/deno.land/std@0.201.0/path/_interface.d.ts +26 -0
  34. package/script/deps/deno.land/std@0.201.0/path/_interface.js +4 -0
  35. package/script/deps/deno.land/std@0.201.0/path/_is_absolute.d.ts +10 -0
  36. package/script/deps/deno.land/std@0.201.0/path/_is_absolute.js +39 -0
  37. package/script/deps/deno.land/std@0.201.0/path/_join.d.ts +10 -0
  38. package/script/deps/deno.land/std@0.201.0/path/_join.js +98 -0
  39. package/script/deps/deno.land/std@0.201.0/path/_normalize.d.ts +14 -0
  40. package/script/deps/deno.land/std@0.201.0/path/_normalize.js +158 -0
  41. package/script/deps/deno.land/std@0.201.0/path/_os.d.ts +4 -0
  42. package/script/deps/deno.land/std@0.201.0/path/_os.js +44 -0
  43. package/script/deps/deno.land/std@0.201.0/path/_parse.d.ts +11 -0
  44. package/script/deps/deno.land/std@0.201.0/path/_parse.js +255 -0
  45. package/script/deps/deno.land/std@0.201.0/path/_relative.d.ts +19 -0
  46. package/script/deps/deno.land/std@0.201.0/path/_relative.js +221 -0
  47. package/script/deps/deno.land/std@0.201.0/path/_resolve.d.ts +10 -0
  48. package/script/deps/deno.land/std@0.201.0/path/_resolve.js +211 -0
  49. package/script/deps/deno.land/std@0.201.0/path/_to_file_url.d.ts +25 -0
  50. package/script/deps/deno.land/std@0.201.0/path/_to_file_url.js +66 -0
  51. package/script/deps/deno.land/std@0.201.0/path/_to_namespaced_path.d.ts +10 -0
  52. package/script/deps/deno.land/std@0.201.0/path/_to_namespaced_path.js +51 -0
  53. package/script/deps/deno.land/std@0.201.0/path/_util.d.ts +6 -0
  54. package/script/deps/deno.land/std@0.201.0/path/_util.js +116 -0
  55. package/script/deps/deno.land/std@0.201.0/path/basename.d.ts +8 -0
  56. package/script/deps/deno.land/std@0.201.0/path/basename.js +20 -0
  57. package/script/deps/deno.land/std@0.201.0/path/common.d.ts +13 -0
  58. package/script/deps/deno.land/std@0.201.0/path/common.js +40 -0
  59. package/script/deps/deno.land/std@0.201.0/path/dirname.d.ts +5 -0
  60. package/script/deps/deno.land/std@0.201.0/path/dirname.js +15 -0
  61. package/script/deps/deno.land/std@0.201.0/path/extname.d.ts +6 -0
  62. package/script/deps/deno.land/std@0.201.0/path/extname.js +16 -0
  63. package/script/deps/deno.land/std@0.201.0/path/format.d.ts +6 -0
  64. package/script/deps/deno.land/std@0.201.0/path/format.js +15 -0
  65. package/script/deps/deno.land/std@0.201.0/path/from_file_url.d.ts +18 -0
  66. package/script/deps/deno.land/std@0.201.0/path/from_file_url.js +27 -0
  67. package/script/deps/deno.land/std@0.201.0/path/glob.d.ts +83 -0
  68. package/script/deps/deno.land/std@0.201.0/path/glob.js +391 -0
  69. package/script/deps/deno.land/std@0.201.0/path/is_absolute.d.ts +5 -0
  70. package/script/deps/deno.land/std@0.201.0/path/is_absolute.js +15 -0
  71. package/script/deps/deno.land/std@0.201.0/path/join.d.ts +5 -0
  72. package/script/deps/deno.land/std@0.201.0/path/join.js +15 -0
  73. package/script/deps/deno.land/std@0.201.0/path/mod.d.ts +22 -0
  74. package/script/deps/deno.land/std@0.201.0/path/mod.js +74 -0
  75. package/script/deps/deno.land/std@0.201.0/path/normalize.d.ts +7 -0
  76. package/script/deps/deno.land/std@0.201.0/path/normalize.js +17 -0
  77. package/script/deps/deno.land/std@0.201.0/path/parse.d.ts +6 -0
  78. package/script/deps/deno.land/std@0.201.0/path/parse.js +15 -0
  79. package/script/deps/deno.land/std@0.201.0/path/posix.d.ts +15 -0
  80. package/script/deps/deno.land/std@0.201.0/path/posix.js +35 -0
  81. package/script/deps/deno.land/std@0.201.0/path/relative.d.ts +12 -0
  82. package/script/deps/deno.land/std@0.201.0/path/relative.js +22 -0
  83. package/script/deps/deno.land/std@0.201.0/path/resolve.d.ts +5 -0
  84. package/script/deps/deno.land/std@0.201.0/path/resolve.js +17 -0
  85. package/script/deps/deno.land/std@0.201.0/path/separator.d.ts +2 -0
  86. package/script/deps/deno.land/std@0.201.0/path/separator.js +8 -0
  87. package/script/deps/deno.land/std@0.201.0/path/to_file_url.d.ts +18 -0
  88. package/script/deps/deno.land/std@0.201.0/path/to_file_url.js +27 -0
  89. package/script/deps/deno.land/std@0.201.0/path/to_namespaced_path.d.ts +5 -0
  90. package/script/deps/deno.land/std@0.201.0/path/to_namespaced_path.js +17 -0
  91. package/script/deps/deno.land/std@0.201.0/path/win32.d.ts +15 -0
  92. package/script/deps/deno.land/std@0.201.0/path/win32.js +35 -0
  93. package/script/deps.d.ts +1 -0
  94. package/script/deps.js +27 -0
  95. package/script/mod.d.ts +8 -0
  96. package/script/mod.js +68 -0
  97. package/script/package.json +3 -0
  98. package/script/plugins/echo.d.ts +2 -0
  99. package/script/plugins/echo.js +16 -0
  100. package/script/plugins/escape.d.ts +2 -0
  101. package/script/plugins/escape.js +19 -0
  102. package/script/plugins/export.d.ts +2 -0
  103. package/script/plugins/export.js +49 -0
  104. package/script/plugins/for.d.ts +2 -0
  105. package/script/plugins/for.js +51 -0
  106. package/script/plugins/function.d.ts +2 -0
  107. package/script/plugins/function.js +40 -0
  108. package/script/plugins/if.d.ts +2 -0
  109. package/script/plugins/if.js +35 -0
  110. package/script/plugins/import.d.ts +2 -0
  111. package/script/plugins/import.js +27 -0
  112. package/script/plugins/include.d.ts +2 -0
  113. package/script/plugins/include.js +25 -0
  114. package/script/plugins/js.d.ts +2 -0
  115. package/script/plugins/js.js +14 -0
  116. package/script/plugins/layout.d.ts +2 -0
  117. package/script/plugins/layout.js +36 -0
  118. package/script/plugins/set.d.ts +2 -0
  119. package/script/plugins/set.js +47 -0
  120. package/script/plugins/unescape.d.ts +2 -0
  121. package/script/plugins/unescape.js +19 -0
  122. package/script/src/environment.d.ts +41 -0
  123. package/script/src/environment.js +179 -0
  124. package/script/src/loader.d.ts +14 -0
  125. package/script/src/loader.js +46 -0
  126. package/script/src/tokenizer.d.ts +8 -0
  127. package/script/src/tokenizer.js +190 -0
package/README.md CHANGED
@@ -123,24 +123,26 @@ can use `load` to load and compile a template file and return it.
123
123
 
124
124
  ```ts
125
125
  // Load and return a template
126
- const template = vto.load("my-template.vto");
126
+ const template = await vto.load("my-template.vto");
127
127
 
128
128
  // Now you can use it passing the data
129
- const result = template({ title: "Hello world" });
129
+ const result = await template({ title: "Hello world" });
130
130
  console.log(result.content);
131
131
  ```
132
132
 
133
133
  Alternatively, you can load and run the template file in a single call:
134
134
 
135
135
  ```ts
136
- const result = vto.run("my-template.vto", { title: "Hello world" });
136
+ const result = await vto.run("my-template.vto", { title: "Hello world" });
137
137
  console.log(result.content);
138
138
  ```
139
139
 
140
140
  If the template code is not a file, you can run it directly:
141
141
 
142
142
  ```ts
143
- const result = vto.runString("<h1>{{ title }}</h1>", { title: "Hello world" });
143
+ const result = await vto.runString("<h1>{{ title }}</h1>", {
144
+ title: "Hello world",
145
+ });
144
146
  console.log(result.content);
145
147
  ```
146
148
 
package/esm/mod.d.ts CHANGED
@@ -3,5 +3,6 @@ import { Loader } from "./src/loader.js";
3
3
  export interface Options {
4
4
  includes?: string | Loader;
5
5
  dataVarname?: string;
6
+ autoescape?: boolean;
6
7
  }
7
8
  export default function (options?: Options): Environment;
package/esm/mod.js CHANGED
@@ -10,7 +10,9 @@ import layoutTag from "./plugins/layout.js";
10
10
  import functionTag from "./plugins/function.js";
11
11
  import importTag from "./plugins/import.js";
12
12
  import exportTag from "./plugins/export.js";
13
+ import echoTag from "./plugins/echo.js";
13
14
  import escape from "./plugins/escape.js";
15
+ import unescape from "./plugins/unescape.js";
14
16
  export default function (options = {}) {
15
17
  const loader = typeof options.includes === "object"
16
18
  ? options.includes
@@ -18,6 +20,7 @@ export default function (options = {}) {
18
20
  const env = new Environment({
19
21
  loader,
20
22
  dataVarname: options.dataVarname || "it",
23
+ autoescape: options.autoescape || false,
21
24
  });
22
25
  // Register basic plugins
23
26
  env.use(ifTag());
@@ -29,6 +32,8 @@ export default function (options = {}) {
29
32
  env.use(functionTag());
30
33
  env.use(importTag());
31
34
  env.use(exportTag());
35
+ env.use(echoTag());
32
36
  env.use(escape());
37
+ env.use(unescape());
33
38
  return env;
34
39
  }
@@ -0,0 +1,2 @@
1
+ import type { Environment } from "../src/environment.js";
2
+ export default function (): (env: Environment) => void;
@@ -0,0 +1,13 @@
1
+ export default function () {
2
+ return (env) => {
3
+ env.tags.push(setTag);
4
+ };
5
+ }
6
+ function setTag(env, code, output, tokens) {
7
+ if (!code.startsWith("echo ")) {
8
+ return;
9
+ }
10
+ const value = code.replace(/^echo\s+/, "");
11
+ const val = env.compileFilters(tokens, value, env.options.autoescape);
12
+ return `${output} += ${val};`;
13
+ }
@@ -3,7 +3,7 @@ export default function () {
3
3
  env.tags.push(includeTag);
4
4
  };
5
5
  }
6
- function includeTag(_env, code, output) {
6
+ function includeTag(env, code, output, tokens) {
7
7
  if (!code.startsWith("include ")) {
8
8
  return;
9
9
  }
@@ -17,6 +17,6 @@ function includeTag(_env, code, output) {
17
17
  {...__data${data ? `, ${data}` : ""}},
18
18
  __file
19
19
  );
20
- ${output} += __tmp.content;
20
+ ${output} += ${env.compileFilters(tokens, "__tmp.content")};
21
21
  }`;
22
22
  }
@@ -24,7 +24,7 @@ function layoutTag(env, code, output, tokens) {
24
24
  tokens.shift();
25
25
  compiled.push(`${varname} = ${compiledFilters};`);
26
26
  compiled.push(`__tmp = await __env.run(${file},
27
- {...__data${data ? `, ${data}` : ""}, content: ${varname}},
27
+ {...__data${data ? `, ${data}` : ""}, content: ${env.compileFilters(tokens, varname)}},
28
28
  __file
29
29
  );
30
30
  ${output} += __tmp.content;`);
@@ -0,0 +1,2 @@
1
+ import type { Environment } from "../src/environment.js";
2
+ export default function (): (env: Environment) => void;
@@ -0,0 +1,16 @@
1
+ export default function () {
2
+ return (env) => {
3
+ env.filters.unescape = unescape;
4
+ };
5
+ }
6
+ const unescapeMap = {
7
+ "&amp;": "&",
8
+ "&lt;": "<",
9
+ "&gt;": ">",
10
+ "&quot;": '"',
11
+ "&#39;": "'",
12
+ "&#x60;": "`",
13
+ };
14
+ function unescape(str) {
15
+ return str.replace(/(&amp;|&lt;|&gt;|&quot;|&#39;|&#x60;)/g, (match) => unescapeMap[match]);
16
+ }
@@ -19,7 +19,8 @@ export type Filter = (...args: any[]) => any;
19
19
  export type Plugin = (env: Environment) => void;
20
20
  export interface Options {
21
21
  loader: Loader;
22
- dataVarname?: string;
22
+ dataVarname: string;
23
+ autoescape: boolean;
23
24
  }
24
25
  export declare class Environment {
25
26
  cache: Map<string, Template>;
@@ -36,5 +37,5 @@ export declare class Environment {
36
37
  compile(source: string, path?: string, defaults?: Record<string, unknown>, sync?: true): TemplateSync;
37
38
  load(file: string, from?: string): Promise<Template>;
38
39
  compileTokens(tokens: Token[], outputVar?: string, stopAt?: string[]): string[];
39
- compileFilters(tokens: Token[], output: string): string;
40
+ compileFilters(tokens: Token[], output: string, autoescape?: boolean): string;
40
41
  }
@@ -67,9 +67,9 @@ export class Environment {
67
67
  if (!this.cache.has(path)) {
68
68
  const { source, data } = await this.options.loader.load(path);
69
69
  const template = this.compile(source, path, data);
70
- this.cache.set(file, template);
70
+ this.cache.set(path, template);
71
71
  }
72
- return this.cache.get(file);
72
+ return this.cache.get(path);
73
73
  }
74
74
  compileTokens(tokens, outputVar = "__exports.content", stopAt) {
75
75
  const compiled = [];
@@ -81,7 +81,7 @@ export class Environment {
81
81
  if (type === "comment") {
82
82
  continue;
83
83
  }
84
- if (type === "string" || type === "raw") {
84
+ if (type === "string") {
85
85
  compiled.push(`${outputVar} += ${JSON.stringify(code)};`);
86
86
  continue;
87
87
  }
@@ -94,7 +94,7 @@ export class Environment {
94
94
  }
95
95
  }
96
96
  // Unknown tag, just print it
97
- const expression = this.compileFilters(tokens, code);
97
+ const expression = this.compileFilters(tokens, code, this.options.autoescape);
98
98
  compiled.push(`${outputVar} += (${expression}) ?? "";`);
99
99
  continue;
100
100
  }
@@ -102,7 +102,8 @@ export class Environment {
102
102
  }
103
103
  return compiled;
104
104
  }
105
- compileFilters(tokens, output) {
105
+ compileFilters(tokens, output, autoescape = false) {
106
+ let unescaped = false;
106
107
  while (tokens.length > 0 && tokens[0][0] === "filter") {
107
108
  const [, code] = tokens.shift();
108
109
  const match = code.match(/^(await\s+)?([\w.]+)(?:\((.*)\))?$/);
@@ -121,10 +122,17 @@ export class Environment {
121
122
  }
122
123
  }
123
124
  else {
125
+ if (name === "unescape") {
126
+ unescaped = true;
127
+ }
124
128
  // It's a filter (e.g. filters.upper())
125
129
  output = `${isAsync ? "await " : ""}__env.filters.${name}(${output}${args ? `, ${args}` : ""})`;
126
130
  }
127
131
  }
132
+ // Escape by default
133
+ if (autoescape && !unescaped) {
134
+ output = `__env.filters.escape(${output})`;
135
+ }
128
136
  return output;
129
137
  }
130
138
  }
@@ -1,4 +1,4 @@
1
- export type TokenType = "string" | "tag" | "filter" | "comment" | "raw";
1
+ export type TokenType = "string" | "tag" | "filter" | "comment";
2
2
  export type Token = [TokenType, string];
3
3
  export default function tokenize(source: string): Token[];
4
4
  /**
@@ -17,15 +17,6 @@ export default function tokenize(source) {
17
17
  break;
18
18
  }
19
19
  source = source.slice(index);
20
- // Check if it's a {{raw}} tag
21
- const raw = parseRawTag(source);
22
- if (raw) {
23
- const rawCode = source.slice(raw[0], raw[1]);
24
- tokens.push(["raw", rawCode]);
25
- source = source.slice(raw[2]);
26
- type = "string";
27
- continue;
28
- }
29
20
  type = source.startsWith("{{#") ? "comment" : "tag";
30
21
  continue;
31
22
  }
@@ -44,6 +35,7 @@ export default function tokenize(source) {
44
35
  if (type === "tag") {
45
36
  const indexes = parseTag(source);
46
37
  const lastIndex = indexes.length - 1;
38
+ let tag;
47
39
  indexes.reduce((prev, curr, index) => {
48
40
  let code = source.slice(prev, curr - 2);
49
41
  // Tag
@@ -59,7 +51,8 @@ export default function tokenize(source) {
59
51
  code = code.slice(0, -1);
60
52
  trimNext = true;
61
53
  }
62
- tokens.push([type, code.trim()]);
54
+ tag = [type, code.trim()];
55
+ tokens.push(tag);
63
56
  return curr;
64
57
  }
65
58
  // Right trim
@@ -73,6 +66,16 @@ export default function tokenize(source) {
73
66
  });
74
67
  source = source.slice(indexes[indexes.length - 1]);
75
68
  type = "string";
69
+ // Search the closing echo tag {{ /echo }}
70
+ if (tag?.[1] === "echo") {
71
+ const end = source.match(/{{\s*\/echo\s*}}/);
72
+ if (!end) {
73
+ throw new Error("Unclosed echo tag");
74
+ }
75
+ const rawCode = source.slice(0, end.index);
76
+ tag[1] = `echo ${JSON.stringify(rawCode)}`;
77
+ source = source.slice(Number(end.index) + end[0].length);
78
+ }
76
79
  continue;
77
80
  }
78
81
  }
@@ -180,18 +183,3 @@ export function parseTag(source) {
180
183
  }
181
184
  throw new Error("Unclosed tag");
182
185
  }
183
- function parseRawTag(source) {
184
- const startResult = source.match(/^{{\s*raw\s*}}/);
185
- if (!startResult) {
186
- return;
187
- }
188
- const endResult = source.match(/{{\s*\/raw\s*}}/);
189
- if (!endResult) {
190
- throw new Error("Unclosed raw tag");
191
- }
192
- return [
193
- startResult[0].length,
194
- endResult.index,
195
- endResult.index + endResult[0].length,
196
- ];
197
- }
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "module": "./esm/mod.js",
3
+ "main": "./script/mod.js",
3
4
  "name": "ventojs",
4
- "version": "0.7.3",
5
+ "version": "0.8.1",
5
6
  "description": "🌬 A minimal but powerful template engine",
6
7
  "license": "MIT",
7
8
  "repository": "github:oscarotero/vento",
@@ -9,7 +10,8 @@
9
10
  "bugs": "https://github.com/oscarotero/vento/issues",
10
11
  "exports": {
11
12
  ".": {
12
- "import": "./esm/mod.js"
13
+ "import": "./esm/mod.js",
14
+ "require": "./script/mod.js"
13
15
  }
14
16
  },
15
17
  "scripts": {
@@ -0,0 +1,5 @@
1
+ import { Deno } from "@deno/shim-deno";
2
+ export { Deno } from "@deno/shim-deno";
3
+ export declare const dntGlobalThis: Omit<typeof globalThis, "Deno"> & {
4
+ Deno: typeof Deno;
5
+ };
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dntGlobalThis = exports.Deno = void 0;
4
+ const shim_deno_1 = require("@deno/shim-deno");
5
+ var shim_deno_2 = require("@deno/shim-deno");
6
+ Object.defineProperty(exports, "Deno", { enumerable: true, get: function () { return shim_deno_2.Deno; } });
7
+ const dntGlobals = {
8
+ Deno: shim_deno_1.Deno,
9
+ };
10
+ exports.dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
11
+ function createMergeProxy(baseObj, extObj) {
12
+ return new Proxy(baseObj, {
13
+ get(_target, prop, _receiver) {
14
+ if (prop in extObj) {
15
+ return extObj[prop];
16
+ }
17
+ else {
18
+ return baseObj[prop];
19
+ }
20
+ },
21
+ set(_target, prop, value) {
22
+ if (prop in extObj) {
23
+ delete extObj[prop];
24
+ }
25
+ baseObj[prop] = value;
26
+ return true;
27
+ },
28
+ deleteProperty(_target, prop) {
29
+ let success = false;
30
+ if (prop in extObj) {
31
+ delete extObj[prop];
32
+ success = true;
33
+ }
34
+ if (prop in baseObj) {
35
+ delete baseObj[prop];
36
+ success = true;
37
+ }
38
+ return success;
39
+ },
40
+ ownKeys(_target) {
41
+ const baseKeys = Reflect.ownKeys(baseObj);
42
+ const extKeys = Reflect.ownKeys(extObj);
43
+ const extKeysSet = new Set(extKeys);
44
+ return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
45
+ },
46
+ defineProperty(_target, prop, desc) {
47
+ if (prop in extObj) {
48
+ delete extObj[prop];
49
+ }
50
+ Reflect.defineProperty(baseObj, prop, desc);
51
+ return true;
52
+ },
53
+ getOwnPropertyDescriptor(_target, prop) {
54
+ if (prop in extObj) {
55
+ return Reflect.getOwnPropertyDescriptor(extObj, prop);
56
+ }
57
+ else {
58
+ return Reflect.getOwnPropertyDescriptor(baseObj, prop);
59
+ }
60
+ },
61
+ has(_target, prop) {
62
+ return prop in extObj || prop in baseObj;
63
+ },
64
+ });
65
+ }
@@ -0,0 +1,2 @@
1
+ /** Make an assertion, error will be thrown if `expr` does not have truthy value. */
2
+ export declare function assert(expr: unknown, msg?: string): asserts expr;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assert = void 0;
4
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
5
+ const assertion_error_js_1 = require("./assertion_error.js");
6
+ /** Make an assertion, error will be thrown if `expr` does not have truthy value. */
7
+ function assert(expr, msg = "") {
8
+ if (!expr) {
9
+ throw new assertion_error_js_1.AssertionError(msg);
10
+ }
11
+ }
12
+ exports.assert = assert;
@@ -0,0 +1,4 @@
1
+ export declare class AssertionError extends Error {
2
+ name: string;
3
+ constructor(message: string);
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AssertionError = void 0;
4
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
5
+ class AssertionError extends Error {
6
+ name = "AssertionError";
7
+ constructor(message) {
8
+ super(message);
9
+ }
10
+ }
11
+ exports.AssertionError = AssertionError;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Return the last portion of a `path`.
3
+ * Trailing directory separators are ignored, and optional suffix is removed.
4
+ *
5
+ * @param path - path to extract the name from.
6
+ * @param [suffix] - suffix to remove from extracted name.
7
+ */
8
+ export declare function posixBasename(path: string, suffix?: string): string;
9
+ /**
10
+ * Return the last portion of a `path`.
11
+ * Trailing directory separators are ignored, and optional suffix is removed.
12
+ *
13
+ * @param path - path to extract the name from.
14
+ * @param [suffix] - suffix to remove from extracted name.
15
+ */
16
+ export declare function windowsBasename(path: string, suffix?: string): string;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
3
+ // This module is browser compatible.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.windowsBasename = exports.posixBasename = void 0;
6
+ const _constants_js_1 = require("./_constants.js");
7
+ const _util_js_1 = require("./_util.js");
8
+ function stripSuffix(name, suffix) {
9
+ if (suffix.length >= name.length) {
10
+ return name;
11
+ }
12
+ const lenDiff = name.length - suffix.length;
13
+ for (let i = suffix.length - 1; i >= 0; --i) {
14
+ if (name.charCodeAt(lenDiff + i) !== suffix.charCodeAt(i)) {
15
+ return name;
16
+ }
17
+ }
18
+ return name.slice(0, -suffix.length);
19
+ }
20
+ function lastPathSegment(path, isSep, start = 0) {
21
+ let matchedNonSeparator = false;
22
+ let end = path.length;
23
+ for (let i = path.length - 1; i >= start; --i) {
24
+ if (isSep(path.charCodeAt(i))) {
25
+ if (matchedNonSeparator) {
26
+ start = i + 1;
27
+ break;
28
+ }
29
+ }
30
+ else if (!matchedNonSeparator) {
31
+ matchedNonSeparator = true;
32
+ end = i + 1;
33
+ }
34
+ }
35
+ return path.slice(start, end);
36
+ }
37
+ function assertArgs(path, suffix) {
38
+ (0, _util_js_1.assertPath)(path);
39
+ if (path.length === 0)
40
+ return path;
41
+ if (typeof suffix !== "string") {
42
+ throw new TypeError(`Suffix must be a string. Received ${JSON.stringify(suffix)}`);
43
+ }
44
+ }
45
+ /**
46
+ * Return the last portion of a `path`.
47
+ * Trailing directory separators are ignored, and optional suffix is removed.
48
+ *
49
+ * @param path - path to extract the name from.
50
+ * @param [suffix] - suffix to remove from extracted name.
51
+ */
52
+ function posixBasename(path, suffix = "") {
53
+ assertArgs(path, suffix);
54
+ const lastSegment = lastPathSegment(path, _util_js_1.isPosixPathSeparator);
55
+ const strippedSegment = (0, _util_js_1.stripTrailingSeparators)(lastSegment, _util_js_1.isPosixPathSeparator);
56
+ return suffix ? stripSuffix(strippedSegment, suffix) : strippedSegment;
57
+ }
58
+ exports.posixBasename = posixBasename;
59
+ /**
60
+ * Return the last portion of a `path`.
61
+ * Trailing directory separators are ignored, and optional suffix is removed.
62
+ *
63
+ * @param path - path to extract the name from.
64
+ * @param [suffix] - suffix to remove from extracted name.
65
+ */
66
+ function windowsBasename(path, suffix = "") {
67
+ assertArgs(path, suffix);
68
+ // Check for a drive letter prefix so as not to mistake the following
69
+ // path separator as an extra separator at the end of the path that can be
70
+ // disregarded
71
+ let start = 0;
72
+ if (path.length >= 2) {
73
+ const drive = path.charCodeAt(0);
74
+ if ((0, _util_js_1.isWindowsDeviceRoot)(drive)) {
75
+ if (path.charCodeAt(1) === _constants_js_1.CHAR_COLON)
76
+ start = 2;
77
+ }
78
+ }
79
+ const lastSegment = lastPathSegment(path, _util_js_1.isPathSeparator, start);
80
+ const strippedSegment = (0, _util_js_1.stripTrailingSeparators)(lastSegment, _util_js_1.isPathSeparator);
81
+ return suffix ? stripSuffix(strippedSegment, suffix) : strippedSegment;
82
+ }
83
+ exports.windowsBasename = windowsBasename;
@@ -0,0 +1,39 @@
1
+ export declare const CHAR_UPPERCASE_A = 65;
2
+ export declare const CHAR_LOWERCASE_A = 97;
3
+ export declare const CHAR_UPPERCASE_Z = 90;
4
+ export declare const CHAR_LOWERCASE_Z = 122;
5
+ export declare const CHAR_DOT = 46;
6
+ export declare const CHAR_FORWARD_SLASH = 47;
7
+ export declare const CHAR_BACKWARD_SLASH = 92;
8
+ export declare const CHAR_VERTICAL_LINE = 124;
9
+ export declare const CHAR_COLON = 58;
10
+ export declare const CHAR_QUESTION_MARK = 63;
11
+ export declare const CHAR_UNDERSCORE = 95;
12
+ export declare const CHAR_LINE_FEED = 10;
13
+ export declare const CHAR_CARRIAGE_RETURN = 13;
14
+ export declare const CHAR_TAB = 9;
15
+ export declare const CHAR_FORM_FEED = 12;
16
+ export declare const CHAR_EXCLAMATION_MARK = 33;
17
+ export declare const CHAR_HASH = 35;
18
+ export declare const CHAR_SPACE = 32;
19
+ export declare const CHAR_NO_BREAK_SPACE = 160;
20
+ export declare const CHAR_ZERO_WIDTH_NOBREAK_SPACE = 65279;
21
+ export declare const CHAR_LEFT_SQUARE_BRACKET = 91;
22
+ export declare const CHAR_RIGHT_SQUARE_BRACKET = 93;
23
+ export declare const CHAR_LEFT_ANGLE_BRACKET = 60;
24
+ export declare const CHAR_RIGHT_ANGLE_BRACKET = 62;
25
+ export declare const CHAR_LEFT_CURLY_BRACKET = 123;
26
+ export declare const CHAR_RIGHT_CURLY_BRACKET = 125;
27
+ export declare const CHAR_HYPHEN_MINUS = 45;
28
+ export declare const CHAR_PLUS = 43;
29
+ export declare const CHAR_DOUBLE_QUOTE = 34;
30
+ export declare const CHAR_SINGLE_QUOTE = 39;
31
+ export declare const CHAR_PERCENT = 37;
32
+ export declare const CHAR_SEMICOLON = 59;
33
+ export declare const CHAR_CIRCUMFLEX_ACCENT = 94;
34
+ export declare const CHAR_GRAVE_ACCENT = 96;
35
+ export declare const CHAR_AT = 64;
36
+ export declare const CHAR_AMPERSAND = 38;
37
+ export declare const CHAR_EQUAL = 61;
38
+ export declare const CHAR_0 = 48;
39
+ export declare const CHAR_9 = 57;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
3
+ // Copyright the Browserify authors. MIT License.
4
+ // Ported from https://github.com/browserify/path-browserify/
5
+ // This module is browser compatible.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.CHAR_9 = exports.CHAR_0 = exports.CHAR_EQUAL = exports.CHAR_AMPERSAND = exports.CHAR_AT = exports.CHAR_GRAVE_ACCENT = exports.CHAR_CIRCUMFLEX_ACCENT = exports.CHAR_SEMICOLON = exports.CHAR_PERCENT = exports.CHAR_SINGLE_QUOTE = exports.CHAR_DOUBLE_QUOTE = exports.CHAR_PLUS = exports.CHAR_HYPHEN_MINUS = exports.CHAR_RIGHT_CURLY_BRACKET = exports.CHAR_LEFT_CURLY_BRACKET = exports.CHAR_RIGHT_ANGLE_BRACKET = exports.CHAR_LEFT_ANGLE_BRACKET = exports.CHAR_RIGHT_SQUARE_BRACKET = exports.CHAR_LEFT_SQUARE_BRACKET = exports.CHAR_ZERO_WIDTH_NOBREAK_SPACE = exports.CHAR_NO_BREAK_SPACE = exports.CHAR_SPACE = exports.CHAR_HASH = exports.CHAR_EXCLAMATION_MARK = exports.CHAR_FORM_FEED = exports.CHAR_TAB = exports.CHAR_CARRIAGE_RETURN = exports.CHAR_LINE_FEED = exports.CHAR_UNDERSCORE = exports.CHAR_QUESTION_MARK = exports.CHAR_COLON = exports.CHAR_VERTICAL_LINE = exports.CHAR_BACKWARD_SLASH = exports.CHAR_FORWARD_SLASH = exports.CHAR_DOT = exports.CHAR_LOWERCASE_Z = exports.CHAR_UPPERCASE_Z = exports.CHAR_LOWERCASE_A = exports.CHAR_UPPERCASE_A = void 0;
8
+ // Alphabet chars.
9
+ exports.CHAR_UPPERCASE_A = 65; /* A */
10
+ exports.CHAR_LOWERCASE_A = 97; /* a */
11
+ exports.CHAR_UPPERCASE_Z = 90; /* Z */
12
+ exports.CHAR_LOWERCASE_Z = 122; /* z */
13
+ // Non-alphabetic chars.
14
+ exports.CHAR_DOT = 46; /* . */
15
+ exports.CHAR_FORWARD_SLASH = 47; /* / */
16
+ exports.CHAR_BACKWARD_SLASH = 92; /* \ */
17
+ exports.CHAR_VERTICAL_LINE = 124; /* | */
18
+ exports.CHAR_COLON = 58; /* : */
19
+ exports.CHAR_QUESTION_MARK = 63; /* ? */
20
+ exports.CHAR_UNDERSCORE = 95; /* _ */
21
+ exports.CHAR_LINE_FEED = 10; /* \n */
22
+ exports.CHAR_CARRIAGE_RETURN = 13; /* \r */
23
+ exports.CHAR_TAB = 9; /* \t */
24
+ exports.CHAR_FORM_FEED = 12; /* \f */
25
+ exports.CHAR_EXCLAMATION_MARK = 33; /* ! */
26
+ exports.CHAR_HASH = 35; /* # */
27
+ exports.CHAR_SPACE = 32; /* */
28
+ exports.CHAR_NO_BREAK_SPACE = 160; /* \u00A0 */
29
+ exports.CHAR_ZERO_WIDTH_NOBREAK_SPACE = 65279; /* \uFEFF */
30
+ exports.CHAR_LEFT_SQUARE_BRACKET = 91; /* [ */
31
+ exports.CHAR_RIGHT_SQUARE_BRACKET = 93; /* ] */
32
+ exports.CHAR_LEFT_ANGLE_BRACKET = 60; /* < */
33
+ exports.CHAR_RIGHT_ANGLE_BRACKET = 62; /* > */
34
+ exports.CHAR_LEFT_CURLY_BRACKET = 123; /* { */
35
+ exports.CHAR_RIGHT_CURLY_BRACKET = 125; /* } */
36
+ exports.CHAR_HYPHEN_MINUS = 45; /* - */
37
+ exports.CHAR_PLUS = 43; /* + */
38
+ exports.CHAR_DOUBLE_QUOTE = 34; /* " */
39
+ exports.CHAR_SINGLE_QUOTE = 39; /* ' */
40
+ exports.CHAR_PERCENT = 37; /* % */
41
+ exports.CHAR_SEMICOLON = 59; /* ; */
42
+ exports.CHAR_CIRCUMFLEX_ACCENT = 94; /* ^ */
43
+ exports.CHAR_GRAVE_ACCENT = 96; /* ` */
44
+ exports.CHAR_AT = 64; /* @ */
45
+ exports.CHAR_AMPERSAND = 38; /* & */
46
+ exports.CHAR_EQUAL = 61; /* = */
47
+ // Digits
48
+ exports.CHAR_0 = 48; /* 0 */
49
+ exports.CHAR_9 = 57; /* 9 */
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Return the directory path of a `path`.
3
+ * @param path - path to extract the directory from.
4
+ */
5
+ export declare function posixDirname(path: string): string;
6
+ /**
7
+ * Return the directory path of a `path`.
8
+ * @param path - path to extract the directory from.
9
+ */
10
+ export declare function windowsDirname(path: string): string;