2.0.1 • Published 6 years ago

@dimerapp/utils v2.0.1

Weekly downloads
87
License
MIT
Repository
github
Last release
6 years ago

DimerApp utils

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 string

const { nodeToString } = require('@dimerapp/utils')
nodeToString(node)

Classes

Functions

Paths

Kind: global class

new Paths(basePath, distPath)

Returns paths to certain directories, required by dimer

ParamTypeDefault
basePathString
distPathString'dist'

Permalinks

Kind: global class

new Permalinks()

Generate, normalize and validate permalinks

Validator

Kind: global class

new Validator()

Exposes validation methods to validate different parts of the user input.

configFile() ⇒ String

Returns path to the config file

Kind: global function

docsPath(versionRelativePath) ⇒ String

Returns path for a given version inside the docs folder

Kind: global function

ParamType
versionRelativePathString

distPath() ⇒ String

Returns path to the dist folder

Kind: global function

apiPath() ⇒ String

Returns path to the API folder

Kind: global function

assetsPath() ⇒ String

Returns path to the assets directory

Kind: global function

zonePath(zoneSlug) ⇒ String

Returns path to a given zone directory inside the api folder

Kind: global function

ParamType
zoneSlugString

versionPath(zoneSlug, versioNo) ⇒ String

Returns path to a given version inside the api folder

Kind: global function

ParamType
zoneSlugString
versioNoString

metaFile() ⇒ String

Returns path to the meta file inside the api folder

Kind: global function

searchIndexFile(zoneSlug, versionNo) ⇒ String

Returns path to the search index file inside the api folder

Kind: global function

ParamType
zoneSlugString
versionNoString

docPath(zoneSlug, versionNo, jsonPath) ⇒ String

Returns path to the doc json file

Kind: global function

ParamType
zoneSlugString
versionNoString
jsonPathString

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

Kind: global function

ParamType
filePathString

generateFromFileName(fileName) ⇒ String

Generates the permalink from the base name of a given file

Kind: global function

ParamType
fileNameString

normalize(permalink) ⇒ String

Normalize permalink by removing slashes around it. Must be used when matching two permalinks

Kind: global function

ParamType
permalinkString

validate(permalink) ⇒ void

Validate permalink to ensure the value is URL friendly

Kind: global function

ParamType
permalinkString

isSame(lhs, rhs) ⇒ Boolean

Returns a boolean telling if 2 permalinks are same. They will be normalized before the check

Kind: global function

ParamType
lhsString
rhsString

validateZoneSlug(slug) ⇒ void

Validates the zone slug to make sure it's URL and folder name friendly

Kind: global function
Throws:

  • Error If slug has unallowed chars
ParamType
slugString

validateVersionNumber(no) ⇒ void

Validates the version number to make sure it's URL and folder name friendly

Kind: global function
Throws:

  • Error If version no has unallowed chars
ParamType
noString

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.