mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
std: remove wildcard export in uuid module (denoland/deno#3540)
This commit is contained in:
parent
1239902a03
commit
a682dfcab8
@ -5,11 +5,11 @@ Support for version 1, 3, 4, and 5 UUIDs.
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import uuid, { validate } from "https://deno.land/std/uuid/mod.ts";
|
||||
import { v4 } from "https://deno.land/std/uuid/mod.ts";
|
||||
|
||||
// Generate a v4 uuid
|
||||
const myUUID = uuid();
|
||||
const myUUID = v4.generate();
|
||||
|
||||
// Validate a v4 uuid
|
||||
const isValid = validate(aString);
|
||||
const isValid = v4.validate(aString);
|
||||
```
|
||||
|
16
uuid/mod.ts
16
uuid/mod.ts
@ -1,5 +1,6 @@
|
||||
// Based on https://github.com/kelektiv/node-uuid
|
||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
import * as v4 from "./v4.ts";
|
||||
|
||||
export const NIL_UUID = "00000000-0000-0000-0000-000000000000";
|
||||
|
||||
@ -7,8 +8,13 @@ export function isNil(val: string): boolean {
|
||||
return val === NIL_UUID;
|
||||
}
|
||||
|
||||
const NOT_IMPLEMENTED = (): void => {
|
||||
throw new Error("Not implemented");
|
||||
const NOT_IMPLEMENTED = {
|
||||
generate(): never {
|
||||
throw new Error("Not implemented");
|
||||
},
|
||||
validate(): never {
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
};
|
||||
|
||||
// TODO Implement
|
||||
@ -16,11 +22,7 @@ export const v1 = NOT_IMPLEMENTED;
|
||||
// TODO Implement
|
||||
export const v3 = NOT_IMPLEMENTED;
|
||||
|
||||
import _v4 from "./v4.ts";
|
||||
export const v4 = _v4;
|
||||
export { v4 };
|
||||
|
||||
// TODO Implement
|
||||
export const v5 = NOT_IMPLEMENTED;
|
||||
|
||||
export default v4;
|
||||
export * from "./v4.ts";
|
||||
|
@ -4,7 +4,6 @@ import { runIfMain } from "../testing/mod.ts";
|
||||
|
||||
// Generic Tests
|
||||
import "./tests/isNil.ts";
|
||||
import "./tests/generate.ts";
|
||||
|
||||
// V4 Tests
|
||||
import "./tests/v4/validate.ts";
|
||||
|
@ -1,32 +0,0 @@
|
||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
import { assert, assertEquals } from "../../testing/asserts.ts";
|
||||
import { test } from "../../testing/mod.ts";
|
||||
import mod, { validate, v4 } from "../mod.ts";
|
||||
import { validate as validate4 } from "../v4.ts";
|
||||
|
||||
test({
|
||||
name: "[UUID] uuid_v4",
|
||||
fn(): void {
|
||||
const u = mod();
|
||||
assertEquals(typeof u, "string", "returns a string");
|
||||
assert(u !== "", "return string is not empty");
|
||||
}
|
||||
});
|
||||
|
||||
test({
|
||||
name: "[UUID] uuid_v4_format",
|
||||
fn(): void {
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
const u = mod() as string;
|
||||
assert(validate(u), `${u} is not a valid uuid v4`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test({
|
||||
name: "[UUID] default_is_v4",
|
||||
fn(): void {
|
||||
assertEquals(mod, v4, "default is v4");
|
||||
assertEquals(validate, validate4, "validate is v4");
|
||||
}
|
||||
});
|
@ -1,7 +1,7 @@
|
||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
import { assert, assertEquals } from "../../../testing/asserts.ts";
|
||||
import { test } from "../../../testing/mod.ts";
|
||||
import generate, { validate } from "../../v4.ts";
|
||||
import { generate, validate } from "../../v4.ts";
|
||||
|
||||
test({
|
||||
name: "[UUID] test_uuid_v4",
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
import { assert } from "../../../testing/asserts.ts";
|
||||
import { test } from "../../../testing/mod.ts";
|
||||
import generate, { validate } from "../../v4.ts";
|
||||
import { generate, validate } from "../../v4.ts";
|
||||
|
||||
test({
|
||||
name: "[UUID] is_valid_uuid_v4",
|
||||
|
@ -9,7 +9,7 @@ export function validate(id: string): boolean {
|
||||
return UUID_RE.test(id);
|
||||
}
|
||||
|
||||
export default function generate(): string {
|
||||
export function generate(): string {
|
||||
const rnds = crypto.getRandomValues(new Uint8Array(16));
|
||||
|
||||
rnds[6] = (rnds[6] & 0x0f) | 0x40; // Version 4
|
||||
|
Loading…
Reference in New Issue
Block a user