Skip to content

Commit

Permalink
convert to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed May 23, 2024
1 parent 82ea63e commit dbbe644
Show file tree
Hide file tree
Showing 15 changed files with 2,945 additions and 788 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
root: true
extends: silverwind
extends:
- silverwind
- silverwind-typescript
11 changes: 6 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [16, 18, 20]
runs-on: ubuntu-latest
os: [ubuntu-latest, macos-latest, windows-latest]
node: [18, 20, 22]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{matrix.node}}
- run: make test
- run: make lint test
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/.vscode
/dist
/node_modules
/npm-debug.log*
/yarn-error.log
/yarn.lock
28 changes: 23 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
SOURCE_FILES := index.ts
DIST_FILES := dist/index.js

node_modules: package-lock.json
npm install --no-save
@touch node_modules
Expand All @@ -7,12 +10,27 @@ deps: node_modules

.PHONY: lint
lint: node_modules
npx eslint --color .
npx eslint --ext js,jsx,ts,tsx --color .
npx tsc

.PHONY: lint-fix
lint-fix: node_modules
npx eslint --ext js,jsx,ts,tsx --color . --fix
npx tsc

.PHONY: test
test: node_modules
npx vitest
npx tsd

.PHONY: test-update
test-update: node_modules
npx vitest -u

.PHONY: build
build: node_modules $(DIST_FILES)

$(DIST_FILES): $(SOURCE_FILES) package-lock.json vite.config.ts
npx vite build

.PHONY: publish
publish: node_modules
Expand All @@ -27,16 +45,16 @@ update: node_modules
@touch node_modules

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

.PHONY: minor
minor: node_modules lint test
minor: node_modules lint test build
npx versions minor package.json package-lock.json
@$(MAKE) --no-print-directory publish

.PHONY: major
major: node_modules lint test
major: node_modules lint test build
npx versions major package.json package-lock.json
@$(MAKE) --no-print-directory publish
25 changes: 0 additions & 25 deletions index.d.ts

This file was deleted.

9 changes: 0 additions & 9 deletions index.js

This file was deleted.

8 changes: 0 additions & 8 deletions index.test-d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion index.test.js → index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isCidr, {v4, v6} from "./index.js";
import isCidr, {v4, v6} from "./index.ts";

const v4positive = [
"0.0.0.0/16",
Expand Down
9 changes: 9 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {v4 as v4Re, v6 as v6Re} from "cidr-regex";

const re4 = v4Re({exact: true});
const re6 = v6Re({exact: true});

const isCidr = (str: string) => re4.test(str) ? 4 : (re6.test(str) ? 6 : 0);
export const v4 = isCidr.v4 = (str: string) => re4.test(str);
export const v6 = isCidr.v6 = (str: string) => re6.test(str);
export default isCidr;
Loading

0 comments on commit dbbe644

Please sign in to comment.