Skip to content

Commit 884916a

Browse files
committed
refactor(gitbook-treeview): refactor some implements of this plugin
1 parent 65ba4d5 commit 884916a

File tree

3 files changed

+505
-564
lines changed

3 files changed

+505
-564
lines changed

lib/entity.js

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
module.exports = {
2+
34: 'quot',
3+
38: 'amp',
4+
39: 'apos',
5+
60: 'lt',
6+
62: 'gt',
7+
160: 'nbsp',
8+
161: 'iexcl',
9+
162: 'cent',
10+
163: 'pound',
11+
164: 'curren',
12+
165: 'yen',
13+
166: 'brvbar',
14+
167: 'sect',
15+
168: 'uml',
16+
169: 'copy',
17+
170: 'ordf',
18+
171: 'laquo',
19+
172: 'not',
20+
173: 'shy',
21+
174: 'reg',
22+
175: 'macr',
23+
176: 'deg',
24+
177: 'plusmn',
25+
178: 'sup2',
26+
179: 'sup3',
27+
180: 'acute',
28+
181: 'micro',
29+
182: 'para',
30+
183: 'middot',
31+
184: 'cedil',
32+
185: 'sup1',
33+
186: 'ordm',
34+
187: 'raquo',
35+
188: 'frac14',
36+
189: 'frac12',
37+
190: 'frac34',
38+
191: 'iquest',
39+
192: 'Agrave',
40+
193: 'Aacute',
41+
194: 'Acirc',
42+
195: 'Atilde',
43+
196: 'Auml',
44+
197: 'Aring',
45+
198: 'AElig',
46+
199: 'Ccedil',
47+
200: 'Egrave',
48+
201: 'Eacute',
49+
202: 'Ecirc',
50+
203: 'Euml',
51+
204: 'Igrave',
52+
205: 'Iacute',
53+
206: 'Icirc',
54+
207: 'Iuml',
55+
208: 'ETH',
56+
209: 'Ntilde',
57+
210: 'Ograve',
58+
211: 'Oacute',
59+
212: 'Ocirc',
60+
213: 'Otilde',
61+
214: 'Ouml',
62+
215: 'times',
63+
216: 'Oslash',
64+
217: 'Ugrave',
65+
218: 'Uacute',
66+
219: 'Ucirc',
67+
220: 'Uuml',
68+
221: 'Yacute',
69+
222: 'THORN',
70+
223: 'szlig',
71+
224: 'agrave',
72+
225: 'aacute',
73+
226: 'acirc',
74+
227: 'atilde',
75+
228: 'auml',
76+
229: 'aring',
77+
230: 'aelig',
78+
231: 'ccedil',
79+
232: 'egrave',
80+
233: 'eacute',
81+
234: 'ecirc',
82+
235: 'euml',
83+
236: 'igrave',
84+
237: 'iacute',
85+
238: 'icirc',
86+
239: 'iuml',
87+
240: 'eth',
88+
241: 'ntilde',
89+
242: 'ograve',
90+
243: 'oacute',
91+
244: 'ocirc',
92+
245: 'otilde',
93+
246: 'ouml',
94+
247: 'divide',
95+
248: 'oslash',
96+
249: 'ugrave',
97+
250: 'uacute',
98+
251: 'ucirc',
99+
252: 'uuml',
100+
253: 'yacute',
101+
254: 'thorn',
102+
255: 'yuml',
103+
402: 'fnof',
104+
913: 'Alpha',
105+
914: 'Beta',
106+
915: 'Gamma',
107+
916: 'Delta',
108+
917: 'Epsilon',
109+
918: 'Zeta',
110+
919: 'Eta',
111+
920: 'Theta',
112+
921: 'Iota',
113+
922: 'Kappa',
114+
923: 'Lambda',
115+
924: 'Mu',
116+
925: 'Nu',
117+
926: 'Xi',
118+
927: 'Omicron',
119+
928: 'Pi',
120+
929: 'Rho',
121+
931: 'Sigma',
122+
932: 'Tau',
123+
933: 'Upsilon',
124+
934: 'Phi',
125+
935: 'Chi',
126+
936: 'Psi',
127+
937: 'Omega',
128+
945: 'alpha',
129+
946: 'beta',
130+
947: 'gamma',
131+
948: 'delta',
132+
949: 'epsilon',
133+
950: 'zeta',
134+
951: 'eta',
135+
952: 'theta',
136+
953: 'iota',
137+
954: 'kappa',
138+
955: 'lambda',
139+
956: 'mu',
140+
957: 'nu',
141+
958: 'xi',
142+
959: 'omicron',
143+
960: 'pi',
144+
961: 'rho',
145+
962: 'sigmaf',
146+
963: 'sigma',
147+
964: 'tau',
148+
965: 'upsilon',
149+
966: 'phi',
150+
967: 'chi',
151+
968: 'psi',
152+
969: 'omega',
153+
977: 'thetasym',
154+
978: 'upsih',
155+
982: 'piv',
156+
8226: 'bull',
157+
8230: 'hellip',
158+
8242: 'prime',
159+
8243: 'Prime',
160+
8254: 'oline',
161+
8260: 'frasl',
162+
8472: 'weierp',
163+
8465: 'image',
164+
8476: 'real',
165+
8482: 'trade',
166+
8501: 'alefsym',
167+
8592: 'larr',
168+
8593: 'uarr',
169+
8594: 'rarr',
170+
8595: 'darr',
171+
8596: 'harr',
172+
8629: 'crarr',
173+
8656: 'lArr',
174+
8657: 'uArr',
175+
8658: 'rArr',
176+
8659: 'dArr',
177+
8660: 'hArr',
178+
8704: 'forall',
179+
8706: 'part',
180+
8707: 'exist',
181+
8709: 'empty',
182+
8711: 'nabla',
183+
8712: 'isin',
184+
8713: 'notin',
185+
8715: 'ni',
186+
8719: 'prod',
187+
8721: 'sum',
188+
8722: 'minus',
189+
8727: 'lowast',
190+
8730: 'radic',
191+
8733: 'prop',
192+
8734: 'infin',
193+
8736: 'ang',
194+
8743: 'and',
195+
8744: 'or',
196+
8745: 'cap',
197+
8746: 'cup',
198+
8747: 'int',
199+
8756: 'there4',
200+
8764: 'sim',
201+
8773: 'cong',
202+
8776: 'asymp',
203+
8800: 'ne',
204+
8801: 'equiv',
205+
8804: 'le',
206+
8805: 'ge',
207+
8834: 'sub',
208+
8835: 'sup',
209+
8836: 'nsub',
210+
8838: 'sube',
211+
8839: 'supe',
212+
8853: 'oplus',
213+
8855: 'otimes',
214+
8869: 'perp',
215+
8901: 'sdot',
216+
8968: 'lceil',
217+
8969: 'rceil',
218+
8970: 'lfloor',
219+
8971: 'rfloor',
220+
9001: 'lang',
221+
9002: 'rang',
222+
9674: 'loz',
223+
9824: 'spades',
224+
9827: 'clubs',
225+
9829: 'hearts',
226+
9830: 'diams',
227+
338: 'OElig',
228+
339: 'oelig',
229+
352: 'Scaron',
230+
353: 'scaron',
231+
376: 'Yuml',
232+
710: 'circ',
233+
732: 'tilde',
234+
8194: 'ensp',
235+
8195: 'emsp',
236+
8201: 'thinsp',
237+
8204: 'zwnj',
238+
8205: 'zwj',
239+
8206: 'lrm',
240+
8207: 'rlm',
241+
8211: 'ndash',
242+
8212: 'mdash',
243+
8216: 'lsquo',
244+
8217: 'rsquo',
245+
8218: 'sbquo',
246+
8220: 'ldquo',
247+
8221: 'rdquo',
248+
8222: 'bdquo',
249+
8224: 'dagger',
250+
8225: 'Dagger',
251+
8240: 'permil',
252+
8249: 'lsaquo',
253+
8250: 'rsaquo',
254+
8364: 'euro',
255+
};

