diff --git a/.gitignore b/.gitignore index 507fbe1..c63d6df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /node_modules /test/build /?.js +/package-lock.json diff --git a/.travis.yml b/.travis.yml index c5c65ab..96408a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,12 @@ addons: language: node_js node_js: - - "4" - - "5" - "6" - "7" - "8" + - "10" + - "12" + - "14" install: - PATH="`npm bin`:`npm bin -g`:$PATH" diff --git a/README.md b/README.md index f6d1d89..64b06d7 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -ref-array +ref-array-napi ========= ### Create C typed "array" instances on top of Buffers -[![Build Status](https://secure.travis-ci.org/TooTallNate/ref-array.svg)](https://travis-ci.org/TooTallNate/ref-array) -[![Build Status](https://ci.appveyor.com/api/projects/status/auxk791h56hbughd?svg=true)](https://ci.appveyor.com/project/TooTallNate/ref-array) +[![Build Status](https://travis-ci.org/Janealter/ref-array-napi.svg)](https://travis-ci.org/Janealter/ref-array-napi) +[![Build Status](https://ci.appveyor.com/api/projects/status/gibqc0mg6dkdn9o4?svg=true)](https://ci.appveyor.com/project/Janealter/ref-array-napi) This module offers an "array" implementation on top of Node.js Buffers using -the ref "type" interface. +the ref "type" interface. Supports Node 6, 7, 8, 10, 12. Installation ------------ @@ -14,7 +14,7 @@ Installation Install with `npm`: ``` bash -$ npm install ref-array +$ npm install ref-array-napi ``` @@ -24,8 +24,8 @@ Examples #### Basic usage ``` js -var ref = require('ref') -var ArrayType = require('ref-array') +var ref = require('ref-napi') +var ArrayType = require('ref-array-napi') // typedef var int = ref.types.int diff --git a/appveyor.yml b/appveyor.yml index c5e4bf1..cf9d979 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,13 +3,15 @@ # Test against these versions of Node.js. environment: # Visual Studio Version - MSVS_VERSION: 2013 + MSVS_VERSION: 2015 # Test against these versions of Node.js and io.js matrix: - - nodejs_version: "4" - nodejs_version: "6" - nodejs_version: "7" - nodejs_version: "8" + - nodejs_version: "10" + - nodejs_version: "12" + - nodejs_version: "14" platform: - x86 diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..74e6ceb --- /dev/null +++ b/index.d.ts @@ -0,0 +1,50 @@ +// Type definitions for ref-array-napi +// Project: https://github.com/Janealter/ref-array-napi +// Definitions by: goooseman +// Used definitions by: Paul Loyd +// TypeScript Version: 3.7 + +import ref = require('ref-napi'); + +interface ArrayTypeInstance { + [i: number]: T; + length: number; + toArray(): T[]; + toJSON(): T[]; + inspect(): string; + buffer: Buffer; + ref(): Buffer; +} + +interface ArrayType extends ref.Type { + BYTES_PER_ELEMENT: number; + fixedLength: number; + /** The reference to the base type. */ + type: ref.Type; + + /** + * Accepts a Buffer instance that should be an already-populated with data + * for the ArrayType. The "length" of the Array is determined by searching + * through the buffer's contents until an aligned NULL pointer is encountered. + */ + untilZeros(buffer: Buffer): ArrayTypeInstance; + + new (length?: number): ArrayTypeInstance; + new (data: number[], length?: number): ArrayTypeInstance; + new (data: Buffer, length?: number): ArrayTypeInstance; + (length?: number): ArrayTypeInstance; + (data: number[], length?: number): ArrayTypeInstance; + (data: Buffer, length?: number): ArrayTypeInstance; +} + +/** + * The array type meta-constructor. + * The returned constructor's API is highly influenced by the WebGL + * TypedArray API. + */ +declare const ArrayType: { + (type: ref.Type, length?: number): ArrayType; + (type: string, length?: number): ArrayType; +}; + +export = ArrayType; diff --git a/lib/array.js b/lib/array.js index b86ae13..08223a2 100644 --- a/lib/array.js +++ b/lib/array.js @@ -3,7 +3,7 @@ * Module dependencies. */ -var _ref = require('ref') +var _ref = require('ref-napi') var assert = require('assert') var debug = require('debug')('ref:array') var ArrayIndex = require('array-index') diff --git a/package.json b/package.json index 3422913..07b6b3f 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { - "name": "ref-array", - "description": "Create C \"array\" instances on top of Buffers", + "name": "ref-array-napi", + "description": "Create C \"array\" instances on top of Buffers. Supports Node 6, 7, 8, 10, 12.", "keywords": [ "array", "ref" ], - "version": "1.2.0", - "author": "Nathan Rajlich (http://tootallnate.net)", + "version": "1.2.2", + "author": "Nathan Rajlich (http://tootallnate.net) & Janealter", "repository": { "type": "git", - "url": "git://github.com/TooTallNate/ref-array.git" + "url": "git://github.com/Janealter/ref-array-napi.git" }, "main": "./lib/array.js", "license": "MIT", @@ -19,7 +19,7 @@ "dependencies": { "array-index": "1", "debug": "2", - "ref": "1" + "ref-napi": "^3.0.1" }, "devDependencies": { "bindings": "1", diff --git a/test/array.js b/test/array.js index 60311b8..23d0c6c 100644 --- a/test/array.js +++ b/test/array.js @@ -1,6 +1,6 @@ var assert = require('assert') - , ref = require('ref') + , ref = require('ref-napi') , ArrayType = require('../') , bindings = require('bindings')({ module_root: __dirname, bindings: 'native_tests' }) diff --git a/test/native_tests.cc b/test/native_tests.cc index 2074d72..3f1add0 100644 --- a/test/native_tests.cc +++ b/test/native_tests.cc @@ -8,13 +8,13 @@ namespace { NAN_METHOD(ArrayAbs) { int *arr = reinterpret_cast(Buffer::Data(info[0].As())); - uint32_t length = info[1]->Uint32Value(); + uint32_t length = info[1]->Uint32Value(Nan::GetCurrentContext()).FromJust(); for (uint32_t i = 0; i < length; i++) { *(arr + i) = abs(arr[i]); } } -void Initialize(v8::Handle target) { +void Initialize(v8::Local target) { Nan::HandleScope scope; Nan::SetMethod(target, "arrayAbs", ArrayAbs); }