-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,153 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* eslint-env node */ | ||
module.exports = { | ||
parser: "@typescript-eslint/parser", | ||
plugins: ["@typescript-eslint", "prettier"], | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:prettier/recommended", | ||
"prettier/@typescript-eslint", | ||
], | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: "module", | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
}, | ||
rules: { | ||
"no-var": "off", | ||
"no-console": ["warn", { allow: ["warn", "error", "assert"] }], | ||
"max-params": ["error", { max: 4 }], | ||
|
||
"prettier/prettier": "warn", | ||
|
||
"@typescript-eslint/explicit-function-return-type": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/prefer-interface": "off", | ||
"@typescript-eslint/explicit-member-accessibility": "off", | ||
"@typescript-eslint/no-parameter-properties": "off", | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@typescript-eslint/no-use-before-define": "off", | ||
"@typescript-eslint/no-var-requires": "off", | ||
"@typescript-eslint/camelcase": "off", | ||
"@typescript-eslint/no-empty-interface": "off", | ||
"@typescript-eslint/no-inferrable-types": "off", | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/ban-types": "off", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
printWidth: 120, | ||
useTabs: false, | ||
arrowParens: "avoid", | ||
trailingComma: "all", | ||
tabWidth: 4, | ||
jsxBracketSameLine: true, | ||
endOfLine: "lf", | ||
overrides: [ | ||
{ | ||
files: ["*.json", ".prettierrc", ".eslintrc", ".stylelintrc", ".yml"], | ||
options: { | ||
tabWidth: 2, | ||
}, | ||
}, | ||
], | ||
proseWrap: "always", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
import { createRouting, number, segment } from '../src/index'; | ||
|
||
describe('createRouting', () => { | ||
it('creates a simple route', () => { | ||
const routes = createRouting({ | ||
products: segment`/products`, | ||
} as const); | ||
|
||
const route = routes.products(); | ||
|
||
expect(route).toEqual('/products'); | ||
}); | ||
|
||
it('creates nested routes', () => { | ||
const routes = createRouting({ | ||
products: { | ||
...segment`/products`, | ||
children: { | ||
create: segment`/create`, | ||
}, | ||
}, | ||
} as const); | ||
|
||
const mainRoute = routes.products(); | ||
const nestedRoute = routes.products.create(); | ||
|
||
expect(mainRoute).toEqual('/products'); | ||
expect(nestedRoute).toEqual('/products/create'); | ||
}); | ||
|
||
it('creates nested routes with params', () => { | ||
const routes = createRouting({ | ||
products: { | ||
...segment`/products/${number('productId')}`, | ||
children: { | ||
edit: segment`/edit`, | ||
}, | ||
}, | ||
} as const); | ||
|
||
const mainRoute = routes.products({ productId: '2' }); | ||
const nestedRoute = routes.products.edit({ productId: '2' }); | ||
|
||
expect(mainRoute).toEqual('/products/2'); | ||
expect(nestedRoute).toEqual('/products/2/edit'); | ||
}); | ||
import { createRouting, number, segment } from "../src/index"; | ||
|
||
describe("createRouting", () => { | ||
it("creates a simple route", () => { | ||
const routes = createRouting({ | ||
products: segment`/products`, | ||
} as const); | ||
|
||
const route = routes.products(); | ||
|
||
expect(route).toEqual("/products"); | ||
}); | ||
|
||
it("creates nested routes", () => { | ||
const routes = createRouting({ | ||
products: { | ||
...segment`/products`, | ||
children: { | ||
create: segment`/create`, | ||
}, | ||
}, | ||
} as const); | ||
|
||
const mainRoute = routes.products(); | ||
const nestedRoute = routes.products.create(); | ||
|
||
expect(mainRoute).toEqual("/products"); | ||
expect(nestedRoute).toEqual("/products/create"); | ||
}); | ||
|
||
it("creates nested routes with params", () => { | ||
const routes = createRouting({ | ||
products: { | ||
...segment`/products/${number("productId")}`, | ||
children: { | ||
edit: segment`/edit`, | ||
}, | ||
}, | ||
} as const); | ||
|
||
const mainRoute = routes.products({ productId: "2" }); | ||
const nestedRoute = routes.products.edit({ productId: "2" }); | ||
|
||
expect(mainRoute).toEqual("/products/2"); | ||
expect(nestedRoute).toEqual("/products/2/edit"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
import { arg, createRouting, segment } from '../../src'; | ||
import { arg, createRouting, segment } from "../../src"; | ||
|
||
describe('arg segment', () => { | ||
it('creates route with an arg segment', () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${arg('productId')}`, | ||
} as const); | ||
describe("arg segment", () => { | ||
it("creates route with an arg segment", () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${arg("productId")}`, | ||
} as const); | ||
|
||
const route = routes.product({ productId: 'id' }); | ||
const route = routes.product({ productId: "id" }); | ||
|
||
expect(route).toEqual('/product/id'); | ||
}); | ||
expect(route).toEqual("/product/id"); | ||
}); | ||
|
||
it('creates route with an optional arg segment', () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${arg('productId', { | ||
optional: true, | ||
})}`, | ||
} as const); | ||
it("creates route with an optional arg segment", () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${arg("productId", { | ||
optional: true, | ||
})}`, | ||
} as const); | ||
|
||
const route = routes.product(); | ||
const route = routes.product(); | ||
|
||
expect(route).toEqual('/product'); | ||
}); | ||
expect(route).toEqual("/product"); | ||
}); | ||
|
||
it('creates route with a custom pattern param', () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${arg('productId', { | ||
pattern: /[0-9]{2}/.source, | ||
})}`, | ||
} as const); | ||
it("creates route with a custom pattern param", () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${arg("productId", { | ||
pattern: /[0-9]{2}/.source, | ||
})}`, | ||
} as const); | ||
|
||
const route = routes.product({ productId: '23' }); | ||
const route = routes.product({ productId: "23" }); | ||
|
||
expect(route).toEqual('/product/23'); | ||
}); | ||
expect(route).toEqual("/product/23"); | ||
}); | ||
|
||
it('route with a custom pattern param gets correctly validated', () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${arg('productId', { | ||
pattern: /[0-9]{2}/.source, | ||
})}`, | ||
} as const); | ||
it("route with a custom pattern param gets correctly validated", () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${arg("productId", { | ||
pattern: /[0-9]{2}/.source, | ||
})}`, | ||
} as const); | ||
|
||
expect(() => routes.product({ productId: '123' })).toThrow(); | ||
}); | ||
expect(() => routes.product({ productId: "123" })).toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import { createRouting, number, segment } from '../../src'; | ||
import { createRouting, number, segment } from "../../src"; | ||
|
||
describe('number segment', () => { | ||
it('creates route with an optional number param', () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${number('productId', true)}`, | ||
} as const); | ||
describe("number segment", () => { | ||
it("creates route with an optional number param", () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${number("productId", true)}`, | ||
} as const); | ||
|
||
const route = routes.product(); | ||
const route = routes.product(); | ||
|
||
expect(route).toEqual('/product'); | ||
}); | ||
expect(route).toEqual("/product"); | ||
}); | ||
|
||
it('creates route with a required number param', () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${number('productId')}`, | ||
} as const); | ||
it("creates route with a required number param", () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${number("productId")}`, | ||
} as const); | ||
|
||
const route = routes.product({ productId: '1' }); | ||
const route = routes.product({ productId: "1" }); | ||
|
||
expect(route).toEqual('/product/1'); | ||
}); | ||
expect(route).toEqual("/product/1"); | ||
}); | ||
|
||
it('throws when given an invalid number param', () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${number('productId')}`, | ||
} as const); | ||
it("throws when given an invalid number param", () => { | ||
const routes = createRouting({ | ||
product: segment`/product/${number("productId")}`, | ||
} as const); | ||
|
||
expect(() => routes.product({ productId: 'aaa' })).toThrow(); | ||
}); | ||
expect(() => routes.product({ productId: "aaa" })).toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import { createRouting, number, query, segment } from '../../src'; | ||
import { createRouting, query, segment } from "../../src"; | ||
|
||
describe('query segment', () => { | ||
it('creates route with an optional query param', () => { | ||
const routes = createRouting({ | ||
product: segment`/product${query({ productId: false })}`, | ||
} as const); | ||
describe("query segment", () => { | ||
it("creates route with an optional query param", () => { | ||
const routes = createRouting({ | ||
product: segment`/product${query({ productId: false })}`, | ||
} as const); | ||
|
||
const route = routes.product(); | ||
const route = routes.product(); | ||
|
||
expect(route).toEqual('/product'); | ||
}); | ||
expect(route).toEqual("/product"); | ||
}); | ||
|
||
it('creates route with a required query param', () => { | ||
const routes = createRouting({ | ||
product: segment`/product${query({ productId: true })}`, | ||
} as const); | ||
it("creates route with a required query param", () => { | ||
const routes = createRouting({ | ||
product: segment`/product${query({ productId: true })}`, | ||
} as const); | ||
|
||
const route = routes.product({}, { productId: '2' }); | ||
const route = routes.product({}, { productId: "2" }); | ||
|
||
expect(route).toEqual('/product?productId=2'); | ||
}); | ||
expect(route).toEqual("/product?productId=2"); | ||
}); | ||
|
||
it('creates route with multiple query params and they are sorted in alphabetical order', () => { | ||
const routes = createRouting({ | ||
product: segment`/product${query({ | ||
productId: true, | ||
details: true, | ||
})}`, | ||
} as const); | ||
it("creates route with multiple query params and they are sorted in alphabetical order", () => { | ||
const routes = createRouting({ | ||
product: segment`/product${query({ | ||
productId: true, | ||
details: true, | ||
})}`, | ||
} as const); | ||
|
||
const route = routes.product({}, { productId: '2', details: 'false' }); | ||
const route = routes.product({}, { productId: "2", details: "false" }); | ||
|
||
expect(route).toEqual(`/product?details=false&productId=2`); | ||
}); | ||
expect(route).toEqual(`/product?details=false&productId=2`); | ||
}); | ||
}); |
Oops, something went wrong.