spooder 4.0.0 → 4.0.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.
- package/README.md +19 -0
- package/package.json +1 -1
- package/src/api.d.ts +1 -0
- package/src/api.ts +7 -0
package/README.md
CHANGED
|
@@ -404,6 +404,7 @@ In addition to the information provided by the developer, `spooder` also include
|
|
|
404
404
|
- [`panic(err_message_or_obj: string | object, ...err: object[]): Promise<void>`](#api-error-handling-panic)
|
|
405
405
|
- [API > Content](#api-content)
|
|
406
406
|
- [`template_sub(template: string, replacements: Record<string, string>): string`](#api-content-template-sub)
|
|
407
|
+
- [`template_sub_file(template_file: string, replacements: Record<string, string>): Promise<string>`](#api-content-template-sub-file)
|
|
407
408
|
- [`generate_hash_subs(length: number, prefix: string): Promise<Record<string, string>>`](#api-content-generate-hash-subs)
|
|
408
409
|
- [`apply_range(file: BunFile, request: Request): HandlerReturnType`](#api-content-apply-range)
|
|
409
410
|
- [API > State Management](#api-state-management)
|
|
@@ -876,6 +877,24 @@ const html = template_sub(template, replacements);
|
|
|
876
877
|
</html>
|
|
877
878
|
```
|
|
878
879
|
|
|
880
|
+
<a id="api-content-template-sub-file"></a>
|
|
881
|
+
### 🔧 `template_sub_file(template_file: string, replacements: Record<string, string>): Promise<string>`
|
|
882
|
+
|
|
883
|
+
Replace placeholders in a template file with values from a replacement object.
|
|
884
|
+
|
|
885
|
+
> [!NOTE]
|
|
886
|
+
> This function is a convenience wrapper around `template_sub` and `Bun.file().text()` to reduce boilerplate. See `template_sub` for more information.
|
|
887
|
+
|
|
888
|
+
```ts
|
|
889
|
+
const html = await template_sub_file('./template.html', replacements);
|
|
890
|
+
|
|
891
|
+
// Is equivalent to:
|
|
892
|
+
const file = Bun.file('./template.html');
|
|
893
|
+
const file_contents = await file.text();
|
|
894
|
+
const html = await template_sub(file_contents, replacements);
|
|
895
|
+
```
|
|
896
|
+
|
|
897
|
+
|
|
879
898
|
<a id="api-content-generate-hash-subs"></a>
|
|
880
899
|
### 🔧 `generate_hash_subs(prefix: string): Promise<Record<string, string>>`
|
|
881
900
|
|
package/package.json
CHANGED
package/src/api.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare class ErrorWithMetadata extends Error {
|
|
|
11
11
|
}
|
|
12
12
|
export declare function panic(err_message_or_obj: string | object, ...err: object[]): Promise<void>;
|
|
13
13
|
export declare function caution(err_message_or_obj: string | object, ...err: object[]): Promise<void>;
|
|
14
|
+
export declare function template_sub_file(template_file: string, replacements: Record<string, string>): Promise<string>;
|
|
14
15
|
export declare function template_sub(template: string, replacements: Record<string, string>): string;
|
|
15
16
|
export declare function generate_hash_subs(length?: number, prefix?: string): Promise<Record<string, string>>;
|
|
16
17
|
type CookieOptions = {
|
package/src/api.ts
CHANGED
|
@@ -82,6 +82,13 @@ export async function caution(err_message_or_obj: string | object, ...err: objec
|
|
|
82
82
|
await handle_error('caution: ', err_message_or_obj, ...err);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
export async function template_sub_file(template_file: string, replacements: Record<string, string>): Promise<string> {
|
|
86
|
+
const file = Bun.file(template_file);
|
|
87
|
+
const file_contents = await file.text();
|
|
88
|
+
|
|
89
|
+
return template_sub(file_contents, replacements);
|
|
90
|
+
}
|
|
91
|
+
|
|
85
92
|
export function template_sub(template: string, replacements: Record<string, string>): string {
|
|
86
93
|
let result = '';
|
|
87
94
|
let buffer = '';
|