Skip to content

Commit

Permalink
docs(std): version all imports in README (denoland#7442)
Browse files Browse the repository at this point in the history
Use $STD_VERSION in std/ README files to automatically
display proper version.
  • Loading branch information
tokiedokie committed Oct 4, 2020
1 parent ec96323 commit 3d65177
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 68 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ deno run https://deno.land/std/examples/welcome.ts
Or a more complex one:

```sh
import { serve } from "https://deno.land/std@0.69.0/http/server.ts";
import { serve } from "https://deno.land/std@$STD_VERSION/http/server.ts";
const s = serve({ port: 8000 });
console.log("http:https://localhost:8000/");
for await (const req of s) {
Expand Down
8 changes: 4 additions & 4 deletions std/archive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Tar

```ts
import { Tar } from "https://deno.land/std/archive/tar.ts";
import { Tar } from "https://deno.land/std@$STD_VERSION/archive/tar.ts";

const tar = new Tar();
const content = new TextEncoder().encode("Deno.land");
Expand All @@ -27,9 +27,9 @@ writer.close();
## Untar

```ts
import { Untar } from "https://deno.land/std/archive/tar.ts";
import { ensureFile } from "https://deno.land/std/fs/ensure_file.ts";
import { ensureDir } from "https://deno.land/std/fs/ensure_dir.ts";
import { Untar } from "https://deno.land/std@$STD_VERSION/archive/tar.ts";
import { ensureFile } from "https://deno.land/std@$STD_VERSION/fs/ensure_file.ts";
import { ensureDir } from "https://deno.land/std@$STD_VERSION/fs/ensure_dir.ts";

const reader = await Deno.open("./out.tar", { read: true });
const untar = new Untar(reader);
Expand Down
14 changes: 7 additions & 7 deletions std/bytes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ All the following functions are exposed in `mod.ts`.
Find first index of binary pattern from given binary array.

```typescript
import { findIndex } from "https://deno.land/std/bytes/mod.ts";
import { findIndex } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

findIndex(
new Uint8Array([1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 3]),
Expand All @@ -26,7 +26,7 @@ findIndex(
Find last index of binary pattern from given binary array.

```typescript
import { findLastIndex } from "https://deno.land/std/bytes/mod.ts";
import { findLastIndex } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

findLastIndex(
new Uint8Array([0, 1, 2, 0, 1, 2, 0, 1, 3]),
Expand All @@ -41,7 +41,7 @@ findLastIndex(
Check whether given binary arrays are equal to each other.

```typescript
import { equal } from "https://deno.land/std/bytes/mod.ts";
import { equal } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

equal(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 3])); // returns true
equal(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 4])); // returns false
Expand All @@ -52,7 +52,7 @@ equal(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 4])); // returns fa
Check whether binary array has binary prefix.

```typescript
import { hasPrefix } from "https://deno.land/std/bytes/mod.ts";
import { hasPrefix } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

hasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([0, 1])); // returns true
hasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([1, 2])); // returns false
Expand All @@ -63,7 +63,7 @@ hasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([1, 2])); // returns false
Repeat bytes of given binary array and return new one.

```typescript
import { repeat } from "https://deno.land/std/bytes/mod.ts";
import { repeat } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

repeat(new Uint8Array([1]), 3); // returns Uint8Array(3) [ 1, 1, 1 ]
```
Expand All @@ -73,7 +73,7 @@ repeat(new Uint8Array([1]), 3); // returns Uint8Array(3) [ 1, 1, 1 ]
Concatenate two binary arrays and return new one.

```typescript
import { concat } from "https://deno.land/std/bytes/mod.ts";
import { concat } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

concat(new Uint8Array([1, 2]), new Uint8Array([3, 4])); // returns Uint8Array(4) [ 1, 2, 3, 4 ]
```
Expand All @@ -83,7 +83,7 @@ concat(new Uint8Array([1, 2]), new Uint8Array([3, 4])); // returns Uint8Array(4)
Copy bytes from one binary array to another.

```typescript
import { copyBytes } from "https://deno.land/std/bytes/mod.ts";
import { copyBytes } from "https://deno.land/std@$STD_VERSION/bytes/mod.ts";

