An open API service indexing awesome lists of open source software.

https://github.com/tseijp/parsed-path

Use the best bits of ES6 to parse your path without stress πŸ‘‹
https://github.com/tseijp/parsed-path

dir directory file filepath filesystem nodejs parse path reactjs stat typescript

Last synced: 3 months ago
JSON representation

Use the best bits of ES6 to parse your path without stress πŸ‘‹

Awesome Lists containing this project

README

          

# πŸ‘‹parsed-path



```ruby
< πŸ‘‹ >
parsed
path
```




Use the best bits of ES6 to parse your path without stress πŸ‘‹

[![ version ](
https://img.shields.io/npm/v/parsed-path)](
https://npmjs.com/package/parsed-path)
[![ Downloads ](
https://img.shields.io/npm/dm/parsed-path.svg)](
https://npmjs.com/package/parsed-path)
[![ jsDelivr ](
https://badgen.net/jsdelivr/hits/npm/parsed-path)](
https://www.jsdelivr.com/package/npm/parsed-path)
[![ minified size ](
https://badgen.net/bundlephobia/minzip/parsed-path)](
https://bundlephobia.com/result?p=parsed-path@latest)
[![ types includes ](
https://badgen.net/npm/types/parsed-path)](
https://www.npmjs.com/package/parsed-path)
[![ license ](
https://badgen.net/npm/license/parsed-path)](
https://www.npmjs.com/package/parsed-path)
[![ module formats ](
https://img.shields.io/badge/module%20formats-cjs%20esm-green.svg)](
#installation)
[![ codecov ](
https://codecov.io/gh/tseijp/parsed-path/coverage.svg?branch=master)](
https://codecov.io/gh/tseijp/parsed-path)
[![ style: styled-components ](
https://img.shields.io/badge/style-%F0%9F%92%85%20styled--components-orange.svg?colorB=daa357&colorA=db748e)](
https://github.com/styled-components/styled-components)




## Installation

```ruby
npm install parsed-path or yarn add parsed-path
```

## Documentation and Examples

See the documentation for more information about `parsed-path`.

More info about the project can be found here: **[Tutorial Intro][intro]**

Quicklinks to some of the most-visited pages: **[Getting started][get]**

Examples and tutorials can be found here: **[API Reference][api]**



## What does it look like?

Utilising tagged template literals (a recent addition to JavaScript),
parsed-path allows you to write pathname.
This two example creates simple pathname.
a Root and a File, with some parsed form to it:

```js
import parsed from 'parsed-path';

const Root = parsed`/`;

const Path = Root`home``user``dir`;
```

You can pass a function to a template literal to adapt it based on its props.
When setting the back prop to true, we are moving to its parent dir.

```js
const Back = Path`
${(props: any) => props.back && '..'}
`;
```

`Parsed-path` tagged pathform to parse your pathname.
It also removes the mapping between pathname and pathform
– using path as a low-level parsing construct could not be easier!

```js
const File = Back`ignore.ts``
name: file;
ext: ${(props: any) => props.xml && '.tsx'};
`;
```

```jsx
to equal /home/user/file.ts
to equal /home/user/dir/file.tsx
```

`Parsed-path` uses **[node][node]** module for parsing the path rules.
For additional information about the supported prefixes visit their **[docs][docs]**.

```js
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ dir β”‚ base β”‚
β”œβ”€β”€β”€β”€β”€β”€β”¬ β”œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€
β”‚ root β”‚ β”‚ name β”‚ ext β”‚
parsed` /``home``user``dir``file``.tsx `
parsed` C:\\`` path``dir``file``.tsx `
β””β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”˜
```

This is a **[live editor][live]**,
so play around with the code to get a feel for
what it's like to work with `parsed-path`!

[intro]: https://tseijp.github.io/parsed-path/docs/intro
[get]: https://tseijp.github.io/parsed-path/docs/get
[api]: https://tseijp.github.io/parsed-path/docs/api
[live]: https://codesandbox.io/s/parsed-path-x66qy
[node]: https://github.com/nodejs/node/blob/master/lib/path.js
[docs]: https://nodejs.org/docs/latest/api/path.html#path_path_parse_path