Gathering detailed insights and metrics for ref-struct-napi
Gathering detailed insights and metrics for ref-struct-napi
Gathering detailed insights and metrics for ref-struct-napi
Gathering detailed insights and metrics for ref-struct-napi
npm install ref-struct-napi
Typescript
Module System
Node Version
NPM Version
JavaScript (57.02%)
C++ (42.47%)
Python (0.51%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
7 Stars
132 Commits
9 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Jun 16, 2025
Latest Version
1.1.1
Package Id
ref-struct-napi@1.1.1
Size
7.71 kB
NPM Version
6.12.0
Node Version
12.13.0
Published on
May 01, 2020
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
This module offers a "struct" implementation on top of Node.js Buffers using the ref "type" interface. Supports Node 6, 7, 8, 10, 12.
Install with npm
:
1$ npm install ref-struct-napi
Say you wanted to emulate the timeval
struct from the stdlib:
1struct timeval { 2 time_t tv_sec; /* seconds since Jan. 1, 1970 */ 3 suseconds_t tv_usec; /* and microseconds */ 4};
1var ref = require('ref-napi') 2var StructType = require('ref-struct-napi') 3 4// define the time types 5var time_t = ref.types.long 6var suseconds_t = ref.types.long 7 8// define the "timeval" struct type 9var timeval = StructType({ 10 tv_sec: time_t, 11 tv_usec: suseconds_t 12}) 13 14// now we can create instances of it 15var tv = new timeval
node-ffi
This gets very powerful when combined with node-ffi
to invoke C functions:
1var ffi = require('ffi') 2 3var tv = new timeval 4gettimeofday(tv.ref(), null)
You can build up a Struct "type" incrementally (useful when interacting with a
parser) using the defineProperty()
function. But as soon as you create an
instance of the struct type, then the struct type is finalized, and no more
properties may be added to it.
1var ref = require('ref-napi')
2var StructType = require('ref-struct-napi')
3
4var MyStruct = StructType()
5MyStruct.defineProperty('width', ref.types.int)
6MyStruct.defineProperty('height', ref.types.int)
7
8var i = new MyStruct({ width: 5, height: 10 })
9
10MyStruct.defineProperty('weight', ref.types.int)
11// AssertionError: an instance of this Struct type has already been created, cannot add new "fields" anymore
12// at Function.defineProperty (/Users/nrajlich/ref-struct/lib/struct.js:180:3)
(The MIT License)
Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 1/28 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More