MCPcopy Create free account
hub / github.com/Power-Playground/app / createVFile

Function createVFile

core/src/virtual-files.ts:35–66  ·  view source on GitHub ↗
({ path, contents, data }: CreateVFileProps<C>)

Source from the content-addressed store, hash-verified

33 path: string, contents?: C, data?: Record<string | symbol, unknown>
34}
35export const createVFile = <
36 C extends string | Buffer,
37 IsBuffer extends boolean = C extends Buffer ? true : false
38>({ path, contents, data }: CreateVFileProps<C>) => {
39 const lastDotIndex = path.lastIndexOf('.')
40 return {
41 path,
42 data,
43 contents,
44 get basename() {
45 return path
46 .slice(0, lastDotIndex === -1 ? undefined : lastDotIndex)
47 .slice(path.lastIndexOf('/') + 1)
48 },
49 get filename() {
50 return this.basename + this.extname
51 },
52 get extname() {
53 return lastDotIndex === -1 ? '' : path.slice(lastDotIndex)
54 },
55 get dirname() { return path.slice(0, path.lastIndexOf('/')) },
56 get isLink() {
57 return data?.[VFileLinkPath] != null
58 },
59 get isDirectory() {
60 return contents === undefined
61 },
62 get isBuffer() {
63 return Buffer.isBuffer(this.contents) as IsBuffer
64 }
65 }
66}
67
68export const createSetVFile = (
69 setVFiles: (arg0: (vFiles: VFile[]) => VFile[]) => void

Callers 1

autoCreateParentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected