Skip to content

Commit

Permalink
- add missing type annotations to functions and missing doc comments,…
Browse files Browse the repository at this point in the history
… so that the jsr score is boosted to 100%.

- ready for publishing version `0.1.0`.
  • Loading branch information
omar-azmi committed Nov 28, 2024
1 parent 48da7f3 commit 781c81c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { console_log, ensureEndSlash, pathToPosixPath, promise_all, resolvePathF


/** get the current working directory (`Deno.cwd`) in posix path format. */
export const getCwdPath = () => { return ensureEndSlash(pathToPosixPath(Deno.cwd())) }
export const getCwdPath = (): string => { return ensureEndSlash(pathToPosixPath(Deno.cwd())) }

/** resolve a file path so that it becomes absolute, with unix directory separator ("/").
* TODO: refactor the name `pathResolve` to `resolvePath`
*/
export const pathResolve = resolvePathFactory(getCwdPath)
export const pathResolve: ((...segments: string[]) => string) = resolvePathFactory(getCwdPath)

/** the tuple description of a writable (or appendable) file.
* - the first entry of the array must describe the destination path of the file,
Expand Down Expand Up @@ -98,6 +98,7 @@ export const createFiles = async (virtual_files: Array<WritableFileConfig>, conf
}))
}

/** write `esbuild` output files (`BuildResult.outputFiles`) to the filesystem. */
export const writeOutputFiles = async (virtual_files: Array<EsbuildOutputFile>, config: CreateFilesConfig = {}): Promise<void> => {
return createFiles(virtual_files.map((virtual_file): WritableFileConfig => {
const
Expand Down
13 changes: 12 additions & 1 deletion src/funcdefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ import { math_min } from "./deps.ts"

const escape_regex_chars_regex = /[.*+?^${}()|[\]\\]/g

export const escapeStringForRegex = (str: string) => (str.replaceAll(escape_regex_chars_regex, "\\$&"))
/** escape a string so that it can be matched exactly in a regex constructor.
*
* @example
* ```ts
* const
* substring = "(++h.e.l.l.o++)",
* my_regex = new RegExp(`${substring}\(world\)`),
* my_str = "this string consist of (++h.e.l.l.o++)(world) positioned somewhere in the middle"
* console.assert(my_regex.test(my_str) === true)
* ```
*/
export const escapeStringForRegex = (str: string): string => (str.replaceAll(escape_regex_chars_regex, "\\$&"))

/** create a mapping function that operates on a list or array inputs that are zipped together as tuples. */
export const zipArraysMapperFactory = <T extends Array<any>, V>(
Expand Down
9 changes: 9 additions & 0 deletions src/typedefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ export interface GenericLoaderConfig {
mode?: "bundle" | "inject" | "inject-link"
}

/** an interface that describes the dependencies and contents of a single file that is parsed by your loader's {@link GenericLoader.extractDeps} method. */
export interface ContentDependencies<K = string> {
/** an ordered list of unique json-encodable key assigned for each dependency path. */
importKeys: Array<K>
/** an ordered list of dependency paths that your file requires for bundling. */
importPaths: Array<string>
/** the contents of your loaded file, further transformed to replace the {@link importPaths | import-paths}
* with {@link importKeys | unique-keys} that are easily identifiable and replaceable later on.
*/
content: string
}

/** an interface similar to {@link ContentDependencies}, but with its {@link content} now containing javascript code that can be dynamically imported. */
export interface ScriptWrappedContent<K = string> extends ContentDependencies<K> {
content: string
}

/** an entry in {@link GenericLoader.meta["imports"]} that specifies the transformation of a dependency path, after the unparsing is complete.
*
* @typeParam K the key `K` must be a json encodable key
Expand All @@ -49,4 +57,5 @@ export interface ImportMetadataEntry<K = string> {
out: string
}

/** an array of metadata entries {@link ImportMetadataEntry}. */
export type ImportMetadata<K = string> = Array<ImportMetadataEntry<K>>

0 comments on commit 781c81c

Please sign in to comment.