1.3.1 • Published 3 years ago

@commodo/name v1.3.1

Weekly downloads
431
License
MIT
Repository
github
Last release
3 years ago

@commodo/name npm.io

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

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

Usage

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.

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.

1.2.2-beta.20

3 years ago

1.2.2-beta.19

3 years ago

1.2.2-beta.18

3 years ago

1.2.2-beta.17

4 years ago

1.2.2-beta.16

4 years ago

1.2.2-beta.15

4 years ago

1.2.2-beta.14

4 years ago

1.2.2-beta.13

4 years ago

1.2.2-beta.12

4 years ago

1.2.2-beta.11

4 years ago

1.2.2-beta.0

4 years ago

1.3.0-next.3

4 years ago

1.3.1-next.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.3.0-next.2

4 years ago

1.3.0-next.1

4 years ago

1.3.0-next.0

4 years ago

1.2.2-next.6

4 years ago

1.2.2-next.5

4 years ago

1.2.2-next.4

4 years ago

1.2.2-next.3

4 years ago

1.2.2-next.2

4 years ago

1.2.2-next.1

4 years ago

1.2.2-next.0

4 years ago

1.2.1

4 years ago

1.2.1-next.0

4 years ago

1.2.0-next.18

4 years ago

1.2.0-next.17

4 years ago

1.2.0

4 years ago

1.2.0-next.15

4 years ago

1.2.0-next.16

4 years ago

1.2.0-next.13

4 years ago

1.2.0-next.14

4 years ago

1.2.0-next.11

4 years ago

1.2.0-next.12

4 years ago

1.2.0-next.10

4 years ago

1.2.0-next.9

4 years ago

1.2.0-next.8

4 years ago

1.2.0-next.2

4 years ago

1.2.0-next.3

4 years ago

1.2.0-next.1

4 years ago

1.2.0-next.0

4 years ago

1.1.1-next.12

4 years ago

1.1.1-next.11

4 years ago

1.1.1-next.10

4 years ago

1.1.1-next.9

4 years ago

1.1.1-next.8

4 years ago

1.1.1-next.7

4 years ago

1.1.1-canary.6

4 years ago

1.1.1-canary.5

4 years ago

1.1.1-canary.4

4 years ago

1.1.1-next.0

4 years ago

1.1.0

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago