1 | [npm]: https://img.shields.io/npm/v/enum-chars
|
2 | [npm-url]: https://www.npmjs.com/package/enum-chars
|
3 | [size]: https://packagephobia.now.sh/badge?p=enum-chars
|
4 | [size-url]: https://packagephobia.now.sh/result?p=enum-chars
|
5 |
|
6 | [![npm][npm]][npm-url]
|
7 | [![size][size]][size-url]
|
8 |
|
9 | # enum-chars
|
10 |
|
11 | Enumeration of characters according to template.
|
12 |
|
13 | ### Simple example:
|
14 |
|
15 | ```js
|
16 | import enumChars from 'enum-chars'
|
17 |
|
18 | let i = 0
|
19 | let n = ''
|
20 | while (n.length < 3) {
|
21 | console.log([i, (n = enumChars(n, 2))])
|
22 | i++
|
23 | }
|
24 | /* RETURNS in console.log: */
|
25 | ;[0, '00']
|
26 | ;[1, '01']
|
27 | // ...
|
28 | ;[593, '9z']
|
29 | ;[594, '9A']
|
30 | // ...
|
31 | ;[3843, 'ZZ']
|
32 | ;[3844, '000']
|
33 | // END
|
34 | ```
|
35 |
|
36 | ## Install
|
37 |
|
38 | Using npm:
|
39 |
|
40 | ```console
|
41 | npm install enum-chars
|
42 | ```
|
43 |
|
44 | or
|
45 |
|
46 | ```console
|
47 | yarn add enum-chars
|
48 | ```
|
49 |
|
50 | ## Usage
|
51 |
|
52 | #### enumChars(word = ``, min = 1, pattern = `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`)
|
53 |
|
54 | #### enumChars.numbers(word = ``, min = 1, pattern = `0123456789`)
|
55 |
|
56 | #### enumChars.lowers(word = ``, min = 1, pattern = `abcdefghijklmnopqrstuvwxyz`)
|
57 |
|
58 | #### enumChars.uppers(word = ``, min = 1, pattern = `ABCDEFGHIJKLMNOPQRSTUVWXYZ`)
|
59 |
|
60 | ```js
|
61 | import enumChars from 'enum-chars'
|
62 |
|
63 | let w = 'abc'
|
64 | for (let i = 0; i < 20000; i++) {
|
65 | w = enumChars(w, 1, 'abcdefghijklmnopqrstuvwxyz')
|
66 | console.log([i, w])
|
67 | }
|
68 | /* RETURNS in console.log: */
|
69 | ;[0, 'abd']
|
70 | ;[1, 'abe']
|
71 | // ...
|
72 | ;[22, 'abz']
|
73 | ;[23, 'aca']
|
74 | // ...
|
75 | ;[17545, 'zzy']
|
76 | ;[17546, 'zzz']
|
77 | ;[17547, 'aaaa']
|
78 | ;[17548, 'aaab']
|
79 | // ...
|
80 |
|
81 | // Min word size:
|
82 | console.log(enumChars.uppers('', 10)) // AAAAAAAAAA
|
83 | console.log(enumChars.uppers('ABC', 10)) // ABDAAAAAAA
|
84 | console.log(enumChars.uppers('AAAAAAAAAA', 10)) // AAAAAAAAAB
|
85 |
|
86 | // Example of working with a binary system
|
87 | let n = ''
|
88 | for (let i = 0; i < 257; i++) {
|
89 | n = enumChars(n, 8, '01')
|
90 | console.log([i, n, parseInt(n, 2)])
|
91 | }
|
92 | /* RETURNS in console.log: */
|
93 | ;[0, '00000000', 0]
|
94 | ;[1, '00000001', 1]
|
95 | ;[2, '00000010', 2]
|
96 | ;[3, '00000011', 3]
|
97 | // ...
|
98 | ;[254, '11111110', 254]
|
99 | ;[255, '11111111', 255]
|
100 | ;[256, '000000000', 0]
|
101 | ```
|
102 |
|
103 | ## Meta
|
104 |
|
105 | [LICENSE (MIT)](/LICENSE)
|