Skip to content

Commit

Permalink
Merge pull request #2 from httpland/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
TomokiMiyauci committed Apr 29, 2023
2 parents 50e5693 + cbc5ef9 commit c57efdb
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 151 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [1.0.1-beta.1](https://github.com/httpland/accept-ranges-parser/compare/1.0.0...1.0.1-beta.1) (2023-04-29)


### Bug Fixes

* **parse:** accept list what includes empty element ([8dea1c5](https://github.com/httpland/accept-ranges-parser/commit/8dea1c5defe575b866ffb22b2a51cd468dbc00a3))

# 1.0.0 (2023-03-27)


Expand Down
23 changes: 19 additions & 4 deletions _tools/meta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BuildOptions } from "https://deno.land/x/dnt@0.33.1/mod.ts";
import { BuildOptions } from "https://deno.land/x/dnt@0.34.0/mod.ts";

export const makeOptions = (version: string): BuildOptions => ({
test: false,
Expand Down Expand Up @@ -37,10 +37,25 @@ export const makeOptions = (version: string): BuildOptions => ({
},
packageManager: "pnpm",
mappings: {
"https://deno.land/x/isx@1.1.0/is_string.ts": {
"https://deno.land/x/isx@1.3.1/is_string.ts": {
name: "@miyauci/isx",
version: "1.1.0",
subPath: "is_string",
version: "1.3.1",
subPath: "is_string.js",
},
"https://deno.land/x/isx@1.3.1/iterable/is_not_empty.ts": {
name: "@miyauci/isx",
version: "1.3.1",
subPath: "iterable/is_not_empty.js",
},
"https://deno.land/x/http_utils@1.2.0/token.ts": {
name: "@httpland/http-utils",
version: "1.2.0",
subPath: "token.js",
},
"https://deno.land/x/http_utils@1.2.0/list.ts": {
name: "@httpland/http-utils",
version: "1.2.0",
subPath: "list.js",
},
},
});
13 changes: 7 additions & 6 deletions _tools/publish_npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ if (import.meta.main) {
const tag = isPrerelease?.[0] ?? "latest";

const pkg = makeOptions(version);
const result = await Deno.run({
cmd: ["npm", "publish", pkg.outDir, "--tag", String(tag)],
stdout: "piped",
})
.output();
const command = new Deno.Command("npm", {
args: ["publish", pkg.outDir, "--tag", String(tag)],
});
const result = await command.output();

console.log(new TextDecoder().decode(result));
if (!result.success) {
console.error(new TextDecoder().decode(result.stderr));
}
}
9 changes: 8 additions & 1 deletion deno.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
"https://deno.land/std@0.181.0/testing/_test_suite.ts": "30f018feeb3835f12ab198d8a518f9089b1bcb2e8c838a8b615ab10d5005465c",
"https://deno.land/std@0.181.0/testing/asserts.ts": "e16d98b4d73ffc4ed498d717307a12500ae4f2cbe668f1a215632d19fcffc22f",
"https://deno.land/std@0.181.0/testing/bdd.ts": "c5ca6d85940dbcc19b4d2bc3608d49ab65d81470aa91306d5efa4b0d5c945731",
"https://deno.land/x/isx@1.1.0/is_string.ts": "268254eab5f8dbc09ee879eb53675813cdc5350207dde436d457cb34462cc857"
"https://deno.land/x/http_utils@1.2.0/deps.ts": "ea68a335c0f6c1bf9fb9db271c453e78fd51d6902614db438b2bae3ab6114552",
"https://deno.land/x/http_utils@1.2.0/list.ts": "eb0820f10b828de9964626546fef15ca82008323633df24e9e362e0bf76ef4f5",
"https://deno.land/x/http_utils@1.2.0/token.ts": "fa313f85544a23efef35964c56fcb7af2139307874e9d019607a85a0f2145c6f",
"https://deno.land/x/isx@1.1.0/is_string.ts": "268254eab5f8dbc09ee879eb53675813cdc5350207dde436d457cb34462cc857",
"https://deno.land/x/isx@1.3.1/is_null.ts": "02b30255073843d001e715a04382f1d6aebd77ed5506ffbb44bf77b9e20ebf7d",
"https://deno.land/x/isx@1.3.1/is_string.ts": "268254eab5f8dbc09ee879eb53675813cdc5350207dde436d457cb34462cc857",
"https://deno.land/x/isx@1.3.1/iterable/is_not_empty.ts": "6f9139c8cc89745add8c880f4aec0359ed8da19842287b409c9e62d1ccd292a7",
"https://deno.land/x/prelude_js@1.2.0/trim.ts": "9e839053220bee1c5673026ccf4ddba475c3b982b3284b1d6b86e5440821de61"
}
}
82 changes: 7 additions & 75 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,10 @@
// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
// This module is browser compatible.

export { isString } from "https://deno.land/x/isx@1.1.0/is_string.ts";

// TODO:(miyauci) Packaging and externalization this module.

/** Types for uppercase letter. */
export type UppercaseLetter =
| "A"
| "B"
| "C"
| "D"
| "E"
| "F"
| "G"
| "H"
| "I"
| "J"
| "K"
| "L"
| "M"
| "N"
| "O"
| "P"
| "Q"
| "R"
| "S"
| "T"
| "U"
| "V"
| "W"
| "X"
| "Y"
| "Z";

/** Types for lowercase letter. */
export type LowercaseLetter = Lowercase<UppercaseLetter>;

/** Types for letter. */
export type Letter = UppercaseLetter | LowercaseLetter;

/** Types for digit. */
export type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;

/** Deserialize types. */
export type Stringify<
T extends string | number | bigint | boolean | null | undefined,
> = `${T}`;

/** Representation of [`<DIGIT>`](https://www.rfc-editor.org/rfc/rfc5234#appendix-B.1). */
export type DIGIT = Stringify<Digit>;

/** Representation of [`<ALPHA>`](https://www.rfc-editor.org/rfc/rfc5234#appendix-B.1). */
export type ALPHA = Letter;

/** Representation of [`<tchar>`](https://www.rfc-editor.org/rfc/rfc9110#section-5.6.2-2). */
export type TChar =
| "!"
| "#"
| "$"
| "%"
| "&"
| "'"
| "*"
| "+"
| "-"
| "."
| "^"
| "_"
| "`"
| "|"
| "~"
| ALPHA
| DIGIT;

/** Representation of [`<token>`](https://www.rfc-editor.org/rfc/rfc9110#section-5.6.2-2). */
export type Token = `${TChar}${string}`;
export { isString } from "https://deno.land/x/isx@1.3.1/is_string.ts";
export { isNotEmpty } from "https://deno.land/x/isx@1.3.1/iterable/is_not_empty.ts";
export {
isToken,
type Token,
} from "https://deno.land/x/http_utils@1.2.0/token.ts";
export { parseListFields } from "https://deno.land/x/http_utils@1.2.0/list.ts";
14 changes: 6 additions & 8 deletions parse.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023-latest the httpland authors. All rights reserved. MIT license.
// This module is browser compatible.

import { isTokenFormat } from "./utils.ts";
import { isNotEmpty, isToken, parseListFields } from "./deps.ts";
import { Msg } from "./constants.ts";
import type { AcceptRanges } from "./types.ts";

Expand All @@ -18,15 +18,13 @@ import type { AcceptRanges } from "./types.ts";
* @throws {SyntaxError} If the input is invalid [`<Accept-Ranges>`](https://www.rfc-editor.org/rfc/rfc9110.html#section-14.3-2) syntax.
*/
export function parseAcceptRanges(input: string): AcceptRanges {
const acceptableRanges = input
.trim()
.split(",")
.map((v) => v.trim());
const acceptableRanges = parseListFields(input);
const msg = `${Msg.InvalidSyntax} "${input}"`;

if (!isNotEmpty(acceptableRanges)) throw new SyntaxError(msg);

acceptableRanges.forEach((token) => {
if (!isTokenFormat(token)) {
throw SyntaxError(`${Msg.InvalidSyntax} "${input}"`);
}
if (!isToken(token)) throw new SyntaxError(msg);
});

return acceptableRanges as AcceptRanges;
Expand Down
3 changes: 1 addition & 2 deletions parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ describe("parseAcceptRanges", () => {
",",
",,,",
", , ,",
"a,",
"a, , a",
"あ",
"a, あ",
`""`,
Expand All @@ -38,6 +36,7 @@ describe("parseAcceptRanges", () => {
[" abc ", ["abc"]],
["abc, def", ["abc", "def"]],
["bytes,none", ["bytes", "none"]],
["bytes, ,,none", ["bytes", "none"]],
];

table.forEach(([input, expected]) => {
Expand Down
5 changes: 2 additions & 3 deletions stringify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { isString } from "./deps.ts";
import { isTokenFormat } from "./utils.ts";
import { isString, isToken } from "./deps.ts";
import { Msg } from "./constants.ts";

/** Serialize string of array into string.
Expand All @@ -20,7 +19,7 @@ export function stringifyAcceptRanges(
const targets = isString(acceptRanges) ? [acceptRanges] : acceptRanges;

targets.forEach((rangeUnit) => {
if (!isTokenFormat(rangeUnit)) {
if (!isToken(rangeUnit)) {
throw TypeError(`${Msg.InvalidRangeUnit} "${rangeUnit}"`);
}
});
Expand Down
21 changes: 0 additions & 21 deletions utils.ts

This file was deleted.

31 changes: 0 additions & 31 deletions utils_test.ts

This file was deleted.

0 comments on commit c57efdb

Please sign in to comment.