Skip to content

Latest commit

 

History

History
121 lines (68 loc) · 2.81 KB

internal.md

File metadata and controls

121 lines (68 loc) · 2.81 KB

Internal API

Considered stable unless denoted with "**".

NOTE: Unlike the rest of the spirit API, there are no camelCase variants.


is_Response

(spirit.node.utils.is_Response)

Returns true or false depending on if v is a instance of Response

Does not return true for a response map, this is a specific check.

Source: src/http/response-class.js (is_Response)

Arguments

  • v {*}

Return

{boolean}


size_of

(spirit.node.utils.size_of)

Returns the size of v in bytes, utf-8 is assumed.

It only returns a size for a string or buffer. Otherwise it returns undefined.

This function is useful for determining the "Content-Length" of a response body that is a string or buffer.

Source: src/http/utils.js (size_of)

Arguments

  • v {string|buffer} A string or buffer to check

Return

{number} The size of the v (string or buffer)


type_of

(spirit.node.utils.type_of)

** This function is expected to change in the future

Returns a string representation of the type of v. It is similar to typeof but it will also correctly detect and report types for: null, array, buffer, stream, file-stream.

As well as all types that typeof already identifies (undefined, string, number, etc.)

Example:

type_of([1, 2, 3]) // "array"
type_of(new Buffer("hi")) // "buffer"
type_of(null) // "null"

Source: src/http/utils.js (type_of)

Arguments

  • v {*} value or object to check

Return

{string} A string representation of the type of v


callp_response

(spirit.node.utils.callp_response)

Works similarly to spirit.callp. Except it adds special handling when the function being called returns a response map but with a response body that is a Promise.

When this occurs, resolves the response's body first instead of passing along a Promise of a response map which has a Promise as it's body that may not be resolved yet.

Additionally it surpresses Promise warnings regarding async error handling.

This is mostly used internally.

Source: src/core/promise_utils.js (resolve_response)

Arguments

  • p {Promise}

Return

{Promise}


resolve_response

(spirit.node.utils.resolve_response)

REMOVED IN v0.6.0

Resolves a response's body if it's a Promise.

This is mostly used internally.

Arguments

  • p {Promise}

Return

{Promise}