const dst = new Uint8Array(4);
const src = Uint8Array.of(1, 2, 3, 4);
Expand Down
8 changes: 4 additions & 4 deletions std/datetime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ are supported:
Takes an input `string` and a `formatString` to parse to a `date`.

```ts
import { parse } from 'https://deno.land/std/datetime/mod.ts'
import { parse } from 'https://deno.land/std@0.69.0/datetime/mod.ts'

parse("20-01-2019", "dd-MM-yyyy") // output : new Date(2019, 0, 20)
parse("2019-01-20", "yyyy-MM-dd") // output : new Date(2019, 0, 20)
Expand All @@ -54,7 +54,7 @@ parse("01-20-2019 16:34:23.123", "MM-dd-yyyy HH:mm:ss.SSS") // output : new Date
Takes an input `date` and a `formatString` to format to a `string`.

```ts
import { format } from "https://deno.land/std/datetime/mod.ts";
import { format } from "https://deno.land/std@$STD_VERSION/datetime/mod.ts";

format(new Date(2019, 0, 20), "dd-MM-yyyy"); // output : "20-01-2019"
format(new Date(2019, 0, 20), "yyyy-MM-dd"); // output : "2019-01-20"
Expand All @@ -71,7 +71,7 @@ format(new Date(2019, 0, 20), "'today:' yyyy-MM-dd"); // output : "today: 2019-0
Returns the number of the day in the year.

```ts
import { dayOfYear } from "https://deno.land/std/datetime/mod.ts";
import { dayOfYear } from "https://deno.land/std@$STD_VERSION/datetime/mod.ts";

dayOfYear(new Date("2019-03-11T03:24:00")); // output: 70
```
Expand All @@ -81,7 +81,7 @@ dayOfYear(new Date("2019-03-11T03:24:00")); // output: 70
Returns the ISO week number of the provided date (1-53).

```ts
import { weekOfYear } from "https://deno.land/std/datetime/mod.ts";
import { weekOfYear } from "https://deno.land/std@$STD_VERSION/datetime/mod.ts";

weekOfYear(new Date("2020-12-28T03:24:00")); // Returns 53
```
29 changes: 22 additions & 7 deletions std/encoding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function is as follows:
### Usage

