UNPKG

@rbac/rbac

Version:

Blazing Fast, Zero dependency, Hierarchical Role-Based Access Control for Node.js

39 lines (38 loc) 1.96 kB
import type { When, PatternPermission, NormalizedWhenFn, Role } from './types'; export declare const isGlob: (value: unknown) => value is string; /** * Determines if the current environment supports ANSI color codes. * * Detection logic (in priority order): * 1. If FORCE_COLOR is set to truthy value → return true * 2. If NO_COLOR is set to any value → return false * 3. If process.stdout.isTTY is false or undefined → return false * 4. If in known CI environment with color support → return true * 5. If process.stdout.isTTY is true → return true * 6. Default → return false * * The result is cached to avoid repeated environment checks. */ export declare const supportsColor: () => boolean; /** * Conditionally applies ANSI color codes to text based on color support. * * @param text - The text to potentially colorize * @param colorCode - The ANSI color code (e.g., "1;32" for bright green) * @param enabled - Whether color support is enabled * @returns Formatted text with ANSI codes when enabled, plain text otherwise */ export declare const colorize: (text: string, colorCode: string, enabled: boolean) => string; export declare const underline: () => string; export declare const defaultLogger: (role: string, operation: string | RegExp, result: boolean, colorsEnabled?: boolean) => void; export declare const normalizeWhen: <P>(when: When<P> | true) => NormalizedWhenFn<P> | true; export declare const regexFromOperation: (value: string | RegExp) => RegExp | null; export declare const globToRegex: (glob: string | string[]) => RegExp; export declare const hasMatchingOperation: (regex: RegExp, names: string[]) => boolean; export declare const buildPermissionData: <P = unknown>(permissions: Role<P>["can"]) => { direct: Set<string>; conditional: Map<string, NormalizedWhenFn<P>>; patterns: PatternPermission<P>[]; all: string[]; }; export type { When, WhenCallback, PatternPermission } from './types';