Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 13.x]
node-version: [18.12, 20.x, 22.x]
os: [ubuntu-latest, windows-latest, macOS-latest]

runs-on: ${{ matrix.os }}

steps:
# Checkout the repository
- uses: actions/checkout@v2
- uses: actions/checkout@v4
# Installs the specific version of Node.js
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -58,7 +58,7 @@ jobs:
# Simply run the tests for the project.
################################################################################
- name: Run tests
run: npm test -- --no-coverage
run: npm test

################################################################################
# Run coverage check
Expand All @@ -73,7 +73,7 @@ jobs:
# pull-request event, and push event (line 3).
################################################################################
- name: Run coverage report
if: github.event_name == 'push' && matrix.node-version == '12.x' && matrix.os == 'ubuntu-latest'
if: github.event_name == 'push' && matrix.node-version == '22.x' && matrix.os == 'ubuntu-latest'
run: npm test
env:
# The environment variable name is leveraged by `tap`
Expand Down
19 changes: 14 additions & 5 deletions lib/nopt.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@ var debug = process.env.DEBUG_NOPT || process.env.NOPT_DEBUG
? function () { console.error.apply(console, arguments) }
: function () {}

var url = require("url")
, path = require("path")
var path = require("path")
, Stream = require("stream").Stream
, abbrev = require("abbrev")
, os = require("os")

// polyfill: `URL.parse` is only available in node 22.1.0 and up
URL.parse ??= (input, base) => {
try {
const url = new URL(input, base);
return url;
} catch {
return null;
}
}

module.exports = exports = nopt
exports.clean = clean

exports.typeDefs =
{ String : { type: String, validate: validateString }
, Boolean : { type: Boolean, validate: validateBoolean }
, url : { type: url, validate: validateUrl }
, URL : { type: URL, validate: validateUrl }
, Number : { type: Number, validate: validateNumber }
, path : { type: path, validate: validatePath }
, Stream : { type: Stream, validate: validateStream }
Expand Down Expand Up @@ -174,8 +183,8 @@ function validateBoolean (data, k, val) {
}

function validateUrl (data, k, val) {
val = url.parse(String(val))
if (!val.host) return false
val = URL.parse(String(val))
if (!val) return false
data[k] = val.href
}

Expand Down
Loading
Loading