Skip to content

Commit

Permalink
Add TypeScript typings (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
yassernasc authored Jan 6, 2025
1 parent cae2526 commit 90ab1e8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
36 changes: 36 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Buffer, { BufferEncoding } from 'bare-buffer'

declare function lex(
input: string | Buffer,
encoding?: BufferEncoding
): {
imports: {
specifier: string
type: number
names: string[]
position: [
importStart: number,
specifierStart: number,
specifierEnd: number
]
}[]

exports: {
name: string
position: [exportStart: number, nameStart: number, nameEnd: number]
}[]
}

declare namespace lex {
export const constants: {
REQUIRE: number
IMPORT: number
DYNAMIC: number
ADDON: number
ASSET: number
RESOLVE: number
REEXPORT: number
}
}

export = lex
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"version": "1.1.0",
"description": "Heuristic lexer for detecting imports and exports in JavaScript modules",
"exports": {
".": "./index.js",
".": {
"types": "./index.d.ts",
"default": "./index.js"
},
"./package": "./package.json"
},
"imports": {
Expand All @@ -14,6 +17,7 @@
},
"files": [
"index.js",
"index.d.ts",
"lex.h",
"binding.c",
"binding/bare.js",
Expand Down Expand Up @@ -42,12 +46,16 @@
"require-addon": "^1.0.2"
},
"devDependencies": {
"bare-buffer": "^2.7.1",
"bare-compat-napi": "^1.0.0",
"brittle": "^3.1.1",
"cmake-bare": "^1.1.7",
"cmake-napi": "^1.0.5",
"cmake-npm": "^1.0.2",
"prettier": "^3.4.1",
"prettier-config-standard": "^7.0.0"
},
"peerDependencies": {
"bare-buffer": "*"
}
}

0 comments on commit 90ab1e8

Please sign in to comment.