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

@oussiden/ts-iface-parser

v1.0.2

Published

parses es6 interface files and outputs a single index.ts export file

Downloads

4

Readme

ts-iface-parser

This package parses a TypeScript directory containing interfaces and builds an index.ts export file with all interfaces as exports

Functions


getInterfaceFiles(source: string)


Scans a source directory for files who's names end with _interfaces.ts and returns an array of file names

Params

|Params |Required |Type |Description | |:-------|:----------|:-------|:----------------------------| |srouce | REQUIRED |string | path to interface directory |

Returns

returns an array file names

[
    'test1_interfaces.ts',
    'test2_interfaces.ts',
    'test3_interfaces.ts'
]

parse(path:string, file:string)


Parses a typescript interface file located at ${path}/$file and puts the data into an object

Params

|Params |Required |Type |Description | |:-------|:----------|:--------|:--------------------------------| |path | REQUIRED |string | path to interface directory | |file | REQUIRED |string | name of interface file file.ts|

Returns

returns an object representing all the interfaces found in ${path}

{
  file: './test2_interfaces',
  path: './test/interfaces/test2_interfaces.ts',
  data: [
    { type: 'interface', name: 'test4_iface' },
    { type: 'interface', name: 'test5_iface' },
    { type: 'enum', name: 'test6_enum' }
  ]
}

build(_idx = 0, _imports = "", _export = "", _out = "index.ts", _parsers, _verbose = false)


Creates an index.ts file composed of all the interfaces found and exports them.

Params

|Params |Required |Type |Description | |:-----------|:----------|:--------|:-----------------------------------| |_idx | REQUIRED |number | what parser to start with | |_imports | REQUIRED |string | an empty string | |_export | REQUIRED |string | an empty string | |_out | REQUIRED |string | location where index.ts is written | |_parsers | REQUIRED |array | array of parsers from parse | |_verbose | REQUIRED |boolean | output results to the terminal |

Returns

returns a promise that will eventually write index.ts

Success

{"status": 0, "message": "done parsing", path: _out}

Error

{"status": 1, "message": "could not save index.ts", path: _out}

Unit Tests

Both commands should output an index.ts file in ./test/interfaces

  • Run a command line test
    • npm run test
  • runs unit tests using mocha
    • npm run tests

Usage

Node

|Flags | |Description | |:--------|:----|:-----------------------------------------------------| |--source | -s | location of the interface direcotry | |--out | -o | the path where the resulting index.ts file is stored | |--verbose| -v | output results to the terminal | |--help | -h | describe command line arguments | |--version| | show the package version |

node ./src/index.js -s ./test/interfaces -v

Sdk

const parser = require("./parser.js");

const source = './path/to/interfaces';
const files = parser.getInterfaceFiles(source);
for(const file of files) {
    path = '${source}/${file}';
    parserPromise = parser.parse(path, file);
    parsers.push(parserPromise);
}
parser.build(0, "", "", out, parsers, verbose).then(() => {
    console.log("DONE");
});