# @commodo/name

> Decorates a function (and its instances) with a name, that can be used for various purposes.

Latest version **1.3.1** (published 2020-09-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @commodo/name
pnpm add @commodo/name
yarn add @commodo/name
bun add @commodo/name
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2020-09-01 |
| First published | 2019-04-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 47 |
| Maintainers | commodo-user |
| Keywords | commodo, composeable, models, name |

## Links

- npm: https://www.npmjs.com/package/@commodo/name
- Repository: https://github.com/webiny/commodo
- Homepage: https://github.com/webiny/commodo#readme
- Issues: https://github.com/webiny/commodo/issues
- npm.io page: https://npm.io/package/@commodo/name

## Dependencies (1)

- [repropose](https://npm.io/package/repropose.md) ^1.0.2

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.3.1 (latest) — 2020-09-01
- 1.2.2-beta.20 (beta) — 2020-11-17
- 1.3.1-next.0 (next) — 2020-09-01
- 1.1.1-canary.6 (canary) — 2020-05-10
- 1.2.2-beta.19 — 2020-11-10
- 1.2.2-beta.18 — 2020-11-06
- 1.2.2-beta.17 — 2020-10-12
- 1.2.2-beta.16 — 2020-09-14
- 1.2.2-beta.15 — 2020-09-13
- 1.2.2-beta.14 — 2020-09-12
- 1.2.2-beta.13 — 2020-09-12
- 1.2.2-beta.12 — 2020-09-11
- 1.2.2-beta.11 — 2020-09-08
- 1.2.2-beta.0 — 2020-09-07
- 1.3.0 — 2020-09-01
- … 51 more at https://npm.io/package/@commodo/name/versions

## README

# @commodo/name [![](https://img.shields.io/npm/v/@commodo/name.svg)](https://www.npmjs.com/package/@commodo/name)
Decorates a function (and its instances) with a name, that can be used for various purposes. 

For example, the [`@commodo/fields-storage`](../fields-storage) package relies on the name in order to determine the database table in which the data will be saved.

## Usage

```js
import { withName } from "@commodo/name";
import { compose } from "ramda";

const User = compose(
  withName("User"),
  (...)
)();

const Company = compose(
  withName("Company"),
  (...)
)();
```

You can then use the `hasName` and `getName` functions in order to determine if a name was assigned to the passed value, or to get the actual name that was assigned, respectively.

```js
import { withName, hasName, getName } from "@commodo/name";
import { compose } from "ramda";

// A function with a name assigned.
const User = compose(
  withName("User"),
  (...)
)();

// A function without a name assigned.
const Unknown = compose(
  // Name not assigned.
  // withName("Unknown"), 
  (...)
)();

console.log(hasName(User)); // true
console.log(getName(User)); // "User"

// The Unknown function doesn't have a name assigned.
console.log(hasName(Unknown)); // false
console.log(getName(Unknown)); // ""

// Also works on function instances.
const user = new User();
console.log(hasName(user)); // true
console.log(getName(user)); // "User"

const unknown = new Unknown();
console.log(hasName(unknown)); // false
console.log(getName(unknown)); // ""
```

## Reference

#### `withName(name: string): Function`
Decorates a function (and its instances) with a name.

#### `hasName(value: any): boolean`
Checks if the passed value has a name assigned via the `withName`.

#### `getName(value: any): string`
Returns a name assigned to the passed value. Returns empty string if none assigned.

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