Working with Modules
Barrel API Shape
A barrel module gathers selected exports into a small public surface.
Barrel API Shape
barrel_api.ts
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 = ;
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 = ;
const line: string = publicApi.formatUser(" ADA ", admin);
console.log(line);
barrel module
A barrel file re-exports a curated set of names so callers do not depend on every internal file.