MCPcopy
hub / github.com/infinitered/gluegun / exists

Function exists

src/toolbox/patching-tools.ts:12–29  ·  view source on GitHub ↗
(filename: string, findPattern: string | RegExp)

Source from the content-addressed store, hash-verified

10 * @return Boolean of success that findPattern was in file.
11 */
12export async function exists(filename: string, findPattern: string | RegExp): Promise<boolean> {
13 // sanity check the filename
14 if (!is(String, filename) || filesystem.isNotFile(filename)) return false
15
16 // sanity check the findPattern
17 const patternIsString = typeof findPattern === 'string'
18 if (!(findPattern instanceof RegExp) && !patternIsString) return false
19
20 // read from jetpack -- they guard against a lot of the edge
21 // cases and return nil if problematic
22 const contents = filesystem.read(filename)
23
24 // only let the strings pass
25 if (!is(String, contents)) return false
26
27 // do the appropriate check
28 return isPatternIncluded(contents, findPattern)
29}
30
31/**
32 * Updates a text file or json config file. Async.

Callers

nothing calls this directly

Calls 3

isFunction · 0.90
isPatternIncludedFunction · 0.85
isNotFileMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…