Working with Modules
Barrel API Shape
A barrel module gathers selected exports into a small public surface.
barrel module
A barrel file re-exports a curated set of names so callers do not depend on every internal file.
Barrel API Shape
barrel_api.ts
Replay: real traced execution (multi-file project)
function normalizeName(name: string): string {
return name.trim().toLowerCase();
}
function formatUser(name: string, admin: boolean): string {
const role: string = admin ? "admin" : "reader";
return `${normalizeName(name)}:${role}`;
}
export const publicApi = {
formatUser,
};
const admin: boolean = false;
const line: string = publicApi.formatUser(" ADA ", admin);
console.log(line);
function normalizeName(name: string): string {
return name.trim().toLowerCase();
}
function formatUser(name: string, admin: boolean): string {
const role: string = admin ? "admin" : "reader";
return `${normalizeName(name)}:${role}`;
}
export const publicApi = {
formatUser,
};
const admin: boolean = true;
const line: string = publicApi.formatUser(" ADA ", admin);
console.log(line);
publicApi ← [object Object], admin ← false
7 return `${normalizeName(name)}:${role}`;8}910export const publicApi→ [object Object] = {11 formatUser,12};1314const admin→ false: boolean = false; //@admin=true15const line: string = publicApi[object Object].formatUser(" ADA ", adminfalse);role ← reader
2 return name.trim().toLowerCase();3}45function formatUser(name ADA : string, adminfalse: boolean): string {6 const role→ reader: string = adminfalse ? "admin" : "reader";7 return `${normalizeName(name ADA )}:${rolereader}`;8}function normalizeName(name: string): string
1function normalizeName(name ADA : string): string {2 return name ADA .trim().toLowerCase();3}line ← ada:reader
14const admin: boolean = false; //@admin=true15const line→ ada:reader: string = publicApi[object Object].formatUser(" ADA ", adminfalse);1617console.log(lineada:reader);outputada:reader
publicApi ← [object Object], admin ← true
7 return `${normalizeName(name)}:${role}`;8}910export const publicApi→ [object Object] = {11 formatUser,12};1314const admin→ true: boolean = true;15const line: string = publicApi[object Object].formatUser(" ADA ", admintrue);role ← admin
2 return name.trim().toLowerCase();3}45function formatUser(name ADA : string, admintrue: boolean): string {6 const role→ admin: string = admintrue ? "admin" : "reader";7 return `${normalizeName(name ADA )}:${roleadmin}`;8}function normalizeName(name: string): string
1function normalizeName(name ADA : string): string {2 return name ADA .trim().toLowerCase();3}line ← ada:admin
14const admin: boolean = true;15const line→ ada:admin: string = publicApi[object Object].formatUser(" ADA ", admintrue);1617console.log(lineada:admin);outputada:admin