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

@aws/fully-qualified-names

v2.1.4

Published

For extracting def use statements from code.

Downloads

106,328

Readme

Fully Qualified Names

A name cannot be dissected any further by means of a definition: it is a primitive sign -- Ludwig Wittgenstein

Powered by tree-sitter, fully-qualified-names lets you extract simple and fully qualified names from code written in JavaScript, TypeScript, Python or Java. Those names are further split into declarations and usages which provides a convenient simplification of more complex ASTs for static analysis.

How to use

The package offers a Rust and a JS API, the latter based on WASM. To get names from a Python code snippet in Rust you would use something like the following.

use fully-qualified-names::Python;

let code = r#"class Person:
  def __init__(self, name):
    self.name = name

  def hello(self):
    return f"Hello, {self.name}"
"#;

let names = Python::find_names(code).unwrap();
println!("{names:?}");

The same in JS would look as follows.

import { Python } from '@aws/fully-qualified-names';

const code = `class Person:
  def __init__(self, name):
    self.name = name

  def hello(self):
    return f"Hello, {self.name}"
`;

const names = await Python.findNames(code);
console.log(JSON.stringify(names));

Background

In programming, identifers are used to refer to values, types and code passages.

Names

Those all have simple names which are context-specific, and fully qualified names (subsequently abbreviated as FQNs), which are unambiguous and unique across projects.

Take e.g. the following Rust code snippet.

let list = std::vec::Vec::new();

Here we have several simple names (list, std, vec, Vec, new), which include variable (list), module (std, vec), type (Vec) and method (new) names.

All of those have FQNs as well, the new method's FQN is explicitly stated as std::vec::Vec::new, the list variable's FQN can only be determined with knowledge of the surrounding package and module structure.

Declaration -- Usage

The names introduced above can be furthermore be separated into declarations (list) and usages (std::vec::Vec::new)

Declaration: A declaration is a statement which introduces a name into a scope.

Value Usage: A symbol name is used in an expression which requires evaluating (i.e. looking up) the symbol’s definition.

Type Usage: A type name is used by the compiler in a left-hand-side context to

  • ensure a value in a right-right-hand side context has the required type
  • avoid type propagation/inference across scopes

Security

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.