Skip to content

cachier-files

CachierFiles

Node.js file persistence manager that uses the file system for improved debugging/caching capabilities

Kind: global class

new CachierFiles([opts], [readFormatter], [writeFormatter], [log])

Constructor

ParamTypeDescription
[opts]TemplateFileOptsThe TemplateFileOpts
[readFormatter]functionThe function(string, readFormatOptions) that will return a formatted string for reading data using the options.readFormatOptions from TemplateOpts as the formatting options. Typically reads are for HTML minification and/or beautifying. NOTE: Use with caution as syntax errors may result depending on the formatter used and the complexity of the data being formatted!
[writeFormatter]functionThe function(string, writeFormatOptions) that will return a formatted string for writting data using the options.writeFormatOptions from TemplateOpts as the formatting options. Typically reads are for JS minification and/or beautifying. NOTE: Use with caution as syntax errors may result depending on the formatter used and the complexity of the data being formatted!
[log]ObjectThe log for handling logging output
[log.debug]functionA function that will accept debug level logging messages (i.e. debug('some message to log'))
[log.info]functionA function that will accept info level logging messages (i.e. info('some message to log'))
[log.warn]functionA function that will accept warning level logging messages (i.e. warn('some message to log'))
[log.error]functionA function that will accept error level logging messages (i.e. error('some message to log'))

cachierFiles.metadata

Kind: instance property of CachierFiles

cachierFiles.readWriteNames

Kind: instance property of CachierFiles

cachierFiles.operations

Kind: instance property of CachierFiles

cachierFiles.register([read], [data], [read], [write]) ⇒ Object

Registers and caches the tempalte, one or more partials and/or context within the internal file system. Also creates any missing directories/sub-directories within the TemplateFileOpts outputPath directory from partialsPath sub-directories.

Kind: instance method of CachierFiles
Returns: Object - An object that contains the registration results:

  • data The object that contains the template, partial fragments and/or context that have been registered
    • name The name that uniquely identifies the template, partial or context
    • content The raw content of the template, partial or context
    • extension The template file extension designation
    • params The URLSearchParams passed during the initial content read
    • fromRead A flag that indicates that the data was set from a read operation
    • overrideFromFileRead A flag that indicates if the passed partial content was overridden by content from a file read
  • dirs Contains the directories/sub-directories that were created
ParamTypeDescription
[read]BooleanWhen true, an attempt will be made to also read any partials using option parameter
[data]Array.<Object>The template, partials and/or context to register.
partials[].nameStringThe name that uniquely identifies the template, partial or context
[partials[].content]StringThe raw content that will be registered. Omit when read === true to read content from cache.
[partials[].params]URLSearchParamsThe URLSearchParams that will be passed during the content read (ignored when content is specified).
[partials[].extension]StringOptional override for a file extension designated for a template, partial or context.
[read]BooleanWhen true, an attempt will be made to also Cachier.read the template, partials and context that do not have a content property set.
[write]BooleanWhen true, an attempt will be made to also Cachier.write the template, partials and context that have a content property set.

cachierFiles.compile()

Kind: instance method of CachierFiles

cachierFiles.read()

Kind: instance method of CachierFiles

cachierFiles.write()

Kind: instance method of CachierFiles

cachierFiles.clear([all])

Clears the output directories and any file watchers

Kind: instance method of CachierFiles

ParamTypeDefaultDescription
[all]Booleanfalsetrue to clear all temporary directories created over multiple instances

Released under the MIT License.