Options
All
  • Public
  • Public/Protected
  • All
Menu

@lerado/typescript-toolbox

Index

Type aliases

CallbackFunction

CallbackFunction<T>: (value: T, change: SimpleChange<T>) => unknown

Type parameters

  • T

Type declaration

SimpleChange

SimpleChange<T>: { currentValue: T; firstChange: boolean; previousValue: T } & { isFirstChange: () => boolean }

Type parameters

  • T

Variables

Const STRONG_PASSWORD_REGEXP

STRONG_PASSWORD_REGEXP: RegExp = /(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9])(?=.{8,})/

Strong password regular expression

Rules

- at least eight characters long

- at least one capital letter

- at least one small letter

- at least one number

- at least one special character

Const URL_REGEXP

URL_REGEXP: RegExp = /^(http(s):\/\/.)[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)$/

URL validation regular expression

Rules

- The string should start with either http or https followed by ://.

- The combined length of the sub-domain and root domain must be between 2 and 256. It should only contain alphanumeric characters and/or special characters.

- The TLD (Top-Level Domain) should only contain alphabetic characters and it should be between two and six characters long.

- The end of the URL string could contain alphanumeric characters and/or special characters. And it could repeat zero or more times.

Functions

Const OnChange

  • Invokes a callback method when a class property is set

    Usage

    import { OnChange } from '@lerado/typescript-toolbox';
    
    class MyClass {
     &#64;OnChange(function(changes) {
       console.log(changes);
     })
     property1 = 0;
    
     &#64;OnChange(function(changes) {
       console.log(changes);
     })
     property1 = 0;
    }
    

    Type parameters

    • T = unknown

    Parameters

    Returns CallableFunction

Const breadthFirstTraversal

  • breadthFirstTraversal<T>(root: T, childrenKey: string, callable?: undefined | ((visitedElement: T) => unknown)): Partial<T>[]
  • Performs a breadth-first traversal of a tree-like structure and returns the march of the traversal

    Usage

    import { breadthFirstTraversal } from '@lerado/typescript-toolbox';
    
    const tree = {
     id: 1,
     children: [
       { id: 2, children: [ { id: 4 } ] },
       { id: 3, children: [ { id: 5 } ] }
     ]
    };
    
    breadthFirstTraversal(tree, 'children', console.log);
    // => console: 1, 2, 3, 4, 5
    // => [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]
    

    Type parameters

    • T: Record<string, unknown>

    Parameters

    • root: T

      the tree's root object

    • childrenKey: string

      accessor name for child elements

    • Optional callable: undefined | ((visitedElement: T) => unknown)

    Returns Partial<T>[]

Const depthFirstTraversal

  • depthFirstTraversal<T>(root: T, childrenKey: string, callable?: undefined | ((visitedElement: T) => unknown)): Partial<T>[]
  • Performs a depth-first traversal of a tree-like structure and returns the march of the traversal

    Usage

    import { depthFirstTraversal } from '@lerado/typescript-toolbox';
    
    const tree = {
     id: 1,
     children: [
       { id: 2, children: [ { id: 4 } ] },
       { id: 3, children: [ { id: 5 } ] }
     ]
    };
    
    depthFirstTraversal(tree, 'children', console.log);
    // => console: 1, 2, 4, 3, 5
    // => [{ id: 1 }, { id: 2 }, { id: 4 },  { id: 3 },  { id: 5 }]
    

    Type parameters

    • T: Record<string, unknown>

    Parameters

    • root: T

      the tree's root object

    • childrenKey: string

      accessor name for child elements

    • Optional callable: undefined | ((visitedElement: T) => unknown)

    Returns Partial<T>[]

isStrongPassword

  • isStrongPassword(password: string): boolean
  • Returns true if a given password is considered a strong password, false otherwise

    Usage

    import { isStrongPassword } from '@lerado/typescript-toolbox';
    
    isStrongPassword('123456');
    // => false
    isStrongPassword('password123');
    // => false
    isStrongPassword('Password123');
    // => false
    isStrongPassword('Password!123');
    // => true
    
    see

    STRONG_PASSWORD_REGEXP

    Parameters

    • password: string

      string representing a password to check

    Returns boolean

Const objectToFlatString

  • objectToFlatString(object: Record<string, unknown>): string
  • Serializes an object. The idea is to serialize each object to a queryable string. This is very useful for search engines.

    Usage

    import { objectToFlatString } from '@lerado/typescript-toolbox';
    
    objectToFlatString({ id: 123, name: 'Mr. Smith', age: 23 });
    // => to 123mr. smith23.
    

    Parameters

    • object: Record<string, unknown>

    Returns string

strongPassword

  • strongPassword(length: number): string
  • Generates a strong password given a certain length (length >= 8)

    Usage

    import { strongPassword } from '@lerado/typescript-toolbox';
    
    strongPassword(7);
    // => throws error: Can not create a strong password less than 8 characters long
    strongPassword(8);
    // => 8u5!W^g!
    
    see

    STRONG_PASSWORD_REGEXP

    Parameters

    • length: number

      length of the generated password

    Returns string

validateURL

  • validateURL(url: string): boolean
  • Returns true if a given string is considered a valid URL, false otherwise

    Usage

    import { validateURL } from '@lerado/typescript-toolbox';
    
    validateURL('https://www.linkedin.com/');
    // => true
    validateURL('http://apple');
    // => false
    validateURL('bullshit');
    // => false
    validateURL('https://w');
    // => false
    
    see

    URL_REGEXP

    Parameters

    • url: string

      string representing a password to check

    Returns boolean

Generated using TypeDoc