humanity-deno
Version:
Humanity is a library for humanizing data in a human-readable form.
147 lines (146 loc) • 4.21 kB
TypeScript
import { LocaleObject } from "./Locales.js";
export declare type Feature = "spacing";
export declare type LocaleHumanity = "ru_RU" | "en_US" | "de_DE" | "custom";
declare class Humanity {
private localeObject;
private withSpace;
private suffixes;
dateTime: {
difference: (dateFirst: Date, dateAfter: Date) => string;
};
/**
* Constructor for setting locale
* @param locale Locale to be used
*/
constructor(locale?: LocaleHumanity, customLocale?: LocaleObject);
/**
* Disable functionality of features
* ```typescript
* // This feature disable space between number and word
* const Humanity = createHumanity();
* Humanity.disableFeature("spacing");
* console.log(Humanity.number(100000));
* // Output: 100thousand
* ```
* @param feature Feature to be used
*/
disableFeature(feature: Feature): void;
getLocale(locale: LocaleHumanity): LocaleObject;
private declinationNumbers;
/**
* @param lenZeros Length of the number
* @returns string
*/
private getZerosByCountZeros;
private switchWord;
/**
* Max returned number quintillion
* ```typescript
* Humanity.number(100); // return a humanized number
* ```
* @param n Number to be converted to a string
* @returns string representation of the number
*/
number(n: number | bigint): string;
private spaceIf;
/**
* Truncate string to max length and paste in end '...'
* ```typescript
* const str = Humanity.truncate(
* "Humanity is a library for humanizing data in a human-readable form.",
* 24
* );
*
* console.log(str);
*
* // Output: Humanity is a library fo...
* ```
* @param n Number to be converted to a string
* @param lengthMax
* @returns string
*/
truncate(n: string | number | bigint, lengthMax: number): string;
/**
* Convert arabic number to roman numerals
* @param n Number to be converted to a roman numerals
* @returns string
*/
toRoman(n: number): string;
/**
* Convert bytes to human readable format
* ### Example
* 0 B
*
* 1.00 B
*
* 1.00 KB
*
* 1.00 KB
* @param bytes Number of bytes
* @param fixed Number of decimal places
* @returns string
*/
binarySuffix(bytes: number, fixed?: number): string;
/**
* Collection data to string
* ```typescript
* const chatMembers = ["Dustin", "Leda", "Tristin", "Maybelle", "Dee", "Stephon"];
* const r = Humanity.arrayToText(chatMembers, 3);
* console.log(r);
* // Output: Dustin, Leda, Tristin and 3 others
* ```
* @param arr Array with your content
* @param n length to slice of array
* @returns string
*/
arrayToText<T = string>(arr: T[], n?: number): string;
humanCase(data: string): string;
/**
* If char is uppercase
* @param char
* @returns boolean
*/
isUpperCase(char: string): boolean;
/**
* If char is lowercase
* @param char
* @returns boolean
*/
isLowerCase(char: string): boolean;
}
/**
* create Humanity instance with default locale
* ```typescript
* const Humanity = createHumanity('en_US');
* console.log(Humanity.number(500000)); // 500 000
* // Output: 500 thousand
* ```
* @param locale Locale to be used
* @returns Humanity instance
*/
declare function createHumanity(locale?: LocaleHumanity): Humanity;
/**
* create Humanity instance with custom locale
* ```typescript
* const Humanity = createCustomHumanity({
* locale: "custom",
* numbers: {
* thousand: "tis",
* million: "er",
* billion: "pe",
* trillion: "xe",
* quadrillion: "fa",
* quintillion: "ier",
* },
* });
*
* console.log(Humanity.number(1000000)); // 1 000 000
* // Output: 1 er
* ```
* @param locale Locale to be used
* @returns Humanity instance
*/
declare function createCustomHumanity(locale: LocaleObject): Humanity;
declare const _default: Humanity;
export default _default;
export { createHumanity, createCustomHumanity };