next-typed-routes
Advanced tools
Comparing version 1.0.1 to 1.0.2
# Changelog | ||
## 1.0.2 (2019-12-07) | ||
- Fix parameters and query parameteres checking when giving falsy values such as zero #8 - [@jagaapple](https://github.com/jagaapple) | ||
- Update development environment #7 - [@jagaapple](https://github.com/jagaapple) | ||
## 1.0.1 (2019-10-09) | ||
- Fix `createRoute` function parse #5 - [@jagaapple](https://github.com/jagaapple) | ||
## 1.0.0 (2019-10-09) | ||
- Initial public release - [@jagaapple](https://github.com/jagaapple) | ||
## 0.0.1 (2019-10-02) | ||
- Initial private release - [@jagaapple](https://github.com/jagaapple) |
@@ -16,2 +16,3 @@ "use strict"; | ||
options = {}) => { | ||
var _a, _b; | ||
const uri = typeof path === "string" ? path : path.href; | ||
@@ -32,6 +33,6 @@ const alias = typeof path === "string" ? path : path.as; | ||
const aliasURL = new URL(alias, baseURI); | ||
const queryString = query_merger_1.mergeQueryString(aliasURL, options.queryParameters || {}); | ||
const queryString = query_merger_1.mergeQueryString(aliasURL, (_a = options.queryParameters, (_a !== null && _a !== void 0 ? _a : {}))); | ||
const url = new URL(queryString.length > 0 ? `${aliasURL.pathname}?${queryString}` : alias, baseURI); | ||
res.writeHead(options.statusCode || 302, { Location: url.toString() }); | ||
res.writeHead((_b = options.statusCode, (_b !== null && _b !== void 0 ? _b : 302)), { Location: url.toString() }); | ||
res.end(); | ||
}; |
@@ -22,2 +22,3 @@ "use strict"; | ||
const newSegment = (() => { | ||
var _a; | ||
const matches = segment.match(/\[(.*?)\]/); | ||
@@ -27,3 +28,3 @@ if (matches == undefined) | ||
const parameterName = matches[1]; | ||
return parameters[parameterName] || segment; | ||
return _a = parameters[parameterName], (_a !== null && _a !== void 0 ? _a : segment); | ||
})(); | ||
@@ -30,0 +31,0 @@ completedURISegments.push(newSegment.toString()); |
{ | ||
"name": "next-typed-routes", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Type safe route utilities for Next.js.", | ||
@@ -35,32 +35,30 @@ "keywords": [ | ||
"prebuild": "rm -rf ./lib", | ||
"build": "tsc -p ./tsconfig.json", | ||
"build": "tsc", | ||
"lint": "eslint ./src/**/*.ts", | ||
"fix": "eslint --fix ./src/**/*.ts", | ||
"prepublishOnly": "npm run build", | ||
"pretest": "rm -rf ./.nyc_output ./coverage", | ||
"test": "nyc --reporter=text --reporter=html mocha --reporter=dot src/**/*.spec.ts", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov" | ||
"test": "jest --coverage", | ||
"coverage": "codecov", | ||
"clean": "rm -rf ./lib ./coverage" | ||
}, | ||
"config": {}, | ||
"dependencies": { | ||
"query-string": "^6.8.3" | ||
"query-string": "^6.9.0" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.2.3", | ||
"@types/mocha": "^5.2.7", | ||
"@types/jest": "^24.0.23", | ||
"@types/jest-plugin-context": "^2.9.2", | ||
"@types/node": "^12.7.11", | ||
"@types/sinon": "^7.5.0", | ||
"@typescript-eslint/eslint-plugin": "^2.3.2", | ||
"@typescript-eslint/parser": "^2.3.2", | ||
"chai": "^4.2.0", | ||
"@typescript-eslint/eslint-plugin": "^2.10.0", | ||
"@typescript-eslint/parser": "^2.10.0", | ||
"codecov": "^3.6.1", | ||
"eslint": "^6.5.1", | ||
"eslint-config-prettier": "^6.3.0", | ||
"eslint": "^6.7.2", | ||
"eslint-config-prettier": "^6.7.0", | ||
"eslint-plugin-prettier": "^3.1.1", | ||
"mocha": "^6.2.1", | ||
"nyc": "^14.1.1", | ||
"prettier": "^1.18.2", | ||
"sinon": "^7.5.0", | ||
"ts-node": "^8.4.1", | ||
"typescript": "^3.6.3" | ||
"jest": "^24.9.0", | ||
"jest-plugin-context": "^2.9.0", | ||
"prettier": "^1.19.1", | ||
"ts-jest": "^24.2.0", | ||
"ts-node": "^8.5.4", | ||
"typescript": "^3.7.3" | ||
}, | ||
@@ -67,0 +65,0 @@ "peerDependencies": {}, |
@@ -26,3 +26,3 @@ <h1 align="center">next-typed-routes</h1> | ||
export default () => ( | ||
const Page () => ( | ||
<Link {...routes.usersDetail(targetUserId)}> | ||
@@ -33,12 +33,6 @@ <a>Go to the user page (id: {targetUserId})</a> | ||
// And it is possible to redirect URL for unviersal (client and server-side)! | ||
import Router from "next/router"; | ||
import { createPageMover } from "next-typed-routes"; | ||
const movePage = createPageMover("https://you-project.example.com", Router); | ||
... | ||
Component.getInitialProps = async ({ res }) => { | ||
Page.getInitialProps = async ({ res }) => { | ||
// Redirect to `/users/123&limit=30` . | ||
// This works fine on web browsers and server-side. | ||
// This works fine on client-side and server-side. | ||
movePage(routes.usersDetail(123), { res, queryParameters: { limit: 30 } }) | ||
@@ -83,8 +77,8 @@ }; | ||
| FEATURES | WHAT YOU CAN DO | | ||
|------------------------------------|-----------------------------------------------------------------| | ||
| ❤️ **Designed for Next.js** | You can use Next.js built-in routing system | | ||
| 🌐 **Build for Universal** | Ready for Universal JavaScript | | ||
| 📄 **Write once, Manage one file** | All you need is write routes to one file | | ||
| 🎩 **Type Safe** | You can get errors when missing required dynamic URL parameters | | ||
| FEATURES | WHAT YOU CAN DO | | ||
|------------------------------------|----------------------------------------------------------| | ||
| ❤️ **Designed for Next.js** | You can use Next.js routing system without custom server | | ||
| 🌐 **Build for Universal** | Ready for Universal JavaScript | | ||
| 📄 **Write once, Manage one file** | All you need is write routes to one file | | ||
| 🎩 **Type Safe** | You can use with TypeScript | | ||
@@ -105,5 +99,5 @@ ### Motivation | ||
### Requirements | ||
- npm or Yarn | ||
- Node.js 10.0.0 or higher | ||
- npm or Yarn | ||
- **Next.js 9 or higher** | ||
- **Next.js 9.0.0 or higher** | ||
@@ -113,6 +107,6 @@ | ||
```bash | ||
$ npm install --save-dev next-typed-routes | ||
$ npm install next-typed-routes | ||
``` | ||
If you use Yarn, use the following command. | ||
If you are using Yarn, use the following command. | ||
@@ -140,7 +134,7 @@ ```bash | ||
First, you need to define routes using next-typed-routes. | ||
Firstly, you need to define routes using next-typed-routes. | ||
`createRoute` function exported from next-typed-routes returns an object for `<Link>` component props, which has `href` and `as` | ||
properties. | ||
So when you manage values created by `createRoute` by keys, you can get `<Link>` component props via the keys like the following. | ||
So when you manage values created by `createRoute`, you can get `<Link>` component props via the keys like the following. | ||
@@ -147,0 +141,0 @@ ```tsx |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15
113
20756
283
Updatedquery-string@^6.9.0