-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrscModule.ts
More file actions
37 lines (33 loc) · 917 Bytes
/
rscModule.ts
File metadata and controls
37 lines (33 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Default directory name for RSC payload files.
*/
export const defaultRscPayloadDir = "fun__rsc-payload";
/**
* Combines the RSC payload directory with a raw ID to form a
* namespaced payload ID (e.g. "fun__rsc-payload/abc123").
*/
export function getPayloadIDFor(
rawId: string,
rscPayloadDir: string = defaultRscPayloadDir,
): string {
return `${rscPayloadDir}/${rawId}`;
}
const rscModulePathPrefix = "/funstack__/";
const rscModulePathSuffix = ".txt";
export function getModulePathFor(id: string): string {
return `${rscModulePathPrefix}${id}${rscModulePathSuffix}`;
}
export function extractIDFromModulePath(
modulePath: string,
): string | undefined {
if (
!modulePath.startsWith(rscModulePathPrefix) ||
!modulePath.endsWith(rscModulePathSuffix)
) {
return undefined;
}
return modulePath.slice(
rscModulePathPrefix.length,
-rscModulePathSuffix.length,
);
}