1.1.0 • Published 4 years ago
stylelint-formatter-utils v1.1.0
stylelint-formatter-utils
Helpful utilities for building custom stylelint formatters.
Install
npm install stylelint-formatter-utils
Usage
The stylelint-formatter-utils
module has the following exports:
Table
This is a class for outputting tabular data:
const {Table} = require('stylelint-formatter-utils')
const table = new Table({
delimiter: ',',
columns: ['source', 'line']
})
console.log(table.format([
{source: 'x.css', line: 10},
{source: 'y.css', line: 5}
])
// outputs:
// source,line
// x.css,10
// y.css,5
Want to generate a Markdown table? Easy peazy:
const markdown = new Table({
columns: [
{title: 'rule', format: ({rule}) => {
return link(rule, `https://stylelint.io/user-guide/rules/${rule}`)
}},
{title: 'path', format: ({source, line}) => {
return link(`${source}@${line}`, `https://github.com/my/repo/blob/master/${source}#L${line}`)
}}
],
delimiter: ' | ',
beforeLine: '| ',
afterLine: ' |'
})
function link(text, url) {
return `[${text}](${url})`
}
getHeadRef()
Get the git head ref, which is useful for generating links to source code.
const {getHeadRef} = require('stylelint-formatter-utils')
const {repository} = require('./package.json')
const head = getHeadRef()
console.log(`browse this ref: https://github.com/${repository}/tree/${ref}`)
getRepoURL()
Get the repo URL from the git origin remote.
const {getRepoURL} = require('stylelint-formatter-utils')
console.log(`check out this repo: ${getRepoURL()}`)
stripCwd(path[, cwd])
Strip the current working directory from the lefthand side of the input path
.
If cwd
is not provided or empty, we get it from process.cwd()
.
const {stripCwd} = require('stylelint-formatter-utils')
console.log(`this file is: ${stripCwd(__filename)}`)
0.0.0-ba66dd4
4 years ago
0.0.0-a91ddb7
5 years ago
1.1.0
5 years ago
0.0.0-42e14f4
5 years ago
0.0.0-bd2e263
5 years ago
0.0.0-012e16a
5 years ago
0.0.0-1d77675
5 years ago
1.0.0
5 years ago
0.0.0-9776fdf
5 years ago