npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@leyyo/fqn

v1.1.1

Published

FQN (Fully Qualified Name) for JavaScript/TypeScript

Downloads

11

Readme

fqn

FQN (Fully Qualified Name) for JavaScript/TypeScript

Leyyo > FQN

  • FQN (Fully Qualified Name) for JavaScript/TypeScript
  • Provides decorator for only class, because module, namespace and functions are not allowed for decorators
  • Support Class, Function, Namespace, Module and File
  • Support to prevent to rename names of function while binding
  • It ignores getter and setter properties

Install

npm i @leyyo/fqn

Standards

  • Language: TS
  • Eslint: Yes
  • Static Code Analysis: Yes IntelliJ Code Inspections
  • DDD - Document Driven: No
  • EDD - Exception Driven: Yes
  • TDD - Test Driven: Yes go to test folder

Commands

  • npm run clear // clears "dist" folder
  • npm run lint // runs eslint for static code analysis
  • npm run build // builds JS files at "dist" folder
  • npm run test // runs test files in "test" folder
  • npm run test:watch *// runs test with watch option
  • npm run test:coverage *// runs test with coverage

Todo

  • Overwrite Function.name
  • Define keyword (static, instance, class, function, constructor, module/namespace) etc

Usage

Interface

export interface Fqn {
    /**
     * Patches given object (function, class, file, ...)
     * */
    patch(targets: Record<string, any>, ...prefixes: Array<string>): void;
    /**
     * Patches given object (module, namespace)
     * */
    patchModule(targets: Record<string, any>, depth?: number, ...prefixes: Array<string>): void;

    /**
     * Returns fqn key
     * */
    get key(): string;

    /**
     * Returns fqn of given value
     * */
    get(value: unknown): string | undefined;

    /**
     * Binds given function with saving fqn
     * */
    fnBind<T extends FuncAny>(fn: T, holder: unknown): T;

    /**
     * Binds given functions with saving fqn
     * */
    fnBindAll(holder: unknown, ...functions: Array<FuncAny>): void;
}

Decorator

import {fqn} from "@leyyo/fqn";

@Fqn('test')
class SampleClass {
    static staticMethod() {}
    instanceMethod() {}
}

console.log(fqn.get(SampleClass)); // test.SampleClass
console.log(fqn.get(SampleClass.staticMethod)); // test.SampleClass.staticMethod

const instance = new SampleClass();
console.log(fqn.get(instance)); // test.SampleClass
console.log(fqn.get(instance.instanceMethod)); // test.SampleClass.instanceMethod

Classes and Functions

import {fqn} from "@leyyo/fqn";

export class MyClass {}
export function myFunction() {}
export const myArrow = () => {}
// patch({...}, ...names: string[]);
fqn.patch({MyClass, MyFunction, myArrow}, 'company', 'project');

console.log(fqn.get(MyClass)); // company.project.MyClass
console.log(fqn.get(myFunction)); // company.project.myFunction
console.log(fqn.get(myArrow)); // company.project.myArrow
console.log(fqn.get(new MyClass())); // company.project.MyClass
console.log(fqn.get(new myFunction())); // company.project.myFunction

Module

import {fqn} from "@leyyo/fqn";

export module mammal {
    export abstract class Base {
        static drink(): void {
        }
    }

    export class Cat extends Base {
        meow(): void {
        }

        static drink(): void {
        }
    }

    export class Dog extends Base {
        woof(): void {
        }
    }

    export function hello() {
    }

    export const world = () => {
    }
}
fqn.patchModule({mammal}, 1, 'animal');

// in other files or projects
const cat = new mammal.Cat();
const dog = new mammal.Dog();

console.log(fqn.get(mammal)); // animal.mammal
console.log(fqn.get(mammal.Base)); // animal.mammal.Base
console.log(fqn.get(mammal.Base.drink)); // animal.mammal.Base.drink
console.log(fqn.get(mammal.Cat)); // animal.mammal.Cat
console.log(fqn.get(mammal.Cat.drink)); // animal.mammal.Cat.drink ## overriden
console.log(fqn.get(cat.meow)); // animal.mammal.Cat.meow
console.log(fqn.get(mammal.Dog)); // animal.mammal.Dog
console.log(fqn.get(mammal.Dog.drink)); // animal.mammal.Base.drink ## inherited
console.log(fqn.get(dog.woof)); // animal.mammal.Dog.woof

Namespaces

import {fqn} from "@leyyo/fqn";

export namespace iam {
    export abstract class User {
        static add(): void {}
    }
    export namespace visitor {
        export class User extends iam.User {
            static visitPage(): void {}
        }
        export function hello() {}
    }
    export namespace admin {
        export class User extends iam.User {
            static getRoles(): void {}
        }
        export function hello() {}
    }
}
fqn.patchModule({iam}); // there is no any prefix

// in other files or projects
console.log(fqn.get(iam)); // iam
console.log(fqn.get(iam.User)); // iam.User
console.log(fqn.get(iam.User.add)); // iam.User.add
console.log(fqn.get(iam.visitor)); // iam.visitor
console.log(fqn.get(iam.visitor.User)); // iam.visitor.User
console.log(fqn.get(iam.visitor.User.add)); // iam.User.add // ## inherited
console.log(fqn.get(iam.visitor.User.visitPage)); // iam.visitor.User.visitPage
console.log(fqn.get(iam.visitor.hello)); // iam.visitor.hello
console.log(fqn.get(iam.admin)); // iam.admin
console.log(fqn.get(iam.admin.User)); // iam.admin.User
console.log(fqn.get(iam.admin.User.add)); // iam.User.add // ## inherited
console.log(fqn.get(iam.admin.User.getRoles)); // iam.admin.User.getRoles
console.log(fqn.get(iam.admin.hello)); // iam.admin.hello

All in a file

import {fqn} from "@leyyo/fqn";

export class Cat {
    static meow(): void {}
    drink(): void {}
}
export function hello() {}
export const world = () => {}
// with custom prefix
fqn.patch(this, 'myUtils');

// in other files or projects
console.log(fqn.get(Cat)); // myUtils.Cat
console.log(fqn.get(Cat.meow)); // myUtils.Cat.meow
console.log(fqn.get((new Cat()).drink)); // myUtils.Cat.drink
console.log(fqn.get(hello)); // myUtils.hello
console.log(fqn.get(world)); // myUtils.world
console.log(fqn.get(new hello())); // myUtils.hello

Author