# pathington

> Custom identity functions for composability

Latest version **2.1.1** (published 2026-07-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install pathington
pnpm add pathington
yarn add pathington
bun add pathington
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2026-07-09 |
| First published | 2017-12-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 61.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Tony Quetano |
| Maintainers | planttheidea |
| Keywords | identity, compose |

## Links

- npm: https://www.npmjs.com/package/pathington
- Repository: https://github.com/planttheidea/pathington
- Homepage: https://github.com/planttheidea/pathington#readme
- Issues: https://github.com/planttheidea/pathington/issues
- npm.io page: https://npm.io/package/pathington

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.1.1 (latest) — 2026-07-09
- 2.1.0 — 2025-12-05
- 2.0.2 — 2025-12-03
- 2.0.1 — 2025-12-03
- 2.0.0 — 2025-12-03
- 1.1.7 — 2019-01-21
- 1.1.6 — 2018-12-30
- 1.1.5 — 2017-12-22
- 1.1.4 — 2017-12-20
- 1.1.3 — 2017-12-20
- 1.1.2 — 2017-12-19
- 1.1.1 — 2017-12-19
- 1.1.0 — 2017-12-18
- 1.0.2 — 2017-12-17
- 1.0.1 — 2017-12-17
- … 1 more at https://npm.io/package/pathington/versions

## README

# pathington

Create or parse an object path based on dot or bracket syntax.

## Table of contents

- [Usage](#usage)
- [Methods](#methods)
  - [create](#create)
  - [parse](#parse)
- [Browser support](#browser-support)
- [Development](#development)

## Usage

```javascript
import { create, parse } from 'pathington';

const parsedPath = parse('some[0].deeply["nested path"]');

console.log(parsed); // ['some', 0, 'deeply', 'nested path']

const createdPath = create(['some', 0, 'deeply', 'nested path']);

console.log(createdPath); // 'some[0].deeply["nested path"]'
```

## Methods

### create

`create(path: Array<number|string>, quote?: '"' | "'" | '```'): string`

Create a path string based on the path values passed.

```javascript
console.log(create(['simple'])); // 'simple'
console.log(create(['array', 0])); // 'array[0]'
console.log(create(['array', 0, 'with', 'quoted keys'])); // 'array[0].with["quoted keys"]'
console.log(create(['special', '%characters*'])); // 'special["%charactres*"]'
```

Optionally, you can pass in the quote string to use instead of `"`. Valid values are backtick or single-quote.

```javascript
console.log(create(['quoted keys'], "'")); // ['quoted keys']
```

#### Symbols

You can provide symbols, and a string path will be created from it:

```ts
const symbol = Symbol('foo');
console.log(create(['array', 0, 'with', symbol])); // 'array[0].with[Symbol()]'
```

This can be used in concert with [`parse`](#parse) to extract the values pack:

```ts
const symbol = Symbol('foo');
const path = create(['array', 0, 'with', symbol]);
const parsedPath = parse(path);
console.log(parsedPath.at(-1) === symbol); // true
```

Because symbol values cannot be statically analyzed for their value by TS in the same way that numbers or strings can, a
consistent visual representation is used for all symbols:

```ts
const symbol = Symbol('foo');
const path = create(['array', 0, 'with', symbol]);
console.log(path); // array[0].with[Symbol()]
```

### parse

`parse(path: (Array<number|string>|string)): string`

Parse a path into an array of path values.

```javascript
console.log(parse('simple')); // ['simple']
console.log(parse('dot.notation')); // ['dot', 'notation']
console.log(parse('array[0]')); // ['array', 0]
console.log(parse('array[0].with["quoted keys"]')); // ['array', 0, 'with', 'quoted keys']
console.log(parse('special["%characters*"]')); // ['special', '%characters*']
```

- If a path string is provided, it will be parsed into an array
- If an array is provided, it will be mapped with the keys normalized

#### Symbols

While symbols can be used with this library, `parse` will only recognize them in a string path when that path is created
by [`create`](#create). If you try to manually stringify a symbol, it will identiy that value as a string key when
parsing.

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