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

edge-ts

v1.1.1

Published

Strongly typed .NET interop with Node.js

Downloads

4

Readme

edge-ts

Build Status Code Climate Dependencies Status Dev Dependencies Status npm version

Create strongly typed .NET bindings from Node.js.

In-process interop powered by the awesome edge.js.

Usage

1. Get the package

npm install --save edge-ts

2. Import it

import { sync, async, proxy } from 'edge-ts';

Types are bundled with the published package and will be automatically imported.

3. Create your bindings

interface InputArgs {
    life: string;
    universe: boolean;
    everything?: SomeOtherType;
}

const meaning = async<InputArgs, number>({
    assemblyFile: 'DeepThought.dll',
    typeName: 'FooBar.MyType',
    methodName: 'MyMethod' // This must be Func<object, Task<object>>
});

4. Call them as though they were Typscript functions

meaning({life: 'test', universe: true, everything: someOtherValue})
    .then(answer => console.log);

// some time passes

=> 42

API

Binding Targets

Bindings can be created to precompiled libraries (*.dll's) or source to be compiled at runtime by edge. Regardless of compile time, the targeted method must be of type Func<object, Task<object>>.

Source

C# source can be written in-line (as a string) as lambda expressions:

const test = async<string, string>(`
    async (input) => {
        return ".NET Welcomes " + input.ToString();
    }
`);

As full classes:

const test = async<string, string>(`
    using System.Data;
    using System.Threading.Tasks;

    public class Startup
    {
        public async Task<object> Invoke(object input)
        {
            // ...
        }
    }
`);

Or referenced as an external file:

const test = async<string, string>({
    source: 'Foo.cs',
    typeName: 'MyType',             // optional, defaults to 'StartUp'
    methodName: 'MyMethod',         // optional, defaults to 'Invoke'
    references: ['MyOtherLib.dll'], // optional (any external assemblies required)
});

Precompiled

Precompiled targets take a similar form:

const test = async<string, string>({
    assemblyFile: 'MyAssembly.dll',
    typeName: 'MyType',             // optional, defaults to 'StartUp'
    methodName: 'MyMethod',         // optional, defaults to 'Invoke'
    references: ['MyOtherLib.dll'], // optional (any external assemblies required)
});

Or, if you're happy with the defaults, just the path to the assembly:

const test = async<string, string>('MyAssembly.dll');

async<I, O>(«binding target»)

Create an asynchronous function, bound to a CLR/.NET Core/Mono method.

The returned function accepts an input (of type I) and returns a Promise (of type O).

Alternatively a Node style callback may be passed as a second argument.

const myAsyncBinding = async<number, string>('FooBar.dll');

myAsyncBinding(123)
    .then(doSomething);
    .catch(e => console.log('Oh noes!!!'));

// or

myAsyncBinding(123, (err, result) => {
    if (err) {
        console.log('Oh noes!!!');
    } else {
        doSomething(result);
    }
});

sync<I, O>(«binding target»)

Creates a synchronous function, bound to a CLR/.NET Core/Mono method.

The returned function takes a single input argument (or type I) and returns an output of type O. If the linked method does not return a synchronous result, an Error will be raised.

const mySyncBinding = sync<number, string>('FooBar.dll');

doSomthing(mySyncBinding(123));

proxy<I, O>(«func»)

Functions may also be passed to the CLR to allow it to call back into Node. These must be of a specific form expected by edge. proxy(..) may be used to transform a function of type I => O into this form.


For further information on marshaling data between the environments, refer to the edge.js guide