Options
All
  • Public
  • Public/Protected
  • All
Menu
     

Module JSN

A collection of JSON handling functions

Index

Functions

Normal

  • Normal(obj: object): string
  • Returns a beautified, string-representation of an Object based on it's enumerable properties.

    Parameters

    • obj: object

    Returns string

Pretty

  • Pretty(obj: any): string
  • Formats and Object into a 4-space tabbed JSON String

    Parameters

    • obj: any

      The Object to format

    Returns string

    The formatted JSON String

Has

  • Has(obj: any, prop: string | number): boolean
  • A safe, compact version of Object.hasOwnProperty(prop)

    Parameters

    • obj: any

      The object to search

    • prop: string | number

      The property name to search for

    Returns boolean

    true, if found

Map

  • Map(obj: object, handler: Function): object
  • Like Array.map(), but for Object literals

    Parameters

    • obj: object

      An Object literal to Map

      • [key: string]: any
    • handler: Function

      The handler for each property

    Returns object

    The newly mapped Object literal

    • [key: string]: any

MapWith

  • MapWith(obj: object, prop: PropertyKey): object
  • Like JSN.map(), except this maps to a specific property within each property's own Object literal

    Parameters

    • obj: object

      An Object literal to Map

      • [key: string]: any
    • prop: PropertyKey

      The sub-property to map to

    Returns object

    The newly mapped Object literal

    • [key: string]: any

MapEdit

  • MapEdit(obj: object, handler: Function, opts: string): object
  • Edits the properties in an Object literal if the properties match a specified pattern

    Parameters

    • obj: object

      An Object literal to Map

      • [key: string]: any
    • handler: Function

      The handler for each property

    • opts: string

      A String of RegExp modifiers

    Returns object

    The newly edited Object literal

    • [key: string]: any

MapPrint

  • MapPrint(obj: object, patterns: JPatterns, reverse: boolean): string
  • Formats an Object literal's keys & values into String given a specified template

    Parameters

    • obj: object

      An Object literal to format

      • [key: string]: string
    • patterns: JPatterns

      Patterns to format the keys/value pairs by

    • reverse: boolean

      Reverses the key order, if true

    Returns string

    The formatted JSON String

Len

  • Len(obj: object): number
  • Gets the length of an Object literal

    Parameters

    • obj: object

      The Object literal

      • [key: string]: string

    Returns number

    The length of the Object literal

KV

  • KV(obj: object): Object
  • Splits an Object literal into separate key and value Arrays

    Parameters

    • obj: object

      The Object literal

      • [key: string]: string

    Returns Object

    An Object with the key and value Arrays

Objectify

  • Objectify(list: any, key: string | number, cols: any, qry: JSNQuery): string
  • Converts an Array of Object literals into a JSON String object for HTTP requests. It does this by grabbing the specified key from each item, and adds said item into an Object literal property as key: item. This is useful when dealing with MySQL.RowData.

    Parameters

    • list: any

      An Array of Row results

    • key: string | number

      The property

    • cols: any

      An Object lieteral denoting the propety path to set each Row in.

    • qry: JSNQuery

      A query object used for further customization

    Returns string

    A JSON formatted String

Optify

  • Optify(pgn: Object, items: any, prefix: string, params: JSNPost, links?: JSNLinks): Object
  • Creates an Object literal of options & links

    Parameters

    • pgn: Object

      The page & limit Numbers

    • items: any

      The actual results themselves

    • prefix: string

      A preceding path for this Endpoint

    • params: JSNPost

      The POST parameters

    • Optional links: JSNLinks

      Any Related links

    Returns Object

    An Object literal of options & links

Result

  • Creates a JSON object for HTTP results

    Parameters

    • status: number

      A 0 for success or an Error code

    • value: any

      The actual results themselves

    • Optional options: JSNOptions

      The result's metadata

    • Optional links: JSNLinks

      The result's relavent links

    Returns JSNResult

    A JSON object for HTTP results

Valid

  • Creates a payload object of HTTP results

    Parameters

    • itms: any

      The actual results themselves

    • options: JSNOptions

      The result's metadata

    • links: JSNLinks

      The result's relavent links

    • code: number

      The HTTP status code

    Returns JSNPayload

    The payload object

Help

  • Help(url: string, message: string, usage: any, code: number): JSNPayload
  • Creates a payload object of HTTP documentation

    Parameters

    • url: string

      The Endpoint being documented

    • message: string

      A decsriptive message

    • usage: any

      The actual documentation

    • code: number

      code The HTTP status code

    Returns JSNPayload

    The payload object

Error

  • Error(message: string, err: Error): string
  • Displays a specified message or the first line of the Error.stack if the message if null

    Parameters

    • message: string

      A message to display for the Error

    • err: Error

      The Error object, which will be used if the message is null

    Returns string

    The Error message