fin-de-siecle
is: An Interface And Ground Implementation For JSX Via HTML Textual Data Processing With Efficient Caching.
yarn add fin-de-siecle
npm i fin-de-siecle
The package is available by importing its default class:
import FinDeSiècle from 'fin-de-siecle'
FinDeSiècle
extends _restream.Replaceable: An interface for processing.
Name | Type | Description | Initial |
---|---|---|---|
constructor | new () => FinDeSiècle | Constructor method. | - |
CACHE_DIR | string | The directory where caches are stored. | .cache |
pretty | (enable: boolean) => void | Whether to enable pretty printing (default true). | - |
getCache | (type: string, name?: string) => !Promise<*> | Returns the cache for the given type as an object by reading and parsing the file asynchronously. | - |
getCacheSync | (type: string, name?: string) => * | Returns the cache for the given type as an object. | - |
appendCache | (type: string, value: !Object<string, *>) => !Promise<void> | Adds a new record in the cache by writing to the cache file asynchronusly. | - |
appendCacheSync | (type: string, value: !Object<string, *>) => void | Adds a new record in the cache. | - |
info | (...data: string[]) => void | Logs with the info level. |
- |
getLocaleMtime | (path: string) => !Promise<string> | Returns the change mtime in local date format. Used for caching. |
- |
getLocaleMtimeSync | (path: string) => string | Returns the change mtime in local date format. Used for caching. |
- |
stat | (path: string) => !Promise<fs.Stats> | Returns the full stats of the file asynchronously. | - |
For example, the text can be transformed using a regular expression and an async rule that will check when the file was last modified. If the target cache entry wasn't created yet, or the file was updated since (ls
is different), the cache will be upgraded. Upon next run, the cache will be read instead of computing a new value to substitute.
import FinDeSiècle, { replace } from 'fin-de-siecle'
let fds = new FinDeSiècle([
{ re: /testing/, async replacement() {
let ls = await this.getLocaleMtime('example/index.js')
let name = 'index'
let { value, ls: cachedLs } = await this.getCache('example', name)
if (!value || cachedLs != ls) {
value = 'cached'
await this.appendCache('example', { [name]: { value, ls } })
}
return value
}}
])
fds.CACHE_DIR = 'example/.cache'
let res = await replace(fds, 'Hello testing World!')
console.log(res)
Hello cached World!
The cache is written in example/.cache/example.json
for the example above, since the CACHE_DIR
was set, and the type of the cache was given as example
. The index
name of the entry is the cache key inside of the example.json
.
{
"index": {
"value": "cached",
"ls": "5/3/2020, 16:13:01"
}
}
GNU Affero General Public License v3.0
Dual licensed under AGPL-3.0 and Art Deco License for Free Open Source packages. If you require a Paid version of Fin-De-Siècle so that you can distribute your software without publishing its source code, please complete a purchase.
© Art Deco™ 2020 |
---|