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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
rules: {
"arrow-parens": ["error", "as-needed"],
"no-sparse-arrays": 0,
"no-unused-vars": 0,
"padding-line-between-statements": [
"error",
{ blankLine: "always", prev: "*", next: "export" },
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ index.umd.js
**/*.d.ts
.coverage
docs/dist
!*.interface.d.ts
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ document.js
ignore.js
indexReadme.js
jest.config.js
mappings.js
normalizeLineEndings.js
package-lock.json
regenerate.js
Expand Down
183 changes: 157 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1113,36 +1113,167 @@ Computes a difference between two objects.

#### base64url

Provides a way to encode strings and bytes from and into Base64URL.
##### decode

##### Type signature
Decodes the given Base64URL back into string.

###### Type signature

<!-- prettier-ignore-start -->
```typescript
{
decode: (text: string, context?: DecodeContext) => string;
decodeBytes: (
text: string,
context?: {
atob: (byteString: string) => string;
TextDecoder: new (encoding: string) => {
decode: (input?: Uint8Array) => string;
};
}
) => number[];
encode: (
text: string,
context?: {
btoa: (byteString: string) => string;
TextEncoder: new () => {
encode: (input?: string) => Uint8Array;
};
}
) => string;
encodeBytes: (bytes: number[], context?: EncodeContext) => string;
fromByteString: (byteString: string) => number[];
toByteString: (bytes: number[]) => string;
}
(text: string, context?: DecodeContext) => string
```
<!-- prettier-ignore-end -->

###### Examples

<!-- prettier-ignore-start -->
```javascript
decode("PDw_Pz8-Pg"); // ⇒ "<<???>>"
```
<!-- prettier-ignore-end -->

##### decodeBytes

Decodes the given Base64URL back into byte array.

###### Type signature

<!-- prettier-ignore-start -->
```typescript
(text: string, context?: DecodeContext) => number[]
```
<!-- prettier-ignore-end -->

###### Examples

<!-- prettier-ignore-start -->
```javascript
decodeBytes("w4Jnw6vCp20-bBsQfA");
// ⇒ [0xc2, 0x67, 0xeb, 0xa7, 0x6d, 0x3e, 0x6c, 0x1b, 0x10, 0x7c]
```
<!-- prettier-ignore-end -->

##### encode

Encodes the given string into Base64URL.

###### Type signature

<!-- prettier-ignore-start -->
```typescript
(text: string, context?: EncodeContext) => string
```
<!-- prettier-ignore-end -->

###### Examples

<!-- prettier-ignore-start -->
```javascript
encode("<<???>>"); // ⇒ "PDw_Pz8-Pg"
```
<!-- prettier-ignore-end -->

##### encodeBytes

Encodes the given bytes into Base64URL.

###### Type signature

<!-- prettier-ignore-start -->
```typescript
(bytes: number[], context?: EncodeContext) => string
```
<!-- prettier-ignore-end -->

###### Examples

<!-- prettier-ignore-start -->
```javascript
encodeBytes([0xc2, 0x67, 0xeb, 0xa7, 0x6d, 0x3e, 0x6c, 0x1b, 0x10, 0x7c]);
// ⇒ "w4Jnw6vCp20-bBsQfA"
```
<!-- prettier-ignore-end -->

##### fromBase64

Converts Base64 string into Base64URL one.

###### Type signature

<!-- prettier-ignore-start -->
```typescript
(base64: string) => string
```
<!-- prettier-ignore-end -->

###### Examples

<!-- prettier-ignore-start -->
```javascript
fromBase64("PDw/Pz8+Pg=="); // ⇒ "PDw_Pz8-Pg"
```
<!-- prettier-ignore-end -->

##### toBase64

Converts Base64URL string into Base64 one.

###### Type signature

<!-- prettier-ignore-start -->
```typescript
(base64Url: string) => string
```
<!-- prettier-ignore-end -->

###### Examples

<!-- prettier-ignore-start -->
```javascript
toBase64("PDw_Pz8-Pg"); // ⇒ "PDw/Pz8+Pg=="
```
<!-- prettier-ignore-end -->

#### byteString

##### from

Converts string to byte array.

###### Type signature

<!-- prettier-ignore-start -->
```typescript
(byteString: string) => number[]
```
<!-- prettier-ignore-end -->

###### Examples

<!-- prettier-ignore-start -->
```javascript
from("PQR"); // ⇒ [80, 81, 82]
```
<!-- prettier-ignore-end -->

##### to

Coverts byte array to string.

###### Type signature

<!-- prettier-ignore-start -->
```typescript
(bytes: number[]) => string
```
<!-- prettier-ignore-end -->

###### Examples

<!-- prettier-ignore-start -->
```javascript
to([0x50, 0x51, 0x52]); // ⇒ "PQR"
```
<!-- prettier-ignore-end -->

Expand Down
4 changes: 2 additions & 2 deletions compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import path from "path";
import os from "os";
import pQueue from "p-queue";

import ignored from "./ignore.js";

const CONCURRENCY = Math.max(1, os.cpus().length - 1);

const { default: PQueue } = pQueue;

const execAsync = promisify(exec);

import ignored from "./ignore.js";

const [sourceIgnoredFiles, ignoredDirectories] = ignored;

const ignoredFiles = sourceIgnoredFiles.filter(x => x !== "index.ts");
Expand Down
2 changes: 0 additions & 2 deletions docs/scripts/docs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-env browser */

// eslint-disable-next-line no-unused-vars
function tryInREPL(event, scope) {
var target = event.target;
var isReplRun = target.matches(".btn-repl");
Expand All @@ -25,7 +24,6 @@ function tryInREPL(event, scope) {
});
}

// eslint-disable-next-line no-unused-vars
function toggleTableOfContents() {
var className = "toc-active";

Expand Down
7 changes: 2 additions & 5 deletions document.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { promises, existsSync } from "fs";
import path from "path";

import ignored from "./ignore.js";
import mappings from "./mappings.js";

const template = ({ name, description, signature, examples, questions }) => {
let content = `# ${name}
Expand Down Expand Up @@ -82,11 +83,7 @@ const {

const [, , cwd = process.cwd()] = process.argv;

const mapping = {
function: "_function"
};

const identifier = name => mapping[name] || name;
const identifier = name => mappings[name] || name;

// Do not match type definition files *.d.ts but match *.ts:
// https://stackoverflow.com/a/43493203/1384679
Expand Down
Loading