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

@stanimirovv/tsoogle

v1.6.1

Published

Find functions or methods by approximate signature - return type, argument types or both. Supports optional arguments, rest arguments and partial type checking.

Downloads

5

Readme

Tsoogle - like google, but for your typescript project

Find functions or methods by approximate signature - return type, argument types or both. Supports optional arguments, rest arguments and partial type checking.

Use tsoogle to:

  • find the function you need
  • explore how a datatype is used in your project
# find all that return a string
npx ts-node index.ts testproject.tsconfig.json "string"       
/Users/dot/code/tsoogle/tests/testProject/class.ts:4 bar(a: string,b: string): string
/Users/dot/code/tsoogle/tests/testProject/class.ts:12 asd(a: TestType): string
/Users/dot/code/tsoogle/tests/testProject/functions.ts:1 asd(a: string,b: string): string
/Users/dot/code/tsoogle/tests/testProject/functions.ts:5 asd2(a: string,b: number): string
/Users/dot/code/tsoogle/tests/testProject/functions.ts:9 asd3(): boolean | Record<string, string>

# find all that return a string, have 2 arguments and their first argument is a string
npx ts-node index.ts testproject.tsconfig.json ":string?string,*"
/Users/dot/code/tsoogle/tests/testProject/class.ts:4 bar(string,string): string
/Users/dot/code/tsoogle/tests/testProject/functions.ts:1 asd(string,string): string
/Users/dot/code/tsoogle/tests/testProject/functions.ts:5 asd2(string,number): string

# find all that accept as parametes a string and a number and return anything
npx ts-node index.ts testproject.tsconfig.json "string?string,*" 
/Users/zlatinstanimirov/code/tsoogle/tests/testProject/class.ts:4 bar(a: string,b: string): string

# find all that accept as parameters a string and a number OR string and return anything
 npx ts-node index.ts testproject.tsconfig.json "*?string,number|string" 
/Users/zlatinstanimirov/code/tsoogle/tests/testProject/class.ts:4 bar(a: string,b: string): string
/Users/zlatinstanimirov/code/tsoogle/tests/testProject/class.ts:16 tt1(a: string,b: string[]): TestType

Usage

npm i @stanimirovv/tsoogle
npx tsoogle <path to tsconfig.json> <query>

Or install the vscode plugin - tsoogle.

Query language

Tsoogle has it's own tiny query language that we use to search for functions and methods.

How to query

The simplest query is to match any function or method that returns a string: string

If you want to add the arguments it will look like this: string?string,number - notice the comma, this is how you add multiple arguments. The query above will return all functions that return a string and have 2 arguments. The first one will be a string, the second a number.

If you input a string that has a comma it will search for arguments instead of return type like so: *,* - this will return all functions that accept 2 arguments.

The string you supply for arguments should either match the type name or the name of the argument.

if the first argument is ... then if any of the arguments match the function will be matched. ... can only be used as the first argument and ignore the

Partial type checking

Instead of the name of the argument you can use the following format to match a subtype: {a&b} - matches any type that has as a subtype both a and b. In layman terms both a & b must be present as keys in the type !!! Currently it does not support nesting and works only on object parameter names .

Motivation

Text search is great, but it is not always the best way to find what you are looking for.

Symbol search is great, but it returns all references not just definitions and is relatively stiff. You can't easily find all functions with 2 parameters of type A and B that return C | Promise for example.

This is where tsoogle comes in - it allows to conviniently and fuzzily search for functions and methods by their signature. Tsoogle was inspired by haskell's hoogle.

Contributing

PR's are welcome, but please open an issue first to discuss the change you want to make.

For code to be accepted: 1 It must add a couple of tests for the new functionality 2 It must pass the existing tests 3 There must be no eslint errors

Basically must pass:

npm test && npm run lint