```ts
import { parse } from "https://deno.land/std/encoding/csv.ts";
import { parse } from "https://deno.land/std@$STD_VERSION/encoding/csv.ts";
const string = "a,b,c\nd,e,f";

console.log(
Expand Down Expand Up @@ -187,7 +187,10 @@ will output:
### Basic usage

```ts
import { parse, stringify } from "https://deno.land/std/encoding/toml.ts";
import {
parse,
stringify,
} from "https://deno.land/std@$STD_VERSION/encoding/toml.ts";
const obj = {
bin: [
{ name: "deno", path: "cli/main.rs" },
Expand Down Expand Up @@ -236,7 +239,10 @@ Heavily inspired from [js-yaml].
string.

```ts
import { parse, stringify } from "https://deno.land/std/encoding/yaml.ts";
import {
parse,
stringify,
} from "https://deno.land/std@$STD_VERSION/encoding/yaml.ts";

const data = parse(`
foo: bar
Expand All @@ -260,7 +266,7 @@ If your YAML contains multiple documents in it, you can use `parseAll` for
handling it.

```ts
import { parseAll } from "https://deno.land/std/encoding/yaml.ts";
import { parseAll } from "https://deno.land/std@$STD_VERSION/encoding/yaml.ts";

const data = parseAll(`
---
Expand Down Expand Up @@ -312,7 +318,10 @@ for Deno.
decodes the given RFC4648 base32 representation to a `Uint8Array`.

```ts
import { decode, encode } from "https://deno.land/std/encoding/base32.ts";
import {
decode,
encode,
} from "https://deno.land/std@$STD_VERSION/encoding/base32.ts";

const b32Repr = "RC2E6GA=";

Expand All @@ -334,7 +343,10 @@ Ascii85/base85 encoder and decoder with support for multiple standards.
decodes the given ascii85 representation to a `Uint8Array`.

```ts
import { decode, encode } from "https://deno.land/std/encoding/ascii85.ts";
import {
decode,
encode,
} from "https://deno.land/std@$STD_VERSION/encoding/ascii85.ts";

const a85Repr = "LpTqp";

Expand Down Expand Up @@ -363,7 +375,10 @@ supported by other encodings.)
encoding examples:

```ts
import { decode, encode } from "https://deno.land/std/encoding/ascii85.ts";
import {
decode,
encode,
} from "https://deno.land/std@$STD_VERSION/encoding/ascii85.ts";
const binaryData = new Uint8Array([136, 180, 79, 24]);
console.log(encode(binaryData));
// => LpTqp
Expand Down
4 changes: 2 additions & 2 deletions std/flags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Command line arguments parser for Deno based on minimist.
# Example

```ts
import { parse } from "https://deno.land/std/flags/mod.ts";
import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";

console.dir(parse(Deno.args));
```
Expand Down Expand Up @@ -56,7 +56,7 @@ options can be:
example:
```ts
// $ deno run example.ts -- a arg1
import { parse } from "https://deno.land/std/flags/mod.ts";
import { parse } from "https://deno.land/std@$STD_VERSION/flags/mod.ts";
console.dir(parse(Deno.args, { "--": false }));
// output: { _: [ "a", "arg1" ] }
console.dir(parse(Deno.args, { "--": true }));
Expand Down
34 changes: 23 additions & 11 deletions std/fs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ is not empty. If the directory does not exist, it is created. The directory
itself is not deleted.

```ts
import { emptyDir, emptyDirSync } from "https://deno.land/std/fs/mod.ts";
import {
emptyDir,
emptyDirSync,
} from "https://deno.land/std@$STD_VERSION/fs/mod.ts";

emptyDir("./foo"); // returns a promise
emptyDirSync("./foo"); // void
Expand All @@ -26,7 +29,10 @@ Ensures that the directory exists. If the directory structure does not exist, it
is created. Like `mkdir -p`.

```ts
import { ensureDir, ensureDirSync } from "https://deno.land/std/fs/mod.ts";
import {
ensureDir,
ensureDirSync,
} from "https://deno.land/std@$STD_VERSION/fs/mod.ts";

ensureDir("./bar"); // returns a promise
ensureDirSync("./ensureDirSync"); // void
Expand All @@ -39,7 +45,10 @@ directories that do not exist, these directories are created. If the file
already exists, it is **NOT MODIFIED**.

```ts
import { ensureFile, ensureFileSync } from "https://deno.land/std/fs/mod.ts";
import {
ensureFile,
ensureFileSync,
} from "https://deno.land/std@$STD_VERSION/fs/mod.ts";

ensureFile("./folder/targetFile.dat"); // returns promise
ensureFileSync("./folder/targetFile.dat"); // void
Expand All @@ -54,7 +63,7 @@ created.
import {
ensureSymlink,
ensureSymlinkSync,
} from "https://deno.land/std/fs/mod.ts";
} from "https://deno.land/std@$STD_VERSION/fs/mod.ts";

ensureSymlink("./folder/targetFile.dat", "./folder/targetFile.link.dat"); // returns promise
ensureSymlinkSync("./folder/targetFile.dat", "./folder/targetFile.link.dat"); // void
Expand All @@ -65,7 +74,7 @@ ensureSymlinkSync("./folder/targetFile.dat", "./folder/targetFile.link.dat"); //
Detects and format the passed string for the targeted End Of Line character.

```ts
import { format, detect, EOL } from "https://deno.land/std/fs/mod.ts";
import { format, detect, EOL } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";

const CRLFinput = "deno\r\nis not\r\nnode";
const Mixedinput = "deno\nis not\r\nnode";
Expand All @@ -86,7 +95,10 @@ format(CRLFinput, EOL.LF); // output "deno\nis not\nnode"
Test whether or not the given path exists by checking with the file system.

```ts
import { exists, existsSync } from "https://deno.land/std/fs/mod.ts";
import {
exists,
existsSync,
} from "https://deno.land/std@$STD_VERSION/fs/mod.ts";

exists("./foo"); // returns a Promise<boolean>
existsSync("./foo"); // returns boolean
Expand All @@ -97,7 +109,7 @@ existsSync("./foo"); // returns boolean
Moves a file or directory. Overwrites it if option provided.

```ts
import { move, moveSync } from "https://deno.land/std/fs/mod.ts";
import { move, moveSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";

move("./foo", "./bar"); // returns a promise
moveSync("./foo", "./bar"); // void
Expand All @@ -110,7 +122,7 @@ moveSync("./foo", "./existingFolder", { overwrite: true });
copy a file or directory. Overwrites it if option provided.

```ts
import { copy, copySync } from "https://deno.land/std/fs/mod.ts";
import { copy, copySync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";

copy("./foo", "./bar"); // returns a promise
copySync("./foo", "./bar"); // void
Expand All @@ -123,7 +135,7 @@ copySync("./foo", "./existingFolder", { overwrite: true });
Iterate all files in a directory recursively.

```ts
import { walk, walkSync } from "https://deno.land/std/fs/mod.ts";
import { walk, walkSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";

for (const entry of walkSync(".")) {
console.log(entry.path);
Expand All @@ -145,7 +157,7 @@ Expand the glob string from the specified `root` directory and yield each result
as a `WalkEntry` object.

```ts
import { expandGlob } from "https://deno.land/std/fs/mod.ts";
import { expandGlob } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";

for await (const file of expandGlob("**/*.ts")) {
console.log(file);
Expand All @@ -157,7 +169,7 @@ for await (const file of expandGlob("**/*.ts")) {
Synchronous version of `expandGlob()`.

```ts
import { expandGlobSync } from "https://deno.land/std/fs/mod.ts";
import { expandGlobSync } from "https://deno.land/std@$STD_VERSION/fs/mod.ts";

for (const file of expandGlobSync("**/*.ts")) {
console.log(file);
Expand Down
10 changes: 5 additions & 5 deletions std/hash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
You can create a new Hasher instance by calling `createHash` defined in mod.ts.

```ts
import { createHash } from "https://deno.land/std/hash/mod.ts";
import { createHash } from "https://deno.land/std@$STD_VERSION/hash/mod.ts";

const hash = createHash("md5");
// ...
Expand All @@ -19,7 +19,7 @@ You can use `update` method to feed data into your hash instance. Call `digest`
method to retrive final hash value in ArrayBuffer.

```ts
import { createHash } from "https://deno.land/std/hash/mod.ts";
import { createHash } from "https://deno.land/std@$STD_VERSION/hash/mod.ts";

const hash = createHash("md5");
hash.update("Your data here");
Expand All @@ -30,7 +30,7 @@ Please note that `digest` invalidates the hash instance's internal state.
Calling `digest` more than once will throw an Error.

```ts
import { createHash } from "https://deno.land/std/hash/mod.ts";
import { createHash } from "https://deno.land/std@$STD_VERSION/hash/mod.ts";

const hash = createHash("md5");
hash.update("Your data here");
Expand All @@ -44,15 +44,15 @@ format.
Supported formats are `hex` and `base64` and default format is `hex`.

```ts
import { createHash } from "https://deno.land/std/hash/mod.ts";
import { createHash } from "https://deno.land/std@$STD_VERSION/hash/mod.ts";

const hash = createHash("md5");
hash.update("Your data here");
const hashInHex = hash.toString(); // returns 5fe084ee423ff7e0c7709e9437cee89d
```

```ts
import { createHash } from "https://deno.land/std/hash/mod.ts";
import { createHash } from "https://deno.land/std@$STD_VERSION/hash/mod.ts";

const hash = createHash("md5");
hash.update("Your data here");
Expand Down
Loading

0 comments on commit 3d65177

Please sign in to comment.