4
4
*/
5
5
import nanoid from "./mod.ts" ;
6
6
import customAlphabet from "./customAlphabet.ts"
7
- import url from "./url.ts" ;
8
7
import { parse } from "https://deno.land/std/flags/mod.ts" ;
9
8
// import { red, bold } from "https://deno.land/std/fmt/colors.ts";
10
9
11
10
// Grab CLI arguments
12
11
const flags = parse ( Deno . args ) ;
13
-
14
- // Logging functions
15
- const log = async ( message : string , type : Deno . File = Deno . stdin ) => {
16
- const encoder = new TextEncoder ( ) ;
17
- const buf = new Deno . Buffer ( encoder . encode ( message + "\n" ) ) ;
18
- Deno . copy ( Deno . stdout , buf ) ;
19
- } ;
20
12
// const error = (message: string) => log(bold("Error: ") + message, Deno.stderr);
21
-
13
+ console . log ( `nanoid v3.0.0\n------------------` ) ;
22
14
// Display help message, if requested
23
15
if ( flags . h || flags . help ) {
24
- log ( `
16
+ console . log ( `original by Andrey Sitnik
17
+ port for deno by Ian Fabs
18
+
25
19
Usage
26
20
$ nanoid
27
21
Options
@@ -40,12 +34,16 @@ if (flags.h || flags.help) {
40
34
` ) ;
41
35
} else {
42
36
// Check if the alphabet supplied is the same as the default one
43
- const equivalent = ( a : string , b : string ) : boolean => JSON . stringify ( a . split ( '' ) . sort ( ) ) === JSON . stringify ( b . split ( '' ) . sort ( ) ) ;
44
37
const size = flags . s ?? flags . size ;
45
38
const alphabet = flags . a ?? flags . alphabet ;
46
- const id = alphabet && ! equivalent ( alphabet , url ) ? customAlphabet ( alphabet , size ?? 12 ) : nanoid ( size ) ;
47
39
48
- log ( id ) ;
40
+ let id ;
41
+ if ( alphabet )
42
+ id = customAlphabet ( alphabet , size ) ( ) ;
43
+ else
44
+ id = nanoid ( size ) ;
45
+
46
+ console . log ( `\n${ id } \n` ) ;
49
47
}
50
48
51
49
Deno . stdin . close ( ) ;
0 commit comments