
Product
Rubygems Ecosystem Support Now Generally Available
Socket's Rubygems ecosystem support is moving from beta to GA, featuring enhanced security scanning to detect supply chain threats beyond traditional CVEs in your Ruby dependencies.
@httpland/range-parser
Advanced tools
HTTP Range
header field parser.
Compliant with RFC 9110, 14.2 Range
Parses a string as HTTP Range
header field and yield JavaScript Object.
The field naming conventions follow RFC 9110, 14.2. Range.
import { parse } from "https://deno.land/x/range_parser@$VERSION/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
const actual = parse("bytes=0-100, 200-, -300, test");
assertEquals(actual, {
rangeUnit: "bytes",
rangeSet: [
{ firstPos: 0, lastPos: 100 },
{ firstPos: 200, lastPos: undefined },
{ suffixLength: 300 },
"test",
],
});
rangeSet
is a list of one or more <int-range>
, <suffix-range>
and
<other-range>
according to the definition of <range-spec>
.
It has the following data structure:
interface IntRange {
firstPos: number;
lastPos: number | undefined;
}
interface SuffixRange {
suffixLength: number;
}
type OtherRange = string;
The parser strictly adheres to the ABNF syntax. It also checks semantics.
Specifically, the parser guarantees the following:
<int-range>
or <suffix-range>
number is a non-negative integer<range-unit>
and <other-range>
are syntactically valid strings<int-range>
, <first-pos>
is equal to or greater than <last-pos>
.Throws SyntaxError
if it detects invalid syntax.
import { parse } from "https://deno.land/x/range_parser@$VERSION/mod.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() => parse("<invalid:input>"));
The following cases are semantic error:
<int-range>
, <last-pos>
less than <first-pos>
.see RFC 9110, 14.1.1. Range Specifiers
In this case, it throws a RangeError
.
import { parse } from "https://deno.land/x/range_parser@$VERSION/mod.ts";
import { assertThrows } from "https://deno.land/std/testing/asserts.ts";
assertThrows(() => parse("bytes=1-0"));
We provide some utilities.
Whether the RangeSpec
is IntRange
or not.
import {
type IntRange,
isIntRange,
type OtherRange,
type SuffixRange,
} from "https://deno.land/x/range_parser@$VERSION/mod.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";
declare const intRange: IntRange;
declare const suffixRange: SuffixRange;
declare const otherRange: OtherRange;
assert(isIntRange(intRange));
assert(!isIntRange(suffixRange));
assert(!isIntRange(otherRange));
Whether the RangeSpec
is SuffixRange
or not.
import {
type IntRange,
isSuffixRange,
type OtherRange,
type SuffixRange,
} from "https://deno.land/x/range_parser@$VERSION/mod.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";
declare const intRange: IntRange;
declare const suffixRange: SuffixRange;
declare const otherRange: OtherRange;
assert(isSuffixRange(suffixRange));
assert(!isSuffixRange(intRange));
assert(!isSuffixRange(otherRange));
Whether the RangeSpec
is OtherRange
or not.
import {
type IntRange,
isOtherRange,
type OtherRange,
type SuffixRange,
} from "https://deno.land/x/range_parser@$VERSION/mod.ts";
import { assert } from "https://deno.land/std/testing/asserts.ts";
declare const intRange: IntRange;
declare const suffixRange: SuffixRange;
declare const otherRange: OtherRange;
assert(isOtherRange(otherRange));
assert(!isOtherRange(intRange));
assert(!isOtherRange(suffixRange));
Copyright © 2023-present httpland.
Released under the MIT license
1.0.0-beta.2 (2023-03-09)
FAQs
HTTP Range header field parser
The npm package @httpland/range-parser receives a total of 95 weekly downloads. As such, @httpland/range-parser popularity was classified as not popular.
We found that @httpland/range-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rubygems ecosystem support is moving from beta to GA, featuring enhanced security scanning to detect supply chain threats beyond traditional CVEs in your Ruby dependencies.
Research
The Socket Research Team investigates a malicious npm package that appears to be an Advcash integration but triggers a reverse shell during payment success, targeting servers handling transactions.
Security Fundamentals
The Socket Threat Research Team uncovers how threat actors weaponize shell techniques across npm, PyPI, and Go ecosystems to maintain persistence and exfiltrate data.