<img width="500" src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1532274184/Dimer_Readme_Banner_lyy7wv.svg" alt="Dimer App">
<a href="https://dimerapp.com/what-is-dimer">
Dimer is an open source project and CMS to help you publish your documentation online.
</a>
<sub>We believe every project/product is incomplete without documentation. <br /> We want to help you publish user facing documentation, without worrying <code>about tools or code</code> to write.</sub>
Handy utilities to keep all other repos DRY and consistent
The utils library provides a handful of methods to be used across multiple dimer repos.
Installation
npm i @dimerapp/utils
# Yarn
yarn add @dimerapp/utils
Usage
const utils = require('@dimerapp/utils')
const basePath = __dirname
const distPath = 'dist' // optional
const paths = utils.paths(basePath, distPath)
const permalink = utils.permalink
const validator = utils.validator
nodeToString(node)
Convert Dimer content JSON node to a plain stringconst { nodeToString } = require('@dimerapp/utils')
nodeToString(node)
Classes
Functions
- configFile() ⇒
String
Returns path to the config file
- docsPath(versionRelativePath) ⇒
String
Returns path for a given version inside the docs folder
- distPath() ⇒
String
Returns path to the dist folder
- apiPath() ⇒
String
Returns path to the API folder
- assetsPath() ⇒
String
Returns path to the assets directory
- zonePath(zoneSlug) ⇒
String
Returns path to a given zone directory inside the api folder
- versionPath(zoneSlug, versioNo) ⇒
String
Returns path to a given version inside the api folder
- metaFile() ⇒
String
Returns path to the meta file inside the api folder
- searchIndexFile(zoneSlug, versionNo) ⇒
String
Returns path to the search index file inside the api folder
- docPath(zoneSlug, versionNo, jsonPath) ⇒
String
Returns path to the doc json file
- makeJsonPath(filePath) ⇒
String
Makes the json path from the doc file path. Also it makes sure to keep the slashes consistent for deployment on unix systems
- generateFromFileName(fileName) ⇒
String
Generates the permalink from the base name of a given file
- normalize(permalink) ⇒
String
Normalize permalink by removing slashes around it. Must be used when matching two permalinks
- validate(permalink) ⇒
void
Validate permalink to ensure the value is URL friendly
- isSame(lhs, rhs) ⇒
Boolean
Returns a boolean telling if 2 permalinks are same. They will be normalized before the check
- validateZoneSlug(slug) ⇒
void
Validates the zone slug to make sure it's URL and folder name friendly
- validateVersionNumber(no) ⇒
void
Validates the version number to make sure it's URL and folder name friendly
Paths
Kind: global classnew Paths(basePath, distPath)
Returns paths to certain directories, required by dimer| Param | Type | Default | | --- | --- | --- | | basePath |
String
| |
| distPath | String
| 'dist'
| Permalinks
Kind: global classnew Permalinks()
Generate, normalize and validate permalinksValidator
Kind: global classnew Validator()
Exposes validation methods to validate different parts of the user input.configFile() ⇒ String
Returns path to the config fileKind: global function
docsPath(versionRelativePath) ⇒ String
Returns path for a given version inside the docs folderKind: global function
| Param | Type | | --- | --- | | versionRelativePath |
String
| distPath() ⇒ String
Returns path to the dist folderKind: global function
apiPath() ⇒ String
Returns path to the API folderKind: global function
assetsPath() ⇒ String
Returns path to the assets directoryKind: global function
zonePath(zoneSlug) ⇒ String
Returns path to a given zone directory inside the api folderKind: global function
| Param | Type | | --- | --- | | zoneSlug |
String
| versionPath(zoneSlug, versioNo) ⇒ String
Returns path to a given version inside the api folderKind: global function
| Param | Type | | --- | --- | | zoneSlug |
String
|
| versioNo | String
| metaFile() ⇒ String
Returns path to the meta file inside the api folderKind: global function
searchIndexFile(zoneSlug, versionNo) ⇒ String
Returns path to the search index file inside the api
folderKind: global function
| Param | Type | | --- | --- | | zoneSlug |
String
|
| versionNo | String
| docPath(zoneSlug, versionNo, jsonPath) ⇒ String
Returns path to the doc json fileKind: global function
| Param | Type | | --- | --- | | zoneSlug |
String
|
| versionNo | String
|
| jsonPath | String
| makeJsonPath(filePath) ⇒ String
Makes the json path from the doc file path. Also it makes sure to
keep the slashes consistent for deployment on unix systemsKind: global function
| Param | Type | | --- | --- | | filePath |
String
| generateFromFileName(fileName) ⇒ String
Generates the permalink from the base name of a given
fileKind: global function
| Param | Type | | --- | --- | | fileName |
String
| normalize(permalink) ⇒ String
Normalize permalink by removing slashes around it. Must be
used when matching two permalinksKind: global function
| Param | Type | | --- | --- | | permalink |
String
| validate(permalink) ⇒ void
Validate permalink to ensure the value is URL
friendlyKind: global function
| Param | Type | | --- | --- | | permalink |
String
| isSame(lhs, rhs) ⇒ Boolean
Returns a boolean telling if 2 permalinks are same. They will
be normalized before the checkKind: global function
| Param | Type | | --- | --- | | lhs |
String
|
| rhs | String
| validateZoneSlug(slug) ⇒ void
Validates the zone slug to make sure it's URL and folder
name friendlyKind: global function
Throws:
Error
If slug has unallowed chars
| Param | Type | | --- | --- | | slug |
String
| validateVersionNumber(no) ⇒ void
Validates the version number to make sure it's URL and folder
name friendlyKind: global function
Throws:
Error
If version no has unallowed chars
| Param | Type | | --- | --- | | no |
String
| Change log
The change log can be found in the CHANGELOG.md file.Contributing
Everyone is welcome to contribute. Please take a moment to review the contributing guidelines.Authors & License
thetutlage and contributors.MIT License, see the included MIT file.