mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 17:30:25 -04:00
33b9e1ed29
Scripts currently use CJS, which is causing a bit of a mess when trying to use shared utilities from the app. Converting everything to ESM so there are fewer conflicts when adding new scripts going forward.
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import * as fs from 'fs'
|
|
import { mapValues, values } from 'lodash-es'
|
|
|
|
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
|
|
})
|
|
)
|