Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace filterFunctions

Index

Functions

camelCase

  • camelCase(input?: string): string
  • Converts the given input to the camel case.

    Example

    camelCase("user-name"); // userName
    

    Parameters

    • input: string = ""

      is the input string to convert.

    Returns string

    string as camel case.

classCase

  • classCase(input?: string): string
  • Converts the given input to the class name.

    Example

    classCase("user-name"); // UserName
    

    Parameters

    • input: string = ""

      is the input string to convert.

    Returns string

    string as class case.

clearDefault

  • clearDefault(input?: string | null): string | undefined
  • Clears the default value of a database object.

    • Converts two quotes '' to single quote '
    • Removes quotes at the start and end of string.
    • Escapes result according to JSON standards.

    Example

    clearDefaultValue("'No ''value'' given'"); // "No value 'given'"
    

    Parameters

    • Optional input: string | null

      is the default for a database object.

    Returns string | undefined

    default value to be used in a template.

dashCase

  • dashCase(input?: string): string
  • Converts the given input to the dash case.

    Example

    dashCase("User Name"); // user-name
    

    Parameters

    • input: string = ""

      is the input string to convert.

    Returns string

    string as dash case.

dboClassName

  • dboClassName(object?: DbObject, schema?: boolean): string
  • Returns given the given database object name as a class name.

    Parameters

    • Optional object: DbObject

      is the object to get the name as a class name.

    • schema: boolean = false

      is whether to include schema name.

    Returns string

dboColumnTypeModifier

  • dboColumnTypeModifier(column?: Column): string
  • Returns column length, precision and scale ready to be used in templates.

    Example

    columnTypeModifier(price); // (10,4)
    columnTypeModifier(name); // (20)
    

    Parameters

    • Optional column: Column

      is the column to get details.

    Returns string

    modifier string.

doubleQuote

  • doubleQuote(input?: string): string
  • Wraps the given string with double quotes.

    Example

    plural("Some "example" text"); // "some \"example\" text"
    

    Parameters

    • Optional input: string

      is the input string to wrap with double quotes.

    Returns string

    string with quotes.

fill

  • fill(input?: string, length?: number, char?: string): string
  • Completes given input's length using with given character (by default space). It may be used to align strings in JSDoc etc.

    Example

    completeWithChar("member", "10"); // "member    "
    completeWithChar("member", "10", "-"); // "member----"
    

    Parameters

    • input: string = ""

      is the input to complete length of.

    • length: number = 20

      is the length of the finel string.

    • char: string = " "

      is the character to be used for filling.

    Returns string

human

  • human(input?: string, lowFirstLetter?: boolean): string
  • Converts text to natural language.

    Example

    human("message_properties"); // "Message properties"
    human("message_properties", true); // "message properties"
    

    Parameters

    • input: string = ""

      is the input string to convert.

    • Optional lowFirstLetter: boolean

      is whther to use small letter in first word.

    Returns string

    string in human readable form.

lcFirst

  • lcFirst(input?: string): string
  • Converts the given input's first letter to the lower case.

    Example

    plural("User_name"); // User_name
    

    Parameters

    • input: string = ""

      is the input string to convert.

    Returns string

    string with lower first case.

linePrefix

  • linePrefix(input?: string, prefix: string): string
  • Adds given prefix each of the lines of given text.

    Example

    linePrefix(`
    Text line 1
    Text line 2
    `, "// ");
    
    // Text line 1
    // Text line 2
    
    returs

    the result string.

    Parameters

    • input: string = ""

      is the input string.

    • prefix: string

      is the prefix to add each of the lines.

    Returns string

listAttribute

  • listAttribute<T>(objects: T[], attribute?: keyof T, options?: { join?: string; quote?: "single" | "double" | "json"; wrap?: string }): string
  • Returns an attribute of each objects as a CSV (comma separated values)

    Example

    const objects = [{ name: "a" }, { name: "b" }, { name: "c" }]
    
    listAttribute(objects, "name"); // a, b, c
    listAttribute(objects, "name", { quote: "json" }); // "a", "b", "c"
    listAttribute(objects, "name", { quote: "single" }); // 'a', 'b', 'c'
    listAttribute(objects, "name", { quote: "json", wrap: "[]" }); // ["a", "b", "c"]
    listAttribute(objects, "name", { quote: "json", wrap: "[]" }); // "a"
    

    Type parameters

    • T: unknown

    Parameters

    • objects: T[]

      are the array of objects to get attribute of.

    • attribute: keyof T = ...

      is the attribute to get for each object.

    • options: { join?: string; quote?: "single" | "double" | "json"; wrap?: string } = ...

      are the options.

      • Optional join?: string

        is the character to join list.

      • Optional quote?: "single" | "double" | "json"

        is whether to add quotes around attributes.

      • Optional wrap?: string

        is the characters to wrap the list if length is greater than 1.

    Returns string

    the list as a string.

maxLength

  • maxLength(input?: string, length?: number): string
  • Cuts the text after given number of characters.

    Example

    maxLength("some example text", 7); // "some ex...";
    

    Parameters

    • input: string = ""

      is the text to shorten.

    • length: number = 50

      is the maximum length allowed.

    Returns string

    cut text

padRight

  • padRight(input?: string, totalLength?: number, paddingString?: string): string
  • Pads given string's end with given padding string to complete its length to count.

    Parameters

    • input: string = ""

      is the input string to convert.

    • totalLength: number = 20

      is the total length of the result string.

    • paddingString: string = " "

      is the string to pad with.

    Returns string

    the string padded with padding string.

pascalCase

  • pascalCase(input?: string): string
  • Converts the given input to the pascal case.

    Example

    pascalCase("user-name"); // UserName
    

    Parameters

    • input: string = ""

      is the input string to convert.

    Returns string

    string as pascal case.

