pg-generator / filterFunctions

# Namespace: filterFunctions

# Functions

# camelCase

camelCase(input?: string): string

Converts the given input to the camel case.

# Example

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

# Parameters:

Name Type Default value Description
input string "" is the input string to convert.

Returns: string

string as camel case.

Defined in: utils/filter-functions.ts:49


# classCase

classCase(input?: string): string

Converts the given input to the class name.

# Example

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

# Parameters:

Name Type Default value Description
input string "" is the input string to convert.

Returns: string

string as class case.

Defined in: utils/filter-functions.ts:75


# 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:

Name Type Description
input? string | null is the default for a database object.

Returns: string | undefined

default value to be used in a template.

Defined in: utils/filter-functions.ts:27


# dashCase

dashCase(input?: string): string

Converts the given input to the dash case.

# Example

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

# Parameters:

Name Type Default value Description
input string "" is the input string to convert.

Returns: string

string as dash case.

Defined in: utils/filter-functions.ts:101


# dboClassName

dboClassName(object?: DbObject, schema?: boolean): string

Returns given the given database object name as a class name.

# Parameters:

Name Type Default value Description
object? DbObject - is the object to get the name as a class name.
schema boolean false is whether to include schema name.

Returns: string

Defined in: utils/filter-functions.ts:501


# 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:

Name Type Description
column? Column is the column to get details.

Returns: string

modifier string.

Defined in: utils/filter-functions.ts:516


# doubleQuote

doubleQuote(input?: string): string

Wraps the given string with double quotes.

# Example

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

# Parameters:

Name Type Description
input? string is the input string to wrap with double quotes.

Returns: string

string with quotes.

Defined in: utils/filter-functions.ts:220


# 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:

Name Type Default value Description
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

Defined in: utils/filter-functions.ts:306


# 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:

Name Type Default value Description
input string "" is the input string to convert.
lowFirstLetter? boolean - is whther to use small letter in first word.

Returns: string

string in human readable form.

Defined in: utils/filter-functions.ts:155


# lcFirst

lcFirst(input?: string): string

Converts the given input's first letter to the lower case.

# Example

plural("User_name"); // User_name

# Parameters:

Name Type Default value Description
input string "" is the input string to convert.

Returns: string

string with lower first case.

Defined in: utils/filter-functions.ts:168


# 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:

Name Type Default value Description
input string "" is the input string.
prefix string - is the prefix to add each of the lines.

Returns: string

Defined in: utils/filter-functions.ts:369


# 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:

Name Type
T unknown

# Parameters:

Name Type Description
objects T[] are the array of objects to get attribute of.
attribute keyof T is the attribute to get for each object.
options object are the options.
options.join? string is the character to join list.
options.quote? single | double | json is whether to add quotes around attributes.
options.wrap? string is the characters to wrap the list if length is greater than 1.

Returns: string

the list as a string.

Defined in: utils/filter-functions.ts:461


# maxLength

maxLength(input?: string, length?: number): string

Cuts the text after given number of characters.

# Example

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

# Parameters:

Name Type Default value Description
input string "" is the text to shorten.
length number 50 is the maximum length allowed.

Returns: string

cut text

Defined in: utils/filter-functions.ts:290


# 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:

Name Type Default value Description
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.

Defined in: utils/filter-functions.ts:274


# pascalCase

pascalCase(input?: string): string

Converts the given input to the pascal case.

# Example

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

# Parameters:

Name Type Default value Description
input string "" is the input string to convert.

Returns: string

string as pascal case.

Defined in: utils/filter-functions.ts:62


# plural

plural(input?: string): string

Converts the given input to the plural form.

# Example

plural("user_name"); // user_names

# Parameters:

Name Type Default value Description
input string "" is the input string to convert.

Returns: string

string in plural form.

Defined in: utils/filter-functions.ts:140


# quote

quote(input?: string): string

Wraps the given string with quotes.

# Example

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

# Parameters:

Name Type Description
input? string is the input string to wrap with quotes.

Returns: string

string with quotes.

Defined in: utils/filter-functions.ts:194


# 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:

Name Type Default value Description
input string "" is the input to convert.

Returns: string

the string with escape characters.

Defined in: utils/filter-functions.ts:427


# singleQuote

singleQuote(input?: string): string

Wraps the given string with single quotes.

# Example

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

# Parameters:

Name Type Description
input? string is the input string to wrap with single quotes.

Returns: string

string with quotes.

Defined in: utils/filter-functions.ts:207


# singular

singular(input?: string): string

Converts the given input to the singular form.

# Example

singular("user_names"); // user_name

# Parameters:

Name Type Default value Description
input string "" is the input string to convert.

Returns: string

string in singular form.

Defined in: utils/filter-functions.ts:127


# snakeCase

snakeCase(input?: string): string

Converts the given input to the snake case.

# Example

snakeCase("userName"); // user_name

# Parameters:

Name Type Default value Description
input string "" is the input string to convert.

Returns: string

string as snake case.

Defined in: utils/filter-functions.ts:88


# 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:

Name Type Description
input any is the input to convert.
options object are the options.
options.indent? number is size of the indentation of each level.
options.nullToUndef? boolean if true, converts all null values to undefined.
options.raw? boolean if true, does not add quotes around values.

Returns: string

converted value.

Defined in: utils/filter-functions.ts:404


# 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:

Name Type Description
input string | undefined is the input string to convert.
...removeList (string | { name: string })[] is the list of strings or objects to remove from input.

Returns: string

converted string.

Defined in: utils/filter-functions.ts:259


# 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:

Name Type Description
input string | undefined is the input string to convert.
...removeList (string | { name: string })[] is the list of strings or objects to remove from input.

Returns: string

converted string.

Defined in: utils/filter-functions.ts:231


# 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:

Name Type Description
input string | undefined is the input string to convert.
...removeList (string | { name: string })[] is the list of strings or objects to remove from input.

Returns: string

converted string.

Defined in: utils/filter-functions.ts:245


# titleCase

titleCase(input?: string): string

Converts the given input to the title case.

# Example

titleCase("user_name"); // User Name

# Parameters:

Name Type Default value Description
input string "" is the input string to convert.

Returns: string

string as title case.

Defined in: utils/filter-functions.ts:114


# ucFirst

ucFirst(input?: string): string

Converts the given input's first letter to the upper case.

# Example

plural("user_name"); // User_name

# Parameters:

Name Type Default value Description
input string "" is the input string to convert.

Returns: string

string with upper first case.

Defined in: utils/filter-functions.ts:181


# uniqueArray

uniqueArray<T>(input?: T[]): T[]

Returns given array with unique elements by eliminating duplicate values.

# Type parameters:

Name Type
T unknown

# Parameters:

Name Type Description
input? T[] is the input array to eliminate duplicates from.

Returns: T[]

the array with unique values.

Defined in: utils/filter-functions.ts:437


# 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:

Name Type Default value Description
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.)
stop? number - is the stop position of each line.

Returns: string

word wrapped text.

Defined in: utils/filter-functions.ts:484


# 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:

Name Type Default value Description
input? string - is the text to warp.
wrapper string "{}" -

Returns: string

wrapped text.

Defined in: utils/filter-functions.ts:324


# 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:

Name Type Default value Description
input string | undefined - is the text to warp.
condition any - is the condition or value to test.
wrapper string "{}" -

Returns: string

wrapped text.

Defined in: utils/filter-functions.ts:348