Constructor
new Cachier(optsopt, readFormatteropt, writeFormatteropt, logopt)
Constructor
- Source:
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
TemplateOpts
|
<optional> |
the |
||||||||||||||||||||
readFormatter |
function
|
<optional> |
The |
||||||||||||||||||||
writeFormatter |
function
|
<optional> |
The |
||||||||||||||||||||
log |
Object
|
<optional> |
The log for handling logging output
|
Members
log
- Source:
(protected) metadata
- Source:
operations
- Source:
options
- Source:
readFormatter
- Source:
readWriteNames
- Source:
- See:
-
Cachier.readWriteName
for parameter details
writeFormatter
- Source:
Methods
(static) contentURL(name, opts) → {Object}
Extracts the proper URL and option name used for a particular template, partial or context
- Source:
Parameters:
Name | Type | Description |
---|---|---|
name |
String
|
The template, partial or context name |
opts |
TemplateOpts
|
The template options |
Returns:
- Type:
-
Object
The extracted content that contains a url
property and a optionName
that describes the option used for the URL
(async, static) waiter(proms, errMsgopt, captureopt) → {Array|undefined}
Waits for promises to finish and throws commulative errors into a single meaningful stack while continuing to process
subsequent promises in the array. When an error is thrown and capture === true
, it will also contain a results
property that contains either each result from an awaited promise or an error thrown when waiting for the promise to
complete.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
proms |
Array.<Promise>
|
The promises to wait for. |
||
errMsg |
String
|
<optional> |
'One or more pomises failed' |
The message to use when any errors occur. |
capture |
Boolean
|
<optional> |
true |
When |
Returns:
- Type:
-
Array
|undefined
When capture === true
, the awaited promise results are retuend. When an error occurs,
the value at the given index will contain the error instead. When capture !== true
nothing is captured/returned.
(async) clear(allopt)
Clears the cache
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
all |
Boolean
|
<optional> |
false |
|
(async) compile(name, templateopt, paramsopt, extensionopt) → {function}
Compiles a locally sandboxed async
template rendering function and when applicable, stores the function in cache
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String
|
The template name that uniquely identifies the primary template content |
|
template |
String
|
Boolean
|
<optional> |
The raw template content, |
params |
URLSearchParams
|
<optional> |
Any URL search parmeters that will be passed when capturing the primary |
extension |
String
|
<optional> |
The file extension designation for the template |
(async) getRegistered(name, paramsopt, extensionopt) → {Object}
Retrieves a template, partial or context that resides in-memory.
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
String
|
The raw template name (i.e. not from |
||
params |
URLSearchParams
|
<optional> |
Any parameters designated during |
|
extension |
String
|
<optional> |
options.defaultExtension |
Optional override for a file extension designation
for the template, partial or context designated during |
Returns:
- Type:
-
Object
A copy of the generated data from Cachier.registerPartial
(async) modules(optional) → {Object}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
optional |
TemplateOpts
|
function
|
Either the |
(async) read(name, forContentopt, extensionopt, paramsopt) → {Object}
Reads either template content or template code from internal cache.
When options.partialsURL
is set to an HTTPS URL and the read is for partial content, A GET
call to window.fetch
is made
when running within browsers or to the https
module when running on the server. The partial name
will be appended to
options.partialsURL
(e.g. https://example.com/some/id.html
where some/id.html
is the the partial's
Cachier.readWriteName
and options.partialsURL
is set to https://example.com
). When options.partialsURL
is
omitted reading of template partial content will be limited to reading from memory. Compiled template source code is always
read from memory only.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String
|
The template name that uniquely identifies the template content |
|
forContent |
Boolean
|
<optional> |
|
extension |
String
|
<optional> |
The file extension designation (only used when |
params |
URLSearchParams
|
<optional> |
The |
Returns:
- Type:
-
Object
An object read from cache that contains either the template content or module.
Returned template content properties:
name
The template name that uniquely identifies the template contentcontent
The template contentextension
The template file extension designation
Returned module properties:
name
The template name that uniquely identifies the template contentfunc
The module function generated from the code
(async) readWriteName(name, optional, paramsopt, store, forContent, extensionopt, forContext) → {String}
Converts template names into a full path name consumable by read
/write
oprtations. Each function from
Cachier.readWriteNames
will be executed in order using the same arguments as Cachier.readWriteName
as well as an
additional last agument being the return value from the previous function invocation.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String
|
The name of the template, partial or context that will be converted into a name suitable for a read operation |
|
optional |
TemplateOpts
|
function
|
Either the |
|
params |
URLSearchParams
|
<optional> |
The parameters that should be used in the converted name |
store |
Object
|
The storage object that can contain metadata used by naming operations |
|
forContent |
Boolean
|
The flag indicating if the converted name is being used to capture partials |
|
extension |
String
|
<optional> |
The file extension override for the converted name (omit to use the default extension set in the options) |
forContext |
Boolean
|
The flag indicating if the converted name is being used to capture context |
Returns:
- Type:
-
String
The full template name
(async) register(dataopt, readopt, writeopt) → {Object}
Registers and caches the template, one or more partial templates and/or context JSON.
- Source:
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Array.<Object>
|
<optional> |
The template, partials and/or context to register.
|
||||||||||||||||||||
read |
Boolean
|
<optional> |
When |
||||||||||||||||||||
write |
Boolean
|
<optional> |
When |
Returns:
- Type:
-
Object
An object that contains the registration results:
data
The object that contains the template, partial fragments and/or context that have been registeredname
The name that uniquely identifies the template, partial or contextcontent
The raw content of the template, partial or contextextension
The template file extension designationparams
The URLSearchParams passed during the initial content readfromRead
A flag that indicates that the data was set from a read operation
registerHelper(func)
Registers a directive function that can be used within template interpolations
- Source:
Parameters:
Name | Type | Description |
---|---|---|
func |
function
|
A named |
(async) registerPartial(name, contentOrParams, extensionopt) → {String}
Registers and stores a partial template in-memory. Use Cachier.register
to write partials to cache (Cachier
)
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
String
|
The raw template name (i.e. not from |
||
contentOrParams |
String
|
URLSearchParams
|
Either the partial template content string to register or the
|
||
extension |
String
|
<optional> |
options.defaultExtension |
Optional override for a file extension designation for the partial |
Returns:
- Type:
-
String
The partial content
(async) unregister(name)
Unregisters a partial template from cache
- Source:
Parameters:
Name | Type | Description |
---|---|---|
name |
String
|
The template name that uniquely identifies the template content |
(async) write(name, data, forContentopt, extensionopt, paramsopt) → {function|undefined}
Writes either template content or template code from internal cache.
When options.partialsURL
is set to an HTTPS URL and the read is for partial content, A POST
call to window.fetch
is made
when running within browsers or to the https
module when running on the server. The partial name
will be appended to
options.partialsURL
(e.g. https://example.com/some/id.html
where some/id.html
is the the partial's
Cachier.readWriteName
and options.partialsURL
is set to https://example.com
). When options.partialsURL
is
omitted writting of template partial content will be limited to writes to memory. Compiled template source code is always
written to memory only.
- Source:
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String
|
The template name that uniquely identifies the template content |
|
data |
String
|
function
|
The data to write. For content, |
|
forContent |
Boolean
|
<optional> |
|
extension |
String
|
<optional> |
The file extension designation (only used when |
params |
URLSearchParams
|
<optional> |
The |
Returns:
- Type:
-
function
|undefined
Optionally return the compiled/written module function