Skip to content

Commit

Permalink
convert to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Sep 16, 2022
1 parent c40d18f commit 538ef33
Show file tree
Hide file tree
Showing 10 changed files with 11,244 additions and 64 deletions.
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ insert_final_newline = true

[Makefile]
indent_style = tab
indent_size = 2
File renamed without changes.
11 changes: 4 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node: ['14', '16', '18']

runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: make deps
node-version: ${{matrix.node}}
- run: make test

10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules
npm-debug.log*
yarn-error.log
yarn.lock
.vscode/
/.vscode
/node_modules
/npm-debug.log*
/yarn-error.log
/yarn.lock
6 changes: 5 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
package-lock=false
audit=false
fund=false
package-lock=true
save-exact=true
update-notifier=false
64 changes: 36 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
test:
yarn -s run eslint --color .
yarn -s run tsd
yarn -s run jest --color
node_modules: package-lock.json
npm install --no-save
@touch node_modules

unittest:
yarn -s run jest --color --watchAll
.PHONY: deps
deps: node_modules

publish:
git push -u --tags origin master
npm publish

deps:
rm -rf node_modules
yarn

update:
yarn -s run updates -cu
$(MAKE) deps
.PHONY: lint
lint: node_modules
npx eslint --color .

patch: test
yarn -s run versions -C patch
$(MAKE) publish
.PHONY: test
test: node_modules
NODE_OPTIONS="--experimental-vm-modules --no-warnings" npx jest --color

minor: test
yarn -s run versions -C minor
$(MAKE) publish

major: test
yarn -s run versions -C major
$(MAKE) publish
.PHONY: publish
publish: node_modules
git push -u --tags origin master
npm publish

.PHONY: test unittest publish deps update patch minor major
.PHONY: update
update: node_modules
npx updates -cu
rm package-lock.json
npm install
@touch node_modules

.PHONY: path
patch: node_modules lint test
npx versions -C patch
@$(MAKE) --no-print-directory publish

.PHONY: minor
minor: node_modules lint test
npx versions -C minor
@$(MAKE) --no-print-directory publish

.PHONY: major
major: node_modules lint test
npx versions -C major
@$(MAKE) --no-print-directory publish
15 changes: 6 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
"use strict";

const ipRegex = require("ip-regex");
import ipRegex from "ip-regex";

const defaultOpts = {exact: false};

const v4str = `${ipRegex.v4().source}\\/(3[0-2]|[12]?[0-9])`;
const v6str = `${ipRegex.v6().source}\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])`;

// can not precompile the non-exact regexes because global flag makes the regex object stateful
// which would require the user to reset .lastIndex on subsequent calls
// pre-compile only the exact regexes as global flag makes regex objects stateful
const v4exact = new RegExp(`^${v4str}$`);
const v6exact = new RegExp(`^${v6str}$`);
const v46exact = new RegExp(`(?:^${v4str}$)|(?:^${v6str}$)`);

module.exports = ({exact} = defaultOpts) => exact ? v46exact : new RegExp(`(?:${v4str})|(?:${v6str})`, "g");
module.exports.v4 = ({exact} = defaultOpts) => exact ? v4exact : new RegExp(v4str, "g");
module.exports.v6 = ({exact} = defaultOpts) => exact ? v6exact : new RegExp(v6str, "g");
const cidrRegex = ({exact} = defaultOpts) => exact ? v46exact : new RegExp(`(?:${v4str})|(?:${v6str})`, "g");
export const v4 = cidrRegex.v4 = ({exact} = defaultOpts) => exact ? v4exact : new RegExp(v4str, "g");
export const v6 = cidrRegex.v6 = ({exact} = defaultOpts) => exact ? v6exact : new RegExp(v6str, "g");
export default cidrRegex;
Loading

0 comments on commit 538ef33

Please # to comment.