# easy-tsnameof

> Typescript nameOf function. Safe types

Latest version **3.1.0** (published 2025-02-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install easy-tsnameof
pnpm add easy-tsnameof
yarn add easy-tsnameof
bun add easy-tsnameof
```

## Health

**Score 50/100 (C)** — status: stable.

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

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2025-02-10 |
| First published | 2020-05-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 53.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Greg Kolens |
| Maintainers | kolengri |
| Keywords | typescript, nameOf |

## Links

- npm: https://www.npmjs.com/package/easy-tsnameof
- Repository: https://github.com/kolengri/easy-tsnameof
- Homepage: https://github.com/kolengri/easy-tsnameof#readme
- Issues: https://github.com/kolengri/easy-tsnameof/issues
- npm.io page: https://npm.io/package/easy-tsnameof

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 3.1.0 (latest) — 2025-02-10
- 3.0.7 — 2025-02-10
- 3.0.6 — 2021-12-30
- 3.0.5 — 2021-12-30
- 3.0.4 — 2021-12-29
- 3.0.3 — 2021-12-29
- 3.0.2 — 2021-12-29
- 3.0.1 — 2021-12-29
- 3.0.0 — 2021-12-29
- 2.1.0 — 2021-12-28
- 2.0.2 — 2021-12-28
- 2.0.1 — 2021-12-28
- 2.0.0 — 2021-12-28
- 1.1.7 — 2021-03-16
- 1.1.6 — 2021-03-16
- … 9 more at https://npm.io/package/easy-tsnameof/versions

## README

# Easy Typescript NameOf

<p>
  <a href="https://www.npmjs.com/package/easy-tsnameof">
    <img height="20px" src="https://badgen.net/npm/license/easy-tsnameof" />
  </a>
  <a href="https://www.npmjs.com/package/easy-tsnameof">
    <img height="20px" src="https://badgen.net/npm/v/easy-tsnameof" />
  </a>
  <a href="https://www.npmjs.com/package/easy-tsnameof">
    <img height="20px" src="https://badgen.net/npm/dependents/easy-tsnameof" />
  </a>
  <a href="https://www.npmjs.com/package/easy-tsnameof">
    <img height="20px" src="https://badgen.net/npm/types/easy-tsnameof" />
  </a>
  <a href="https://github.com/kolengri/easy-tsnameof#readme">
    <img height="20px" src="https://badgen.net/github/issues/kolengri/easy-tsnameof" />
  </a>
  <a href="https://bundlephobia.com/result?p=easy-tsnameof">
    <img height="20px" src="https://badgen.net/bundlephobia/min/easy-tsnameof" />
  </a>
  <a href="https://bundlephobia.com/result?p=easy-tsnameof">
    <img height="20px" src="https://badgen.net/bundlephobia/minzip/easy-tsnameof" />
  </a>
</p>

## Install

```bash
yarn add easy-tsnameof
```

```bash
npm install easy-tsnameof
```

## How to use?

```ts
import nameOf from 'easy-tsnameof';

type NameOfTest = {
  test1: {
    test2: {
      test3: string;
    };
  };
};
nameOf<NameOfTest>((o) => o.test1.test2.test3);
// test1.test2.test3

nameOf<NameOfTest>('test1');
// test1

nameOf<NameOfTest, never>().test1.test2.test3.$path;
// test1.test2.test3
```

## Fabrics

```ts
import { nameOf } from 'easy-tsnameof';

type NameOfTest = {
  test1: {
    test2: {
      test3: string;
    };
  };
};
const f = nameOf<NameOfTest, never>();
f.test1.test2.test3.$path;
// test1.test2.test3
```

## Working with arrays

```ts
import { nameOf } from 'easy-tsnameof';

type NameOfTest = {
  test1: {
    test2: {
      test: string;
    };
    test3: { test4: number }[];
  };
};
const f = nameOf<NameOfTest, never>();
const index = 999;

f.test1.test3[index].test4.$path;
// test1.test3[999].test4
```

## Path access methods

### .$path

Access to path string:

```ts
nameOf<TestType, never>().a.b.c.d.$path;
// "a.b.c.d"
```

[@m-abboud](https://github.com/m-abboud)

### .$rawPath

Access to raw path array

Type: `(string | number | Symbol)[]`

```ts
nameOf<TestType, never>().a.b[5].c.d.$rawPath;
// ["a", "b", 5, "c", "d"]
```

The `$rawPath` is something that you might want to use with the following methods from
Ramda, to add type safety on the path:

- [R.assocPath](https://ramdajs.com/docs/#assocPath),
- [R.dissocPath](https://ramdajs.com/docs/#dissocPath),
- [R.hasPath](https://ramdajs.com/docs/#hasPath),
- [R.path](https://ramdajs.com/docs/#path),
- [R.pathEq](https://ramdajs.com/docs/#pathEq),
- [R.pathOr](https://ramdajs.com/docs/#pathOr),
- [R.paths](https://ramdajs.com/docs/#paths),
- [R.lensPath](https://ramdajs.com/docs/#lensPath)

## Inspired by

- [typed-path](https://github.com/bsalex/typed-path)

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