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

tsdlocal

v0.1.6

Published

Rewrite .d.ts definitions as local modules.

Downloads

1

Readme

tsdlocal

Transform .d.ts files to look like local modules. Then rewrite your output javascript file to use actual require() statements. All this without using --module in tsc.

Usage

To generate a definition:

tsdlocal in.d.ts out.local.d.ts

To process code that uses local definitions.

tsdlocal --parsejs in.js out.js

For example for using the require("path"), you would need to write:

/// <reference path="/typings/node/node.local.d.ts"/>
import path = __require__path; // require("path")

Grunt Parsing

Grunt support is embedded. In order to parse your outputed sources as part of the build, you just need to add it:

/**
 * Grunt project configuration.
 */
module.exports = function(grunt) {
    // configuration for the plugins.
    grunt.initConfig({
        tsdlocal : {
            dist : {
                files : [
                    {
                        expand: true,
                        cwd: 'dest/',
                        src: ['**/*.js'],
                        dest: 'dest/'
                    }
                ]
            }
        }
    });
    // load NPM tasks:
    grunt.loadNpmTasks('tsdlocal');
    // register our task:
    grunt.registerTask('default', ['tsdlocal']);
};

Using the same source and destination works, since the task will first read the file, then process it, and only after rewriting it. This is equivalent with running tsdlocal --parsejs for each js file.

Local definitions generation

If you want to generate namespace definitions from some module definitions, you can use the generateDefinitions option.

    tsdlocal : {
        "dist" : {
            options : {
                generateDefinitions : true
            },
            files : [
                {
                    src: [
                        "./core-promise.d.ts"
                    ],
                    dest: "./core-promise.local.d.ts"
                }
            ]
        }
    }

Note

There is a high chance that the local .d.ts to still need a bit of fidling from your side, namely for modules that export instances for the exports. Like so:

declare module "x" {
    export = someInstance;
}

If that's the case, then you probably need to assign a variable, declare the variable with the name __require__x, and the type of the instance:

declare var __require__x : someInstanceType;

and in the client do:

// instead of:
//
// import mymodule = __require__x; // require("x")
//
// do:
var mymodule = __require__x; // require("x")

The static type checking will still function as expected.

ChangeLog

  • v0.1.6 2015-08-28 Bugfix Imports that have also classes are working. (import A = __require__x.A;)
  • v0.1.5 2015-07-22 The grunt task can also parse definitions now.
  • v0.1.4 2015-07-20 Use out.js for the standalone launcher, duh.
  • v0.1.3 2015-07-15 Use v0.1.2 grunt task to build itself.
  • v0.1.2 2015-07-15 Added Grunt task.
  • v0.1.1 2015-07-14 Documentation update.
  • v0.1.0 2015-07-10 Initial implementation.