mirror of
https://github.com/netbirdio/docs.git
synced 2026-04-18 08:26:35 +00:00
add first version of tailwind docs
This commit is contained in:
42
generator/helpers.ts
Normal file
42
generator/helpers.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import * as _ from 'lodash'
|
||||
import * as fs from 'fs'
|
||||
|
||||
export const slugify = (text: string) => {
|
||||
if (!text) return ''
|
||||
return text
|
||||
.toString()
|
||||
.toLowerCase()
|
||||
.replace(/[. )(]/g, '-') // Replace spaces and brackets -
|
||||
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
|
||||
.replace(/\-\-+/g, '-') // Replace multiple - with single -
|
||||
.replace(/^-+/, '') // Trim - from start of text
|
||||
.replace(/-+$/, '') // Trim - from end of text
|
||||
}
|
||||
|
||||
// Uppercase the first letter of a string
|
||||
export const toTitle = (text: string) => {
|
||||
return text.charAt(0).toUpperCase() + text.slice(1)
|
||||
}
|
||||
|
||||
/**
|
||||
* writeToDisk()
|
||||
*/
|
||||
export const writeToDisk = (fileName: string, content: any) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile(fileName, content, (err: any) => {
|
||||
if (err) return reject(err)
|
||||
else return resolve(true)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Object to Array of values
|
||||
*/
|
||||
export const toArrayWithKey = (obj: object, keyAs: string) =>
|
||||
_.values(
|
||||
_.mapValues(obj, (value: any, key: string) => {
|
||||
value[keyAs] = key
|
||||
return value
|
||||
})
|
||||
)
|
||||
Reference in New Issue
Block a user