lib/fn.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/***********************************************************************
2+
* _
3+
* _____ _ ____ _ |_|
4+
* | _ |/ \ ____ ____ __ ___ / ___\/ \ __ _ ____ _
5+
* | |_| || | / __ \/ __ \\ '_ \ _ / / | |___\ \ | |/ __ \| |
6+
* | _ || |__. ___/. ___/| | | ||_|\ \___ | _ | |_| |. ___/| |
7+
* |_/ \_|\___/\____|\____||_| |_| \____/|_| |_|_____|\____||_|
8+
*
9+
* ================================================================
10+
* More than a coder, More than a designer
11+
* ================================================================
12+
*
13+
*
14+
* - Document: fn.js
15+
* - Author: aleen42
16+
* - Description: base library
17+
* - Create Time: Feb 12nd, 2018
18+
* - Update Time: Feb 12nd, 2018
19+
*
20+
*
21+
**********************************************************************/
22+
23+
const isNullity = x => x == null;
24+
const TAG_NULL = [];
25+
const TAG_ARRAY = [];
26+
const TAG_OBJECT = ['[object Object]'];
27+
const TAG_STRING = ['[object String]'];
28+
const TAG_NUMBER = ['[object Number]'];
29+
// https://stackoverflow.com/questions/7656280/how-do-i-check-whether-an-object-is-an-arguments-object-in-javascript/7656333#7656333
30+
const TAG_ARGUMENTS = ['[object Arguments]'];
31+
const TAG_FUNCTION = ['[object Function]'];
32+
const tags = {};
33+
[TAG_OBJECT, TAG_STRING, TAG_NUMBER, TAG_ARGUMENTS, TAG_FUNCTION].map(tag => { tags[tag[0]] = tag });
34+
const getTag = x => isNullity(x) ? TAG_NULL : Array.isArray(x) ? TAG_ARRAY : tags[({}).toString.call(x)];
35+
const is = TAG => x => getTag(x) === TAG;
36+
37+
/**
38+
* [replaceAll: replace all match sub-string in a string]
39+
* @param {string} search [description]
40+
* @param {string} replacement [description]
41+
* @return {string} [description]
42+
*/
43+
String.prototype.replaceAll = function (search, replacement) {
44+
return this.split(search).join(replacement);
45+
};
46+
47+
/**
48+
* [leftTrim: trim left space]
49+
* @return {string} [description]
50+
*/
51+
String.prototype.leftTrim = function () {
52+
return this.replace(/^\s+/, '');
53+
};
54+
55+
module.exports = {
56+
isOBJ: is(TAG_OBJECT),
57+
isSTR: is(TAG_STRING),
58+
isNUM: is(TAG_NUMBER),
59+
isFUN: is(TAG_FUNCTION),
60+
61+
/**
62+
* [E2A: HTML entities to Ascii]
63+
* @param {string} str [description]
64+
* @returns {void | string | *}
65+
*/
66+
E2A: str => str.replace(/&([\S]+?);/g, value => {
67+
value = value.replace('&', '');
68+
value = value.replace(';', '');
69+
70+
/** get the first key of a specific value */
71+
const entity = Object.entries(require('./entity')).find(([, val]) => val === value);
72+
return !entity ? null : String.fromCharCode(entity[0]);
73+
}),
74+
75+
/**
76+
* [A2U: convert ascii to unicode]
77+
* @param {string} str [description]
78+
* @returns {string}
79+
* @constructor
80+
*/
81+
A2U: str => str.split('').map(ch => `&#${ch.charCodeAt(0)};`).join(''),
82+
};

0 commit comments

Comments
 (0)