Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

@fluffy-spoon/name-of

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Issues
File Explorer

Advanced tools

@fluffy-spoon/name-of

[`@fluffy-spoon/name-of`](https://www.npmjs.com/package/@fluffy-spoon/name-of) makes it possible to get the name of a property at runtime, even if that type does not exist at runtime. Think of it as the `nameof` keyword in C#, but for TypeScript.

    1.4.0latest

Version published
Maintainers
1
Yearly downloads
10,292
increased by346.9%

Weekly downloads

Changelog

Source

v1.4.0

Published automatically by https://github.com/ffMathy/FluffySpoon.Publishers.

@fluffy-spoon/name-of https://www.npmjs.com/package/@fluffy-spoon/name-of/v/1.4.0

Readme

Source

What is this?

@fluffy-spoon/name-of makes it possible to get the name of a property at runtime, even if that type does not exist at runtime. Think of it as the nameof keyword in C#, but for TypeScript.

Installing

npm install @fluffy-spoon/name-of

Usage

import { getPropertyName, getDeepPropertyName } from '@fluffy-spoon/name-of'; interface SomeType { foo: boolean; someNestedObject: { bar: string; } } console.log(getPropertyName<SomeType>(x => x.foo)); //prints "foo" console.log(getPropertyName<SomeType>(x => x.someNestedObject)); //prints "someNestedObject" console.log(getPropertyName<SomeType>(x => x.someNestedObject.bar)); //prints "bar" console.log(getDeepPropertyName<SomeType>(x => x.foo)); //prints "foo" console.log(getDeepPropertyName<SomeType>(x => x.someNestedObject)); //prints "someNestedObject" console.log(getDeepPropertyName<SomeType>(x => x.someNestedObject.bar)); //prints "someNestedObject.bar"
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc