surge-auth-generator
Version:
Generate AUTH files for basic authentication in surge.sh projects
45 lines (44 loc) • 1.93 kB
TypeScript
/// <reference types="node" />
/**
* User authentication credentials
*
* @interface Credential
*/
export interface Credential {
/** authentication username */
username?: string;
/** authentication password */
password?: string;
/** whether the username should be case insensitive during authentication */
caseInsensitive?: boolean;
}
/**
* @description Generate all case permutations for a given string
* @param input the string for which to determine permutations
* @returns all possible case permutations
* @see adopted from {@link https://stackoverflow.com/a/27995370|stackoverflow answer}
* @license {@link https://creativecommons.org/licenses/by-sa/3.0/|Creative Commons licence 3.0}
*/
export declare const getAllCasePermutations: (input: string | undefined) => string[];
/**
* @description Generate AUTH file string for given credentials
* @param credentials the credentials to convert to AUTH file string
* @returns the credential string
* @example
* // returns 'foo:bar'
* getCredentialString({username: 'foo', password: 'bar', isCaseInsensitive: false});
*/
export declare const getCredentialString: (credential: Credential) => string;
/**
* @description Write an AUTH file to the file system
* @param content the file contents
* @param directory the output directory
* @returns promise resolving in the full path of the written file
*/
export declare const writeAuthFile: (content: string, directory: string | undefined) => Promise<string | NodeJS.ErrnoException>;
/**
* @description Write an AUTH file with given credentials
* @param [credentials={}] the credentials to be written
* @param [directory=require.main.filename] the output directory (defaults to project root)
*/
export declare const generate: (credentials?: Credential | Credential[], directory?: string | undefined) => Promise<string | NodeJS.ErrnoException>;