UNPKG

1.87 kBTypeScriptView Raw
1/**
2 * Converts string into camelCase.
3 *
4 * @see http://stackoverflow.com/questions/2970525/converting-any-string-into-camel-case
5 */
6export declare function camelCase(str: string, firstCapital?: boolean): string;
7/**
8 * Converts string into snake-case.
9 *
10 * @see https://regex101.com/r/QeSm2I/1
11 */
12export declare function snakeCase(str: string): string;
13/**
14 * Converts string into title-case.
15 *
16 * @see http://stackoverflow.com/questions/196972/convert-string-to-title-case-with-javascript
17 */
18export declare function titleCase(str: string): string;
19/**
20 * Builds abbreviated string from given string;
21 */
22export declare function abbreviate(str: string, abbrLettersCount?: number): string;
23export interface IShortenOptions {
24 /** String used to split "segments" of the alias/column name */
25 separator?: string;
26 /** Maximum length of any "segment" */
27 segmentLength?: number;
28 /** Length of any "term" in a "segment"; "OrderItem" is a segment, "Order" and "Items" are terms */
29 termLength?: number;
30}
31/**
32 * Shorten a given `input`. Useful for RDBMS imposing a limit on the
33 * maximum length of aliases and column names in SQL queries.
34 *
35 * @param input String to be shortened.
36 * @param options Default to `4` for segments length, `2` for terms length, `'__'` as a separator.
37 *
38 * @return Shortened `input`.
39 *
40 * @example
41 * // returns: "UsShCa__orde__mark__dire"
42 * shorten('UserShoppingCart__order__market__director')
43 *
44 * // returns: "cat_wit_ver_lon_nam_pos_wit_ver_lon_nam_pos_wit_ver_lon_nam"
45 * shorten(
46 * 'category_with_very_long_name_posts_with_very_long_name_post_with_very_long_name',
47 * { separator: '_', segmentLength: 3 }
48 * )
49 *
50 * // equals: UsShCa__orde__mark_market_id
51 * `${shorten('UserShoppingCart__order__market')}_market_id`
52 */
53export declare function shorten(input: string, options?: IShortenOptions): string;