# typesafe-path

> This library is aim to explicitly annotate path format of the code, and throwing error when passing incorrect format paths.

Latest version **0.2.2** (published 2022-10-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install typesafe-path
pnpm add typesafe-path
yarn add typesafe-path
bun add typesafe-path
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2022-10-11 |
| First published | 2022-10-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Maintainers | johnsoncodehk |

## Links

- npm: https://www.npmjs.com/package/typesafe-path
- Repository: https://github.com/johnsoncodehk/typesafe-path
- Homepage: https://github.com/johnsoncodehk/typesafe-path#readme
- Issues: https://github.com/johnsoncodehk/typesafe-path/issues
- npm.io page: https://npm.io/package/typesafe-path

## Recent versions

- 0.2.2 (latest) — 2022-10-11
- 0.2.1 — 2022-10-04
- 0.2.0 — 2022-10-01
- 0.1.0 — 2022-10-01

## README

# TypeSafe Path

This library is aim to explicitly annotate path format of the code, and throwing error when passing incorrect format paths.

The advantage is that we can avoid using `upath` to convert all paths to unix path, and ensure current code logic always correctly know the path format that should be processed.

Please note that you should only use it in your modules that are coupled to the filesystem.

## Usage

```ts
import * as path from 'typesafe-path';

/**
 * win32: __dirname is 'c:\\foo\\bar.js'
 * posix: __dirname is '/foo/bar.js'
 */
const osPath = __dirname as path.OsPath;
const win32Path = '..\\aaa\\bbb' as path.Win32Path;

/**
 * win32: 'c:\\foo\\aaa\\bbb' <-- good result
 * posix: '/foo/bar.js/..\\aaa\\bbb' <-- bad result
 */
path.resolve(osPath, win32Path);
//                   ^ Argument of type 'Win32Path' is not assignable to parameter of type 'OsPath | PosixPath'.

// Fixs
const posixPath = win32Path.replace(/\\/g, '/') as path.PosixPath;
path.resolve(osPath, posixPath); // no type error
```

---
_Source: https://npm.io/package/typesafe-path · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
