Skip to content

Commit

Permalink
feat: export defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
revelt committed Apr 10, 2022
1 parent bccad1c commit ac9dac8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 3 additions & 1 deletion packages/is-relative-uri/README.md
Expand Up @@ -26,12 +26,14 @@

## Install

The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `3.1.0`.
This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required:

```bash
npm i is-relative-uri
```

If you need a legacy version which works with `require`, use version 3.1.0

## Quick Take

```js
Expand Down
10 changes: 5 additions & 5 deletions packages/is-relative-uri/src/main.ts
Expand Up @@ -325,6 +325,10 @@ interface Opts {
flagUpUrisWithSchemes: boolean;
offset: number;
}
const defaults: Opts = {
flagUpUrisWithSchemes: true,
offset: 0,
};

interface Res {
res: boolean;
Expand All @@ -344,10 +348,6 @@ function isRel(str: string, originalOpts?: Partial<Opts>): Res {
`is-relative-uri: [THROW_ID_02] opts be plain object, it was given as ${originalOpts} (type ${typeof originalOpts})`
);
}
let defaults = {
flagUpUrisWithSchemes: true,
offset: 0,
};
let opts: Opts = { ...defaults, ...originalOpts };
if (opts.offset && !Number.isInteger(opts.offset)) {
throw new Error(
Expand Down Expand Up @@ -518,4 +518,4 @@ function isRel(str: string, originalOpts?: Partial<Opts>): Res {
};
}

export { isRel, version };
export { isRel, defaults, version };
3 changes: 2 additions & 1 deletion packages/is-relative-uri/types/index.d.ts
Expand Up @@ -3,10 +3,11 @@ interface Opts {
flagUpUrisWithSchemes: boolean;
offset: number;
}
declare const defaults: Opts;
interface Res {
res: boolean;
message: string | null;
}
declare function isRel(str: string, originalOpts?: Partial<Opts>): Res;

export { isRel, version };
export { defaults, isRel, version };

0 comments on commit ac9dac8

Please sign in to comment.