node-fre-utils/lib/utils/rotines.d.ts

97 lines
3.8 KiB
TypeScript

/**
* Classe de rotinas basicas para utilização em qualquer sistema
*
* @export
* @class Routines
*/
export declare class Routines {
/**
* Completa a string um valor informado e do lado informado
*
* @static
* @param {string} valor Valor base para concatenar
* @param {string} mascara Valor que será utilizado paca completar a string Ex.: '0' ou ' '
* @param {('E' | 'D')} lado Lado que será completada a string 'E' = Esquerda ou 'D' = Direita
* @param {number} tamanho Tamanho final que a string deve ter
* @param {boolean} [recorta=true] Remove o resto do valor caso o valor fique maior que o tamanho definido
* @returns {string} Retorna a string formatada
* @memberof Routines
*/
static CompletaCampos: (valor: string, mascara: string, lado: 'E' | 'D', tamanho: number, recorta?: boolean) => string;
/**
* Converte 2 bytes em um word
*
* @static
* @param {Uint8Array} bytes Array com no minimo 2 bytes os demais bytes serão ignorados
* @returns {(number | undefined)} retorna undefined caso seja menor que 2 bytes ou o valor convertido
* @memberof Routines
*/
static ByteToWord: (bytes: Uint8Array) => number | undefined;
/**
* Converte até 4 bytes em um number
*
* @static
* @param {Uint8Array} bytes
* @returns {(number | undefined)} retorna undefined caso não tenha entre 1 e 4 bytes ou o valor convertido
* @memberof Routines
*/
static ByteToNumber: (bytes: Uint8Array) => number | undefined;
/**
* Converte um array de bytes em String
*
* @static
* @param {Uint8Array} bytes Array de bytes Ex.: [0x31, 0x32, 0x33, 0x2A]
* @returns {string} retorna a string convertida Ex: [0x31, 0x32, 0x33, 0x2A] = '123*'
* @memberof Routines
*/
static ByteToString: (bytes: Uint8Array) => string;
/**
* Converte um array de bytes em uma string com o valor hexadecimal correspondente
*
* @static
* @param {Uint8Array} bytes Array de bytes Ex.: [0x31, 0x32, 0x33, 0x2A]
* @returns {string} retorna a string convertida Ex: [0x31, 0x32, 0x33, 0x2A] = '3132332A'
* @memberof Routines
*/
static ByteToHexa: (bytes: Uint8Array) => string;
/**
* Converte uma string em hexadecimal para um array de bytes
*
* @static
* @param {string} hex String em hexa Ex.: '3132332A'
* @returns {Uint8Array} Retorna um array de bytes referente a string Ex: '3132332A' = [0x31, 0x32, 0x33, 0x2A]
* @memberof Routines
*/
static StrHexaToByte: (hex: string) => Uint8Array;
/**
* Converte uma string em array de bytes
*
* @static
* @param {string} str String que será convertida EX.: '123*'
* @returns {Uint8Array} retorna um array com os valores correspondentes Ex: '123*' = [0x31, 0x32, 0x33, 0x2A]
* @memberof Routines
*/
static StrToByte: (str: string) => Uint8Array;
/**
* Verifiaca se um número informado está entre outros dois
*
* @static
* @param {number} x valor que será verificado
* @param {number} min valor minino da comparação
* @param {number} max valor maximo da comparação
* @returns {boolean} retorna se o x está entre o min e o max
* @memberof Routines
*/
static between: (x: number, min: number, max: number) => boolean;
/**
* Converte uma string em número caso não seja um número válido ele devolve o valor default
*
* @static
* @param {string} s String com um valor numérico que será convertido
* @param {number} df valor default que será resultado caso a conversão falhe
* @returns {number} retorna o valor convertido ou o default caso não consiga converter
* @memberof Routines
*/
static parseNumber: (s: string, df: number) => number;
}