mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
refactor: strictly typed
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
||||
import { last } from '../util/underscore'
|
||||
import IFS from './ifs'
|
||||
|
||||
function domResolve (root, path) {
|
||||
function domResolve (root: string, path: string) {
|
||||
const base = document.createElement('base')
|
||||
base.href = root
|
||||
|
||||
@@ -16,7 +16,7 @@ function domResolve (root, path) {
|
||||
return resolved
|
||||
}
|
||||
|
||||
function resolve (root, filepath, ext) {
|
||||
function resolve (root: string, filepath: string, ext: string) {
|
||||
if (root.length && last(root) !== '/') root += '/'
|
||||
const url = domResolve(root, filepath)
|
||||
return url.replace(/^(\w+:\/\/[^/]+)(\/[^?]+)/, (str, origin, path) => {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
export default interface IFS {
|
||||
exists: (filepath?: string) => Promise<boolean>
|
||||
exists: (filepath: string) => Promise<boolean>
|
||||
readFile: (filepath:string) => Promise<string>
|
||||
resolve: (root: string, file: string, ext: string) => string
|
||||
}
|
||||
|
||||
+3
-3
@@ -3,11 +3,11 @@ import { resolve, extname } from 'path'
|
||||
import { stat, readFile } from 'fs'
|
||||
import IFS from './ifs'
|
||||
|
||||
const statAsync = _.promisify(stat) as (filepath: string) => Promise<object>
|
||||
const readFileAsync = _.promisify(readFile) as (filepath: string, encoding: string) => Promise<string>
|
||||
const statAsync = _.promisify(stat)
|
||||
const readFileAsync = _.promisify<string, string, string>(readFile)
|
||||
|
||||
const fs: IFS = {
|
||||
exists: filepath => {
|
||||
exists: (filepath: string) => {
|
||||
return statAsync(filepath).then(() => true).catch(() => false)
|
||||
},
|
||||
readFile: filepath => {
|
||||
|
||||
Reference in New Issue
Block a user