Skip to content

Commit 3cc344a

Browse files
committed
rewrite to esm, externalize the data, module is cli only now
1 parent 13fb81e commit 3cc344a

18 files changed

+2037
-332685
lines changed

.eslintrc.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
root: true
22
extends: silverwind
33

4-
rules:
5-
import/no-commonjs: [0]
6-
no-restricted-globals: [0]
7-
import/no-unused-modules: [0]
4+
# espree can't into import assertions
5+
parser: "@babel/eslint-parser"
6+
parserOptions:
7+
requireConfigFile: false
8+
babelOptions:
9+
plugins: ["@babel/plugin-syntax-import-assertions"]
10+
11+
ignorePatterns:
12+
- /bin/

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* text=auto eol=lf
2+
snapshots/*.snap linguist-language=JavaScript linguist-generated

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jobs:
55
test:
66
runs-on: ubuntu-latest
77
steps:
8-
- uses: actions/checkout@v3
8+
- uses: actions/checkout@v4
99
- uses: actions/setup-node@v3
1010
with:
11-
node-version: 18
11+
node-version: 20
1212
- run: make deps
1313
- run: make test
1414

.github/workflows/update.yaml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/.vscode/
1+
/.vscode
2+
/bin
23
/node_modules
34
/npm-debug.log*
45
/yarn-error.log

Makefile

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
SRC := oui.js
2+
DST := bin/oui.js
3+
14
node_modules: package-lock.json
25
npm install --no-save
36
@touch node_modules
@@ -7,38 +10,51 @@ deps: node_modules
710

811
.PHONY: lint
912
lint: node_modules
10-
npx eslint --color *.js
13+
npx eslint --color .
14+
15+
.PHONY: lint-fix
16+
lint-fix: node_modules
17+
npx eslint --color . --fix
1118

1219
.PHONY: test
13-
test: node_modules lint
20+
test: node_modules build
1421
npx vitest
1522

23+
.PHONY: test-update
24+
test-update: node_modules build
25+
npx vitest -u
26+
27+
.PHONY: build
28+
build: $(DST)
29+
30+
$(DST): $(SRC) node_modules Makefile
31+
# workaround for https://github.com/evanw/esbuild/issues/1921
32+
npx esbuild --log-level=warning --platform=node --target=node18 --format=esm --bundle --minify --legal-comments=none --banner:js="import {createRequire} from 'module';const require = createRequire(import.meta.url);" --define:import.meta.VERSION=\"$(shell jq .version package.json)\" --outfile=$(DST) $(SRC) --external:oui-data
33+
chmod +x $(DST)
34+
1635
.PHONY: publish
1736
publish: node_modules
1837
git push -u --tags origin master
1938
npm publish
2039

40+
.PHONY: update
2141
update: node_modules
2242
npx updates -cu
2343
rm -rf node_modules package-lock.json
2444
npm install
2545
@touch node_modules
2646

27-
.PHONY: data
28-
data: node_modules
29-
node oui.js update -w
30-
3147
.PHONY: patch
32-
patch: node_modules test
33-
npx versions patch package.json package-lock.json
48+
patch: node_modules lint test
49+
npx versions -c 'make --no-print-directory build' patch package.json package-lock.json
3450
@$(MAKE) --no-print-directory publish
3551

3652
.PHONY: minor
37-
minor: node_modules test
38-
npx versions minor package.json package-lock.json
53+
minor: node_modules lint test
54+
npx versions -c 'make --no-print-directory build' minor package.json package-lock.json
3955
@$(MAKE) --no-print-directory publish
4056

4157
.PHONY: major
42-
major: node_modules test
43-
npx versions major package.json package-lock.json
58+
major: node_modules lint test
59+
npx versions -c 'make --no-print-directory build' major package.json package-lock.json
4460
@$(MAKE) --no-print-directory publish

README.md

Lines changed: 5 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,17 @@
11
# oui
2-
[![](https://img.shields.io/npm/v/oui.svg?style=flat)](https://www.npmjs.org/package/oui) [![](https://img.shields.io/npm/dm/oui.svg)](https://www.npmjs.org/package/oui)
3-
> Look up MAC addresses for their vendor in the IEEE OUI database
2+
[![](https://img.shields.io/npm/v/oui.svg?style=flat)](https://www.npmjs.org/package/oui) [![](https://img.shields.io/npm/dm/oui.svg)](https://www.npmjs.org/package/oui) [![](https://packagephobia.com/badge?p=oui)](https://packagephobia.com/result?p=oui)
3+
> CLI to look up MAC addresses for their vendor in the IEEE OUI database
44
5-
The data used in this module comes from the [IEEE OUI Data](https://standards-oui.ieee.org/oui/oui.txt) which is updated once a week on Sunday. The module is also able self-update on demand.
5+
*Note: This module is CLI only since v13. The data has moved to module [oui-data](https://github.com/silverwind/oui-data).*
66

7-
## Installation
8-
```console
9-
$ npm i oui
10-
```
11-
## Example
12-
```js
13-
var oui = require('oui');
14-
15-
console.log(oui('20:37:06:12:34:56'));
16-
//=> Cisco Systems, Inc
17-
//=> 80 West Tasman Drive
18-
//=> San Jose CA 94568
19-
//=> United States
20-
21-
console.log(oui.search('*Juniper Systems*'))
22-
//=> [
23-
//=> {
24-
//=> oui: '0C0535',
25-
//=> organization: 'Juniper Systems\n1132 W. 1700 N.\nLogan UT 84321\nUnited States'
26-
//=> }
27-
//=> ]
28-
```
29-
30-
## Installation (CLI)
31-
```console
32-
$ npm install -g oui
33-
```
34-
## Examples (CLI)
7+
## Usage
358
```console
9+
$ npm i -g oui
3610
$ oui 20:37:06:12:34:56
3711
Cisco Systems, Inc
3812
80 West Tasman Drive
3913
San Jose CA 94568
4014
United States
4115
```
42-
```console
43-
$ oui --search cisco theory
44-
OUI ORGANZATION ADDRESS COUNTRY
45-
000C41 Cisco-Linksys LLC 121 Theory Dr. Irvine CA 92612
46-
000F66 Cisco-Linksys LLC 121 Theory Dr. Irvine CA 92612
47-
001217 Cisco-Linksys LLC 121 Theory Dr. Irvine CA 92612
48-
001310 Cisco-Linksys LLC 121 Theory Dr. Irvine CA 92612
49-
```
50-
To update the local OUI database:
51-
```console
52-
$ oui --update
53-
```
54-
Or from the original IEEE source (slow):
55-
```console
56-
$ oui --update http://standards.ieee.org/develop/regauth/oui/oui.txt
57-
```
58-
59-
## API
60-
### oui(input, [options])
61-
- `input` *string*: The input string. Non-hexadecimal characters and characters after 6 hex characters are found are ignored unless `options.strict` is set.
62-
- `options` *Object*: A optional options object.
63-
- `strict` *boolean*: When `true`, only [strict input formats will be accepted](#strictformats). Will throw an error when an invalid format is supplied.
64-
- `file` *string*: A absolute file path to `oui.json`, which contains the parsed oui data. Defaults to the `oui.json` in the module directory.
65-
66-
Returns: Either a string, or `null` if no matches are found. Throws if input is not a string.
67-
68-
### oui.update([options])
69-
- `options` *Object*: A optional options object.
70-
- `url` *string*: The URL from where to retrieve `oui.txt`. Default `"https://standards-oui.ieee.org/oui/oui.txt"`.
71-
- `file` *string*: A absolute file path for `oui.json`, which is used to store the parsed oui data. Defaults to the `oui.json` in the module directory.
72-
73-
Returns: A Promise that indicates when the internal database has been updated. Rejects on error.
74-
75-
### oui.search(patterns [, options])
76-
- `patterns` *string/Array*: One or more wildcard patterns to search the vendor data, as supported by [minimatch](https://github.com/isaacs/minimatch).
77-
- `options` *Object*: A optional options object.
78-
- `file` *String*: A absolute file path for `oui.json`, which is used to store the parsed oui data. Defaults to the `oui.json` in the module directory.
79-
- All [minimatch options](https://github.com/isaacs/minimatch#options) are supported as well.
80-
81-
Returns a array of objects in the format {oui, organization}.
82-
<a name="strictformats" />
83-
#### strict formats
84-
- `000000`
85-
- `00:00:00`
86-
- `00-00-00`
87-
- `000000000000`
88-
- `0000.0000.0000`
89-
- `00:00:00:00:00:00`
90-
- `00-00-00-00-00-00`
9116

9217
© [silverwind](https://github.com/silverwind), distributed under BSD licence

0 commit comments

Comments
 (0)