plural

  • plural(input?: string): string
  • Converts the given input to the plural form.

    Example

    plural("user_name"); // user_names
    

    Parameters

    • input: string = ""

      is the input string to convert.

    Returns string

    string in plural form.

quote

  • quote(input?: string): string
  • Wraps the given string with quotes.

    Example

    plural("user_name"); // "user_name"
    

    Parameters

    • Optional input: string

      is the input string to wrap with quotes.

    Returns string

    string with quotes.

singleLine

  • singleLine(input?: string): string
  • If given data is a multi line string replaces new lines with escape characters. May be used to prevent JS multi line errors.

    Parameters

    • input: string = ""

      is the input to convert.

    Returns string

    the string with escape characters.

singleQuote

  • singleQuote(input?: string): string
  • Wraps the given string with single quotes.

    Example

    plural("Some 'example' text"); // 'some \'example\' text'
    

    Parameters

    • Optional input: string

      is the input string to wrap with single quotes.

    Returns string

    string with quotes.

singular

  • singular(input?: string): string
  • Converts the given input to the singular form.

    Example

    singular("user_names"); // user_name
    

    Parameters

    • input: string = ""

      is the input string to convert.

    Returns string

    string in singular form.

snakeCase

  • snakeCase(input?: string): string
  • Converts the given input to the snake case.

    Example

    snakeCase("userName"); // user_name
    

    Parameters

    • input: string = ""

      is the input string to convert.

    Returns string

    string as snake case.

stringify

  • stringify(input: any, options?: { indent?: number; nullToUndef?: boolean; raw?: boolean }): string
  • If given data is object or array, converts it to string.

    1. If it has toString method uses it. If it returns [object Object] tries other steps.
    2. Uses util.inspect();

    Parameters

    • input: any

      is the input to convert.

    • options: { indent?: number; nullToUndef?: boolean; raw?: boolean } = ...

      are the options.

      • Optional indent?: number

        is size of the indentation of each level.

      • Optional nullToUndef?: boolean

        if true, converts all null values to undefined.

      • Optional raw?: boolean

        if true, does not add quotes around values.

    Returns string

    converted value.

strip

  • strip(input: string | undefined, ...removeList: (string | { name: string })[]): string
  • Vairadic function which strips all of the given strings or database object's names from the source string.

    Parameters

    • input: string | undefined

      is the input string to convert.

    • Rest ...removeList: (string | { name: string })[]

      is the list of strings or objects to remove from input.

    Returns string

    converted string.

stripPrefix

  • stripPrefix(input: string | undefined, ...removeList: (string | { name: string })[]): string
  • Vairadic function which strips all of the given strings or database object's names from the start of the source string.

    Parameters

    • input: string | undefined

      is the input string to convert.

    • Rest ...removeList: (string | { name: string })[]

      is the list of strings or objects to remove from input.

    Returns string

    converted string.

stripSuffix

  • stripSuffix(input: string | undefined, ...removeList: (string | { name: string })[]): string
  • Vairadic function which strips all of the given strings or database object's names from the end of the source string.

    Parameters

    • input: string | undefined

      is the input string to convert.

    • Rest ...removeList: (string | { name: string })[]

      is the list of strings or objects to remove from input.

    Returns string

    converted string.

titleCase

  • titleCase(input?: string): string
  • Converts the given input to the title case.

    Example

    titleCase("user_name"); // User Name
    

    Parameters

    • input: string = ""

      is the input string to convert.

    Returns string

    string as title case.

ucFirst

  • ucFirst(input?: string): string
  • Converts the given input's first letter to the upper case.

    Example

    plural("user_name"); // User_name
    

    Parameters

    • input: string = ""

      is the input string to convert.

    Returns string

    string with upper first case.

uniqueArray

  • uniqueArray<T>(input?: T[]): T[]
  • Returns given array with unique elements by eliminating duplicate values.

    Type parameters

    • T: unknown

    Parameters

    • Optional input: T[]

      is the input array to eliminate duplicates from.

    Returns T[]

    the array with unique values.

wordWrap

  • wordWrap(input?: string, startOrStop?: number, stop?: number): string
  • Word wraps given text.

    Example

    wordWrap("The quick fox", 10); // "The quick\nfox"
    wordWrap("The quick fox", 2, 10); // "  The quick\n  fox"
    

    Parameters

    • Optional input: string

      is the text to word wrap.

    • startOrStop: number = 80

      is the start or the stop position of each line. (The stop position if this is single option.)

    • Optional stop: number

      is the stop position of each line.

    Returns string

    word wrapped text.

wrap

  • wrap(input?: string, wrapper?: string): string
  • Wraps given text with start and end characters. By default it wraps with curly braces.

    Example

    wrap("hello"); // "{hello}"
    wrap("hello", "~"); // "~hello~"
    wrap("hello", "[]"); // "[hello]"
    

    Parameters

    • Optional input: string

      is the text to warp.

    • wrapper: string = "{}"

    Returns string

    wrapped text.

wrapIf

  • wrapIf(input: string | undefined, condition: any, wrapper?: string): string
  • Wraps given text with start and end characters if given condition is truthy. By default it wraps with curly braces.

    Example

    wrapIf("hello", "x"); // "{hello}"
    wrapIf("hello", true); // "{hello}"
    wrapIf("hello", false); // "hello"
    wrapIf("hello", true, "~"); // "~hello~"
    wrapIf("hello", true, "[]"); // "[hello]"
    

    Parameters

    • input: string | undefined

      is the text to warp.

    • condition: any

      is the condition or value to test.

    • wrapper: string = "{}"

    Returns string

    wrapped text.

Generated using TypeDoc