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

native-huron

v0.1.7

Published

Utility classes for writing native addons for node.js.

Downloads

3

Readme

native-huron

A set of utility classes to make writing native addons easier. The majority of the code is from zcbenz's native-mate library. See tests folder for example. Current list of classes:

  • Converter: Converting from primitive and basic C++ variables to V8 variables and from V8 variables to C++ variables.
  • Dictionary: Handle dictionaries that represents a Javascript Object.
  • PersistentDictionary: Same as Dictionaries but stored on the heap.
  • ScopedPersistent: Store V8 objects on the heap.
  • Emitter: Event emitter class.

Install

$ npm i native-huron

Usage

In your binding.gyp:

{
  'includes': [ 'path/to/native-huron/module/native_huron_files.gypi' ],
  'targets': [ {
    'target_name': 'test'
    , 'sources': [ '<@(native_huron_files)' ]
    , 'include_dirs': [ "<!(node -e \"require('native-huron')\")" ]
  } ]
}

In your C++ files:

#include <native_huron/converter.h>
#include <native_huron/dictionary.h>

// Use utility classes...

API

Converter

ConvertToV8(isolate, value)

Converts the value, a primitive or simple C++ variable (e.g. double or std::string) to a V8 variable. Returns the converted V8 variable.

TryConvertToV8(isolate, value, result)

Tries to convert the value, a primitive or simple C++ variable (e.g. double or std::string) to a V8 variable. Returns a boolean wether the conversion was successful, if it was, the result is written to the result address.

ConvertFromV8(isolate, value, result)

Tries to convert the value, a V8 variable, primitive or simple C++ variable (e.g. double or std::string). Returns a boolean wether the conversion was successful, if it was, the result is written to the result address.

StringToV8(isolate, input)

Convenience function to convert a std::string to a v8::String. Returns the converted string.

V8ToString(isolate, input)

Convenience function to convert a v8::String to a std::string. Returns the converted string.

Dictionary

This class can also be used with Converter's ConvertTo/FromV8 functions.

Dictionary::Dictionary(isolate, object)

Creates a Dictionary object from the object parameter, which is a v8::Local<v8::Object>.

Dictionary::CreateEmpty(isolate)

Creates an empty Dictionary object. Returns the created dictionary.

dict.Get(key, out)

Returns true, if the key (std::string) exists in the dictionary and writes it to the out address.

dict.GetHidden(key, out)

Returns true, if the key (std::string) exists as a hidden value in the dictionary and writes it to the out address.

dict.Set(key, value)

Returns true, if the key (std::string) is successfully set in the dictionary with the given value.

dict.SetHidden(key, value)

Returns true, if the key (std::string) is successfully set as hidden value in the dictionary with the given value.

dict.SetMethod(key, callback)

Returns true, if the key (std::string) method is successfully set in the dictionary with the given callback, which is a C++ method with V8 FunctionCallback signature (standard V8 addon method signature).

dict.Delete(key)

Returns true, if the key (std::string) is successfully deleted from the dictionary.

dict.IsEmpty()

Returns if the dictionary is empty.

PersistentDictionary

Same functionality as Dictionary, but it is stored on the heap. Use only if really neccessary.

Emitter

Classes derived from this class can use the Emit method to fire listeners added in Javascript. In your class you have to add Emitter's On method to use it (see test folder).

Emit(V8String eventName, V8Types args...)

Emits the eventName event handlers with the specified args. All parameters' type should be V8 types!

Emit(std::string eventName, V8Types args...)

Alias for the above method.

Emit(const char* eventName, V8Types args...)

Alias for the above method.

Emit(std::string eventName, lambda(Dictionary &dict))

Emits the eventName event handlers with the dict object as a parameter. So you have to add the desired parameters in your lambda function your dictionary. This is needed to emit events from different threads as V8's thread.

Emit(const char* eventName, lambda(Dictionary &dict))

Alias for the above method.

On(std::string eventName, Local callback)

This member method lets you set listeners from c++ code.

Off(std::string eventName, Local callback)

This member method lets you remove listeners from c++ code.

Once(std::string eventName, Local callback)

This member method lets you set listeners from c++ code that fire only once.