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
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

26 changes: 0 additions & 26 deletions .eslintrc

This file was deleted.

11 changes: 7 additions & 4 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ jobs:
uses: actions/checkout@v2

- name: Install
run: yarn install
run: npm install

- name: Lint
run: yarn run lint
run: npm run lint

- name: Test
run: yarn run test
run: npm run test --verbose

- name: Build
run: yarn run build
run: npm run build

- name: Predeploy
run: npm pack
10 changes: 0 additions & 10 deletions .prettierrc

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Pontus Persson
Copyright (c) 2022 Pontus Persson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ A JavaScript and TypeScript lib for handling type rich URLs in web apps.
Start by defining paths. Paths are usually created once in a single module, then imported for usage.

```ts
import { createPath, codecs } from '@pomle/paths';
import { createPath, codecs } from "@pomle/paths";

const user = createPath('/user/:userId', {
const user = createPath("/user/:userId", {
userId: codecs.string,
});

const userPost = user.append('/posts/:postId', {
const userPost = user.append("/posts/:postId", {
postId: codecs.number,
});

Expand All @@ -28,10 +28,10 @@ export const paths = {
Create URLs

```ts
import { paths } from './paths';
import { paths } from "./paths";

const url = paths.userPost.build({
userId: 'pomle',
userId: "pomle",
postId: 24,
});

Expand All @@ -41,33 +41,33 @@ console.log(url); // Prints "/user/pomle/posts/24"
Parse path params from URLs

```ts
import { paths } from './paths';
import { paths } from "./paths";

const values = paths.userPost.parse('/user/pomle/posts/24');
const values = paths.userPost.parse("/user/pomle/posts/24");

console.log(values); // Prints {userId: "pomle", postId: 24}
```

Non-matching or under-matching returns null

```ts
import { paths } from './paths';
import { paths } from "./paths";

// Returns null
paths.userPost.parse('/not/user/posts');
paths.userPost.parse("/not/user/posts");

// Returns null
paths.userPost.parse('/user/pomle');
paths.userPost.parse("/user/pomle");
```

Decode params already parsed

```ts
import { paths } from './paths';
import { paths } from "./paths";

const values = paths.userPost.decode({
userId: 'pomle',
postId: '24',
userId: "pomle",
postId: "24",
});

console.log(values); // Prints {userId: "pomle", postId: 24}
Expand All @@ -78,7 +78,7 @@ console.log(values); // Prints {userId: "pomle", postId: 24}
Define query params

```ts
import { createQuery, codecs } from '@pomle/paths';
import { createQuery, codecs } from "@pomle/paths";

const searchFilter = createQuery({
username: codecs.string,
Expand Down Expand Up @@ -108,7 +108,7 @@ Update query string
// Location ?username=Pontus+Alexander&range=3&range=5

const qs = searchFilter.build({
username: ['Pontus Alexander'],
username: ["Pontus Alexander"],
range: [3, 5],
});

Expand All @@ -121,15 +121,15 @@ console.log(qs);
There are 4 codecs bundled

```ts
import { codecs } from '@pomle/paths';
import { codecs } from "@pomle/paths";
```

#### `codecs.string`

Encodes strings safely

```ts
import { createQuery, codecs } from '@pomle/paths';
import { createQuery, codecs } from "@pomle/paths";

const searchOptions = createQuery({
query: codecs.string,
Expand All @@ -141,7 +141,7 @@ const searchOptions = createQuery({
Encodes true/false as "0" and "1"

```ts
import { createQuery, codecs } from '@pomle/paths';
import { createQuery, codecs } from "@pomle/paths";

const viewOptions = createQuery({
showAll: codecs.boolean,
Expand All @@ -153,7 +153,7 @@ const viewOptions = createQuery({
Encodes number safely

```ts
import { createQuery, codecs } from '@pomle/paths';
import { createQuery, codecs } from "@pomle/paths";

const searchOptions = createQuery({
pageSize: codecs.number,
Expand All @@ -166,9 +166,9 @@ const searchOptions = createQuery({
Ensures values are in a list of known values. If no match is found, first is returned.

```ts
import { createQuery, codecs } from '@pomle/paths';
import { createQuery, codecs } from "@pomle/paths";

const CAR_TYPES = ['sedan', 'hatchback', 'truck'] as const;
const CAR_TYPES = ["sedan", "hatchback", "truck"] as const;

const carType = codecs.oneOf(CAR_TYPES);

Expand All @@ -182,8 +182,8 @@ const carOptions = createQuery({
Do not encode and decode with `encodeURIComponent` or `decodeURIComponent` manually. It will be handled by the library.

```ts
import { createPath, createCodec } from '@pomle/paths';
import { DateTime } from 'luxon';
import { createPath, createCodec } from "@pomle/paths";
import { DateTime } from "luxon";

const dateCodec = createCodec<DateTime>(
(date) => {
Expand All @@ -194,7 +194,7 @@ const dateCodec = createCodec<DateTime>(
},
);

const bookings = createPath('/bookings/:dayOfArrival', {
const bookings = createPath("/bookings/:dayOfArrival", {
dayOfArrival: dateCodec,
});

Expand Down Expand Up @@ -227,13 +227,13 @@ The `oneOf` codec can take any object that implements `.toString`.
```ts
const MyTypeOne = {
toString() {
return 'one';
return "one";
},
};

const MyTypeTwo = {
toString() {
return 'two';
return "two";
},
};

Expand Down
34 changes: 34 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { defineConfig } from "eslint/config";
import tseslint from "@typescript-eslint/eslint-plugin";
import tsparser from "@typescript-eslint/parser";
import prettier from "eslint-plugin-prettier";
import react from "eslint-plugin-react";

export default defineConfig([
{
files: ["**/*.{js,jsx,ts,tsx}"],
languageOptions: {
parser: tsparser,
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
ecmaFeatures: {
jsx: true,
legacyDecorators: true,
},
},
},
plugins: {
"@typescript-eslint": tseslint,
react,
prettier,
},
settings: {
react: { version: "detect" },
},
rules: {
"prettier/prettier": "error",
},
ignores: ["build/", "dist/", "node_modules/", ".snapshots/", "*.min.js"],
},
]);
6 changes: 0 additions & 6 deletions jest.config.js

This file was deleted.

Loading