Skip to content

Commit 1a5d625

Browse files
authored
[api] default pivots from which partitions can be derived (#10)
1 parent a469455 commit 1a5d625

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

src/pivots/index.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// ['0', (...), '9']
2+
const numbers = Array.from({ length: 10 }, (_, i) => String.fromCharCode(48 + i));
3+
4+
// ['a', (...), 'z']
5+
const alphabet = Array.from({ length: 26 }, (_, i) => String.fromCharCode(97 + i));
6+
7+
/*
8+
azExpand('a') => [
9+
'aa', 'ab', 'ac', 'ad', 'ae',
10+
'af', 'ag', 'ah', 'ai', 'aj',
11+
'ak', 'al', 'am', 'an', 'ao',
12+
'ap', 'aq', 'ar', 'as', 'at',
13+
'au', 'av', 'aw', 'ax', 'ay',
14+
'az'
15+
]
16+
*/
17+
function azExpand(prefix) {
18+
return [
19+
...alphabet.map(c => `${prefix}${c}`)
20+
];
21+
}
22+
23+
// ['a', (...), 'zzz']
24+
const atozzz = alphabet.reduce((acc, a) => {
25+
acc.push(a); // ['a', (...)
26+
27+
azExpand(a)
28+
.forEach(aa => {
29+
acc.push(...azExpand(aa)) // (...) aaa', 'aab', 'aac']
30+
});
31+
32+
return acc;
33+
}, []);
34+
35+
const allPivots = [
36+
null,
37+
/* 0 – 9 */
38+
...numbers,
39+
'@!',
40+
/* @0 – @9 */
41+
...numbers.map(c => `@${c}`),
42+
'@_',
43+
//
44+
// TODO (cjr) must partition @ali__@alj
45+
// [@ali, @alicn, @alifd, @alifd/theme-{???}, @aligov, @aliwind, @alj]
46+
//
47+
/* @a[a-z] - @z[a-z] */
48+
...atozzz.map(cc => `@${cc}`),
49+
//
50+
// TODO (cjr) must partition nod_noe
51+
// entire `node-*` package namespace
52+
//
53+
'@~',
54+
'A',
55+
'Z',
56+
...atozzz,
57+
null
58+
]
59+
60+
const pivots = allPivots;
61+
62+
export {
63+
pivots
64+
}

src/pivots/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@_all_docs/partition",
3+
"version": "0.1.0",
4+
"description": "Default pivots from which _all_docs partitions are derived",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/indexzero/_all_docs.git",
8+
"directory": "src/partition"
9+
},
10+
"author": "Charlie Robbins <npm@charlie.dev>",
11+
"license": "Apache-2.0"
12+
}

0 commit comments

Comments
 (0)