mirror of
https://github.com/supabase/supabase.git
synced 2026-06-20 15:26:07 +08:00
* Move the spec/parser package into packages folder. * Fix the spec generation with the new paths. * Remove the spec folder from prettierignore. * Run prettier on the spec folder (without regenerating, that's should be done by the product teams).
42 lines
1.0 KiB
TypeScript
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
|
|
})
|
|
)
|