initial commit
This commit is contained in:
commit
d799808203
126 changed files with 16265 additions and 0 deletions
23
lib/utils/files.ts
Normal file
23
lib/utils/files.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
const pipe =
|
||||
(...fns) =>
|
||||
(x) =>
|
||||
fns.reduce((v, f) => f(v), x)
|
||||
|
||||
const flattenArray = (input) =>
|
||||
input.reduce((acc, item) => [...acc, ...(Array.isArray(item) ? item : [item])], [])
|
||||
|
||||
const map = (fn) => (input) => input.map(fn)
|
||||
|
||||
const walkDir = (fullPath: string) => {
|
||||
return fs.statSync(fullPath).isFile() ? fullPath : getAllFilesRecursively(fullPath)
|
||||
}
|
||||
|
||||
const pathJoinPrefix = (prefix: string) => (extraPath: string) => path.join(prefix, extraPath)
|
||||
|
||||
const getAllFilesRecursively = (folder: string): string[] =>
|
||||
pipe(fs.readdirSync, map(pipe(pathJoinPrefix(folder), walkDir)), flattenArray)(folder)
|
||||
|
||||
export default getAllFilesRecursively
|
14
lib/utils/formatDate.ts
Normal file
14
lib/utils/formatDate.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import siteMetadata from '@/data/siteMetadata'
|
||||
|
||||
const formatDate = (date: string) => {
|
||||
const options: Intl.DateTimeFormatOptions = {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
}
|
||||
const now = new Date(date).toLocaleDateString(siteMetadata.locale, options)
|
||||
|
||||
return now
|
||||
}
|
||||
|
||||
export default formatDate
|
22
lib/utils/htmlEscaper.ts
Normal file
22
lib/utils/htmlEscaper.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
const { replace } = ''
|
||||
|
||||
// escape
|
||||
const ca = /[&<>'"]/g
|
||||
|
||||
const esca = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
"'": ''',
|
||||
'"': '"',
|
||||
}
|
||||
const pe = (m: keyof typeof esca) => esca[m]
|
||||
|
||||
/**
|
||||
* Safely escape HTML entities such as `&`, `<`, `>`, `"`, and `'`.
|
||||
* @param {string} es the input to safely escape
|
||||
* @returns {string} the escaped input, and it **throws** an error if
|
||||
* the input type is unexpected, except for boolean and numbers,
|
||||
* converted as string.
|
||||
*/
|
||||
export const escape = (es: string): string => replace.call(es, ca, pe)
|
5
lib/utils/kebabCase.ts
Normal file
5
lib/utils/kebabCase.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { slug } from 'github-slugger'
|
||||
|
||||
const kebabCase = (str: string) => slug(str)
|
||||
|
||||
export default kebabCase
|
Loading…
Add table
Add a link
Reference in a new issue