Files
supabase/apps/reference/generator/helpers.ts
Copple e486815ab0 Docs: hide generated (#9078)
* removes all generated files

* ignore all generated files

* moves the docs generator into docusaurus

* clean up old files from the generator

* generator -> parser

* Adds the latest spec

* fixing generated path

* updates specs

* delete generated files

* keep the generated folder

* keep generated folder

* Adds a dart generator

* Addds new auth doc for Dart v1

* Adds postgrest method in Dart doc

* Adds realtime docs to Dart v1

* Adds storage docs to Dart doc

* Adds filters and modifiers to Dart docs spec file

* fix: label used in dart sidebar to match spec file for Dart docs

* final items for generator

* Adds a build command

* Adds typescript

* fix broken links

* fix build

* fix import error

* lowercase helpers

* clean missing file

Co-authored-by: dshukertjr <18113850+dshukertjr@users.noreply.github.com>
2022-09-23 11:40:07 +02:00

42 lines
1.0 KiB
TypeScript

import * as _ from 'lodash'
import * as fs from 'fs'
export const slugify = (text: string) => {
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
})
)