JSPM

@igor.dvlpr/my-file-path

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q12985F
  • License MIT

๐ŸŒŸ An npm module that strongly types file paths! ๐ŸฅŠ

Package Exports

  • @igor.dvlpr/my-file-path
  • @igor.dvlpr/my-file-path/dist/index.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@igor.dvlpr/my-file-path) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

My file path

๐ŸŒŸ An npm module that strongly types file paths! ๐ŸฅŠ



๐Ÿ’– Support further development

I work hard for every project, including this one and your support means a lot to me!
Consider buying me a coffee. โ˜•
Thank you for supporting my efforts! ๐Ÿ™๐Ÿ˜Š


Donate to igorskyflyer

@igorskyflyer



๐Ÿ•ต๐Ÿผ Usage

Install it by executing:

npm i "@igor.dvlpr/my-file-path"

๐Ÿคน๐Ÿผ API

The module exposes a generic type and 3 generic functions.

Type

type FilePath<ext extends string>

Use this type for compile-time safety.


index.ts

type JsonFile = FilePath<'json'>

const filePathJson: JsonFile = 'abc.json' // works in the IDE
const filePathTxt: JsonFile = 'abc.txt' // will not work in the IDE

Functions


isMyFilePath

function isMyFilePath<Ext extends string>(
  filePath: string,
  extension: Ext
): boolean

Checks whether the provided filepath conforms with the provided file extension.


Generic parameter:

Ext - the file extension to use with the generic, without a leading dot.


Function parameters:

filePath - the filepath to check. extension - the file extension to perform the check with.


Will not throw. Returns a boolean.


createMyFilePath

function createMyFilePath<Ext extends string>(
  filePath: string,
  extension: Ext
): FilePath<Ext>

Checks whether the provided filepath conforms with the provided file extension and returns it if true. Otherwise it returns an empty string.


Generic parameter:

Ext - the file extension to use with the generic, without a leading dot.


Function parameters:

filePath - the filepath to check. extension - the file extension to perform the check with.


Will not throw. Returns a FilePath<Ext>.


assertMyFilePath

function assertMyFilePath<Ext extends string>(
  filePath: string,
  extension: Ext,
  errorMessage?: string
): void

Asserts whether the provided filepath conforms with the provided file extension.


Generic parameter:

Ext - the file extension to use with the generic, without a leading dot.


Function parameters:

filePath - the filepath to check. extension - the file extension to perform the check with. errorMessage - the error message to throw.


Will throw if the filepath doesn't conform the provided extension. Returns a void.

๐Ÿชช License

Licensed under the MIT license which is available here, MIT license.


uPath

๐ŸŽ Provides a universal way of formatting file-paths in Unix-like and Windows operating systems as an alternative to the built-in path.normalize(). ๐Ÿงฌ

pathexists

๐Ÿงฒ Provides ways of properly checking if a path exists inside a given array of files/directories both on Windows and UNIX-like operating systems. ๐Ÿ—บ

valid-path

๐Ÿงฐ Provides ways of testing whether a given value can be a valid file/directory name. ๐Ÿœ

Zep

๐Ÿง  Zep is a zero-dependency, efficient debounce module. โฐ

Odin

๐Ÿ”ฑ Odin is an Object wrapper that allows you to create objects and set their attributes - all at once! ๐Ÿ”บ