bitwrench 1.2.16 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/README.md +160 -158
  2. package/bin/bitwrench.js +3 -0
  3. package/dist/bitwrench-code-edit.cjs.js +639 -0
  4. package/dist/bitwrench-code-edit.es5.js +875 -0
  5. package/dist/bitwrench-code-edit.es5.min.js +15 -0
  6. package/dist/bitwrench-code-edit.esm.js +628 -0
  7. package/dist/bitwrench-code-edit.esm.min.js +15 -0
  8. package/dist/bitwrench-code-edit.umd.js +645 -0
  9. package/dist/bitwrench-code-edit.umd.min.js +15 -0
  10. package/dist/bitwrench.cjs.js +6983 -0
  11. package/dist/bitwrench.cjs.min.js +62 -0
  12. package/dist/bitwrench.css +5100 -0
  13. package/dist/bitwrench.es5.js +8446 -0
  14. package/dist/bitwrench.es5.min.js +31 -0
  15. package/dist/bitwrench.esm.js +6981 -0
  16. package/dist/bitwrench.esm.min.js +62 -0
  17. package/dist/bitwrench.umd.js +6989 -0
  18. package/dist/bitwrench.umd.min.js +62 -0
  19. package/dist/builds.json +127 -0
  20. package/dist/sri.json +18 -0
  21. package/package.json +86 -24
  22. package/readme.html +288 -0
  23. package/src/bitwrench-code-edit.js +627 -0
  24. package/src/bitwrench-color-utils.js +311 -0
  25. package/src/bitwrench-component-base.js +736 -0
  26. package/src/bitwrench-components-inline.js +374 -0
  27. package/src/bitwrench-components-v2.js +1879 -0
  28. package/src/bitwrench-components.js +610 -0
  29. package/src/bitwrench-styles.js +3240 -0
  30. package/src/bitwrench.js +3367 -0
  31. package/src/cli/convert.js +205 -0
  32. package/src/cli/index.js +122 -0
  33. package/src/cli/inject.js +55 -0
  34. package/src/cli/layout-default.js +142 -0
  35. package/src/generate-css.js +381 -0
  36. package/src/vendor/quikdown.js +654 -0
  37. package/src/version.js +16 -0
  38. package/.eslintrc.json +0 -27
  39. package/.github/workflows/codeql-analysis.yml +0 -72
  40. package/.travis.yml +0 -34
  41. package/bitwrench.css +0 -92
  42. package/bitwrench.js +0 -3348
  43. package/bitwrench.js_sri.txt +0 -1
  44. package/bitwrench.min.js +0 -1
  45. package/bitwrench.min.js_sri.txt +0 -1
  46. package/bitwrench_ESM.js +0 -3207
  47. package/bitwrench_ESM.js_sri.txt +0 -1
  48. package/bitwrench_ESM.min.js +0 -1
  49. package/bitwrench_ESM.min.js_sri.txt +0 -1
  50. package/dev/bitwrench-todo.md +0 -215
  51. package/dev/css-arrows.md +0 -23
  52. package/dev/docStringDev.js +0 -124
  53. package/dev/docStringParseDev.js +0 -171
  54. package/dev/example11-load-mjs-page.html +0 -17
  55. package/dev/figures.html +0 -37
  56. package/dev/html_gen.js +0 -349
  57. package/dev/htmld.md +0 -250
  58. package/dev/htmldev.html +0 -45
  59. package/dev/index-old.html +0 -87
  60. package/dev/misc-notes.md +0 -21
  61. package/dev/norm.css +0 -30
  62. package/dev/notes.md +0 -2
  63. package/dev/pageData.mjs +0 -69
  64. package/dev/sizes.html +0 -49
  65. package/dev/universal-js-module.js +0 -37
  66. package/examples/example1.html +0 -78
  67. package/examples/example10.html +0 -84
  68. package/examples/example11.html +0 -17
  69. package/examples/example12.html +0 -18
  70. package/examples/example2.html +0 -44
  71. package/examples/example3.html +0 -50
  72. package/examples/example4.html +0 -22
  73. package/examples/example5.html +0 -82
  74. package/examples/example6.html +0 -128
  75. package/examples/example7.html +0 -91
  76. package/examples/example8.html +0 -27
  77. package/examples/example9.html +0 -102
  78. package/examples/examplePageData12.mjs +0 -73
  79. package/examples/pageData.mjs +0 -69
  80. package/examples/pico.min.css +0 -5
  81. package/icon/bitwrench-dark-tall.png +0 -0
  82. package/icon/bitwrench-dark.png +0 -0
  83. package/icon/bitwrench-icon-lt-grey.png +0 -0
  84. package/icon/bitwrench-icon.vsd +0 -0
  85. package/icon/bitwrench-logo-dark.png +0 -0
  86. package/icon/bitwrench-logo-full.png +0 -0
  87. package/icon/bitwrench-logo-green.png +0 -0
  88. package/icon/bitwrench-logo-grey.png +0 -0
  89. package/icon/bitwrench-logo-white.png +0 -0
  90. package/icon/bitwrench-logos-colors.png +0 -0
  91. package/icon/bitwrench-thick-logo.png +0 -0
  92. package/icon/bitwrench-thick-teal/android-chrome-192x192.png +0 -0
  93. package/icon/bitwrench-thick-teal/android-chrome-512x512.png +0 -0
  94. package/icon/bitwrench-thick-teal/apple-touch-icon.png +0 -0
  95. package/icon/bitwrench-thick-teal/browserconfig.xml +0 -9
  96. package/icon/bitwrench-thick-teal/favicon-16x16.png +0 -0
  97. package/icon/bitwrench-thick-teal/favicon-32x32.png +0 -0
  98. package/icon/bitwrench-thick-teal/favicon.ico +0 -0
  99. package/icon/bitwrench-thick-teal/mstile-144x144.png +0 -0
  100. package/icon/bitwrench-thick-teal/mstile-150x150.png +0 -0
  101. package/icon/bitwrench-thick-teal/mstile-310x150.png +0 -0
  102. package/icon/bitwrench-thick-teal/mstile-310x310.png +0 -0
  103. package/icon/bitwrench-thick-teal/mstile-70x70.png +0 -0
  104. package/icon/bitwrench-thick-teal/site.webmanifest +0 -19
  105. package/icon/bitwrench-thick-teal.ico +0 -0
  106. package/icon/bitwrench-thick-teal.svg +0 -44
  107. package/icon/bitwrench-thick-teal.zip +0 -0
  108. package/icon/favicon-test.html +0 -20
  109. package/icon/logos-test.PNG +0 -0
  110. package/images/bitwrench-512x512.png +0 -0
  111. package/images/bitwrench-logo-med.png +0 -0
  112. package/images/bitwrench-thick-logo.png +0 -0
  113. package/images/bitwrench-thick-logo.svg +0 -64
  114. package/images/bitwrench-thick-teal.ico +0 -0
  115. package/images/favicon.ico +0 -0
  116. package/index.html +0 -282
  117. package/instr_tmp/bitwrench.js +0 -1350
  118. package/karma.conf.js +0 -140
  119. package/makefile +0 -21
  120. package/quick-docs.html +0 -206
  121. package/test/bitwrench_test.js +0 -1255
  122. package/test/karma-test.js +0 -1081
  123. package/tools/bw_deprecatedNames.js +0 -19
  124. package/tools/bwconsole.js +0 -20
  125. package/tools/createSimpleHTMLPage.js +0 -41
  126. package/tools/emitreadme.sh +0 -4
  127. package/tools/export-bw-default-css.js +0 -41
  128. package/tools/umd2ModuleHack.js +0 -32
  129. package/tools/update-bw-package.js +0 -36
  130. package/tools/updatereadme.js +0 -34
@@ -1,1255 +0,0 @@
1
- /**
2
- bitwrench test functions for npm (nodejs) see bitwrench_test_karam.js for browser version of tests
3
-
4
- this file uses the mocha test framework and chai assert framework along with jsdom to test certiain environment params
5
-
6
- npm install mocha --save-dev
7
- npm install chai --save-dev
8
- npm install jsdom --save-dev
9
-
10
- */
11
- "use strict";
12
-
13
-
14
-
15
- var assert = require("assert");
16
-
17
- // include bitwrench!
18
- var bw = require("../bitwrench.js"); // this is a live copy of bitwrench for nodejs testing as below
19
- //var bw = require("../instr_tmp/bitwrench.js"); // this is a live copy of bitwrench for nodejs testing as below
20
-
21
- //====================
22
-
23
- //if (bw.isNodeJS()) {
24
-
25
- var jsdom = require('jsdom');
26
- const { JSDOM } = jsdom;
27
-
28
- var istanbul = require('nyc')
29
- // console.log(istanbul,istanbul.__coverage__)
30
- const fs = require("fs");
31
- const path = require("path");
32
-
33
- const bitwrenchFile = fs.readFileSync(path.resolve(__dirname,"../bitwrench.js"), { encoding: "utf-8" }).toString(); // this is a literal copy of bitwrench for jsdom injection
34
- console.log("bitwrenchFile Loaded..."+bitwrenchFile.length+" chars");
35
-
36
- const bitwrenchFileInstrumented = fs.readFileSync(path.resolve(__dirname,"../instr_tmp/bitwrench.js"), { encoding: "utf-8" }).toString(); // this is a literal copy of bitwrench for jsdom injection
37
- console.log("bitwrenchFileInstrumented Loaded..."+bitwrenchFileInstrumented.length+" chars");
38
-
39
- `
40
- var coverageVar = (
41
- function() {
42
- var coverageVar = __coverage__;
43
- / *
44
- for(var key of Object.keys(global)) {
45
- if (/\$\$cov\d+\$\$/.test(key)) {
46
- coverageVar = key;
47
- }
48
- }* /
49
- console.log('Coverage var:', coverageVar);
50
- return coverageVar;
51
- }
52
- )();
53
- `
54
- //}
55
- // ================================================================
56
- var setupdom = function(wnd,html) {
57
- if (bw.isNodeJS() ) {
58
-
59
- const testDoc = `<!DOCTYPE html><html><head></head><body><span id="myTestSpan">starter</span><div class="foo">default</div></body></html>`;
60
- wnd = (new JSDOM( (((typeof html) !== "undefined") ? html : testDoc),
61
- {
62
- runScripts: "dangerously" ,
63
- created: function (errors, wnd) { wnd[coverageVar] = global[coverageVar]; console.log(coverageVar) },
64
- done : function (errors, wnd) {if (errors) {console.log(errors); done(true); } else { window = wnd; done(); }
65
- }
66
- })).window;
67
-
68
- // Execute my library by inserting a <script> tag containing it.
69
- const scriptEl = wnd.document.createElement("script");
70
- scriptEl.textContent = bitwrenchFileInstrumented;
71
- wnd.document.head.appendChild(scriptEl);
72
- }
73
- else {
74
-
75
- wnd = (typeof window != "undefined") ? window : wnd; // yes the global window -- we're in the browser
76
- //if (html)
77
- // window.document.documentElement = html;
78
- console.log("browser context")
79
- }
80
- return wnd;
81
- }
82
- //==================================
83
-
84
- //tests begin:
85
- // ================================================================
86
- describe("#choice(x,choiceDict{},defaultVal) - Allows a dictionary to be used as a switch statement, including functions as values. ", function() {
87
- /**
88
-
89
- */
90
- var tests = [
91
- {args: [1, {1:2,foo:"bar"},function(){return "defaultUsed"}], expected: 2 },
92
- {args: ["foo", {1:2, foo:function(x){return x+"bar"}},function(){return "defaultUsed"}], expected: "foobar" },
93
- {args: [3, {1:2,foo:"bar"},function(x){return "not found: " + String(x)}], expected: "not found: 3" },
94
- ];
95
-
96
- tests.forEach(function(test) {
97
- it("bw.choice " + test.args.length + "args", function() {
98
- var res = bw.choice.apply(null, test.args);
99
- assert.equal(res, test.expected);
100
- });
101
- });
102
-
103
- });
104
-
105
- // ================================================================
106
- describe("#jsonClone() - duplicate a (simple) object by converting to JSON and back", function() {
107
- /**
108
-
109
- */
110
- var tests = [
111
- {args: [{1:2,foo:"bar"}], expected: {1:2,foo:"bar"} },
112
- {args: ["foo"], expected: "foo" }
113
- ];
114
-
115
- tests.forEach(function(test) {
116
- it("bw.jsonClone " + test.args.length + "args", function() {
117
- var res = bw.jsonClone.apply(null, test.args);
118
- assert.deepEqual(res, test.expected);
119
- });
120
- });
121
- });
122
-
123
- // ================================================================
124
- describe("#typeOf()", function() {
125
- /**
126
- test built-in basic bitwrench typeof operator
127
- */
128
-
129
- //using meta tests
130
- var x;
131
- var tests = [
132
- {args: [[]], expected: "array"},
133
- {args: [{}], expected: "object"},
134
- {args: [1], expected: "number"},
135
- {args: ["test string"], expected: "string"},
136
- {args: [x], expected: "undefined"},
137
- {args: [null], expected: "null"},
138
- {args: [new Date()], expected: "date"},
139
- {args: [function(){}], expected: "function"},
140
- {args: [class{}], expected: "function" },
141
- {args: [class{},true], expected: "function" }
142
- ];
143
-
144
- tests.forEach(function(test) {
145
- it("bw.typeOf (internal type operator) " + test.args.length + " args", function() {
146
- var res = bw.typeOf.apply(null, test.args);
147
- assert.equal(res, test.expected);
148
- });
149
- });
150
-
151
- });
152
- // ================================================================
153
- describe("#typeAssign(x,type,trueV,FalseV) - see if a variable is a certain type or one of a list of types", function() {
154
- /**
155
-
156
- */
157
- var tests = [
158
- {args: [1,0,true,false], expected:false }, // needs typeString to be a number or string
159
- {args: [1,"number",true,false], expected: true },
160
- {args: [1,"string",true,false], expected: false },
161
- {args: [1,["number","string"],true,false], expected: true }
162
- ];
163
-
164
- tests.forEach(function(test) {
165
- it("bw.typeAssign " + test.args.length + "args", function() {
166
- var res = bw.typeAssign.apply(null, test.args);
167
- assert.equal(res, test.expected);
168
- });
169
- });
170
- });
171
- // ================================================================
172
- describe("#typeConvert(x,type,trueV,FalseV) - see if a variable is a certain type or one of a list of types, allows output to be functional", function() {
173
- /**
174
-
175
- */
176
- var tests = [
177
- {args: [1,0,true,false], expected:false }, // needs typeString to be a number or string
178
- {args: [1,"number",true,false], expected: true },
179
- {args: [1,"string",true,false], expected: false },
180
- {args: [1,["number","string"],true,false], expected: true },
181
- {args: [1,["number","string"],function(){return "true"},function(){return "false"}], expected: "true" },
182
- {args: [1,["number","string"],function(){return "true"},function(x){return x}], expected: "true" },
183
- {args: [{},["number","string"],function(){return "true"},function(){return "false"}], expected: "false" }
184
- ];
185
-
186
- tests.forEach(function(test) {
187
- it("bw.typeConvert " + test.args.length + "args", function() {
188
- var res = bw.typeConvert.apply(null, test.args);
189
- assert.equal(res, test.expected);
190
- });
191
- });
192
- });
193
-
194
- // ================================================================
195
- describe("#typeConvert(x,type,trueV,FalseV) - see if a variable is a certain type or one of a list of types, allows output to be functional", function() {
196
- /**
197
-
198
- */
199
- var tests = [
200
- {args: [1,0,true,false], expected:false }, // needs typeString to be a number or string
201
- {args: [1,"number",true,false], expected: true },
202
- {args: [1,"string",true,false], expected: false },
203
- {args: [1,["number","string"],true,false], expected: true },
204
- {args: [1,["number","string"],function(){return "true"},function(){return "false"}], expected: "true" },
205
- {args: [1,["number","string"],function(){return "true"},function(x){return x}], expected: "true" },
206
- {args: [{},["number","string"],function(){return "true"},function(){return "false"}], expected: "false" }
207
- ];
208
-
209
- tests.forEach(function(test) {
210
- it("bw.typeConvert " + test.args.length + "args", function() {
211
- var res = bw.typeConvert.apply(null, test.args);
212
- assert.equal(res, test.expected);
213
- });
214
- });
215
- });
216
- // ================================================================
217
-
218
- describe("#arrayUniq([]) - return uniq elements of an Array", function() {
219
- /**
220
-
221
- */
222
- var tests = [
223
-
224
- {args: [[1,2,3,2,1]], expected:[1,2,3] },
225
- {args: [1], expected: []} // type check
226
- ];
227
-
228
- tests.forEach(function(test) {
229
- it("bw.arrayUniq " + test.args.length + "args", function() {
230
- var res = bw.arrayUniq.apply(null, test.args);
231
- assert.deepEqual(res, test.expected);
232
- });
233
- });
234
- });
235
- // ================================================================
236
-
237
- describe("#arrayBinA(a[],b[]) - return elements of Array B in Array A ", function() {
238
- /**
239
-
240
- */
241
- var tests = [
242
-
243
- {args: [[1,2,3,2,1],[1,3,5]], expected:[1,3] },
244
- {args: [1,[]], expected: []}, //type check
245
- {args: [[],1], expected: []} //type check
246
- ];
247
-
248
- tests.forEach(function(test) {
249
- it("bw.arrayBinA " + test.args.length + "args", function() {
250
- var res = bw.arrayBinA.apply(null, test.args);
251
- assert.deepEqual(res, test.expected);
252
- });
253
- });
254
- });
255
- // ================================================================
256
-
257
- describe("#arrayBNotinA(a,b) - return elements of Array B not in Array A ", function() {
258
- /**
259
-
260
- */
261
- var tests = [
262
- {args: [[1,2,3,2,1],[1,3,5]], expected:[5] },
263
- {args: [1,[]], expected: []}, //type check
264
- {args: [[],1], expected: []} //type check
265
- ];
266
-
267
- tests.forEach(function(test) {
268
- it("bw.arrayBNotinA " + test.args.length + "args", function() {
269
- var res = bw.arrayBNotInA.apply(null, test.args);
270
- assert.deepEqual(res, test.expected);
271
- });
272
- });
273
- });
274
-
275
- describe("#bw.DOMIsElement()", function() {
276
- /**
277
-
278
-
279
- */
280
- var wind;
281
- beforeEach(() => {
282
- wind = setupdom(wind);
283
- });
284
-
285
- it("DOMIsElement()", () => {
286
- assert.equal(wind.bw.DOMIsElement(wind.bw.DOM("span")[0]), true); // test jsdom is using bw correctly in window context
287
- });
288
- it("DOMIsElement()", () => {
289
- assert.equal(wind.bw.DOMIsElement(wind.bw.DOM("not an Element")[0]), false); // test jsdom is using bw correctly in window context
290
- });
291
- });
292
-
293
- describe("#bw.DOMGetElements())", function() {
294
- /**
295
-
296
- */
297
- var wind;
298
- beforeEach(() => {
299
- wind = setupdom(wind);
300
- });
301
-
302
- it("bw.DOM test equivalents...", () => {
303
- assert.equal(wind.document.getElementById("myTestSpan").innerHTML, "starter");
304
- assert.equal(wind.bw.DOMGetElements("myTestSpan","id")[0].innerHTML, "starter");
305
- });
306
- it("bw.DOM test equivalents...", () => {
307
- var res = wind.bw.DOMGetElements("foo","className")[0].innerHTML;
308
- assert.equal(wind.document.getElementsByClassName("foo")[0].innerHTML, res);
309
- });
310
-
311
-
312
- });
313
-
314
- describe("#bw.DOM())", function() {
315
- /**
316
- bw.DOM and bw.DOMSetElements
317
-
318
-
319
- */
320
-
321
- var wind;
322
- beforeEach(() => {
323
- wind = setupdom(wind);
324
- });
325
-
326
-
327
- it("bw.DOM test equivalents...", () => {
328
- assert.equal(wind.document.getElementById("myTestSpan").innerHTML, "starter");
329
- assert.equal(wind.bw.DOM("#myTestSpan")[0].innerHTML, "starter");
330
- });
331
- it("bw.DOM test equivalents...", () => {
332
-
333
- wind.bw.DOM(".foo","fizbinn");
334
- assert.equal(wind.document.getElementsByClassName("foo")[0].innerHTML, "fizbinn");
335
- });
336
- it("bw.DOM test equivalents...", () => {
337
- wind.bw.DOM("span","fizbinnagain");
338
- assert.equal(wind.document.getElementsByTagName("span")[0].innerHTML, "fizbinnagain");
339
- });
340
-
341
-
342
- });
343
- // ================================================================
344
-
345
- describe("#colorInterp((x, in0, in1, colors, stretch) - interpolate a value from an array of colors ", function() {
346
- /**
347
-
348
- */
349
- var tests = [
350
- {args: [228,100,355,["#000","rgb(255,255,255)"]], expected:[128,128,128,255,"rgb"] },
351
- {args: [162.5,100,200,["#000","#aaa","#fff","#000","#bbb"]], expected: [127.5, 127.5, 127.5, 255, "rgb"]}
352
- ];
353
-
354
- tests.forEach(function(test) {
355
- it("bw.colorInterp " + test.args.length + "args", function() {
356
- var res = bw.colorInterp.apply(null, test.args);
357
- assert.deepEqual(res, test.expected);
358
- });
359
- });
360
- });
361
-
362
- // ================================================================
363
- /*
364
- some useful color values:
365
-
366
- Black #000000 (0,0,0) (0°,0%,0%)
367
- White #FFFFFF (255,255,255) (0°,0%,100%)
368
- Red #FF0000 (255,0,0) (0°,100%,50%)
369
- Lime #00FF00 (0,255,0) (120°,100%,50%)
370
- Blue #0000FF (0,0,255) (240°,100%,50%)
371
- Yellow #FFFF00 (255,255,0) (60°,100%,50%)
372
- Cyan #00FFFF (0,255,255) (180°,100%,50%)
373
- Magenta #FF00FF (255,0,255) (300°,100%,50%)
374
- Silver #BFBFBF (191,191,191) (0°,0%,75%)
375
- */
376
-
377
- describe("#colorHslToRgb(h, s, l, a - convert HSL color space to RGB ", function() {
378
- /**
379
- test conversion of HSL colors to RGB
380
- */
381
- var tests = [
382
- {args: [120,100,50,128], expected:[0,255,0,128,"rgb"] } ,
383
- {args: [[0,0,75,128]], expected:[191,191,191,128,"rgb"] }
384
- ];
385
-
386
- var crnd = function(a){return [Math.round(a[0]),Math.round(a[1]),Math.round(a[2]),Math.round(a[3]),a[4] ];}
387
- tests.forEach(function(test) {
388
- it("bw.colorHslToRgb " + test.args.length + "args", function() {
389
- var res = bw.colorHslToRgb.apply(null, test.args);
390
- //res = crnd(res);
391
- assert.deepEqual(res, test.expected);
392
- });
393
- });
394
- });
395
-
396
-
397
- // ================================================================
398
-
399
- describe("#colorRgbToHsl(r, g, b, a - convert HSL color space to RGB ", function() {
400
- /**
401
- test conversion of RGB style colors to HSL
402
- */
403
- var tests = [
404
- {args: [0,255,0,100], expected:[120,100,50,100,"hsl"] },
405
- {args: [[191,191,191,100]], expected:[0,0,75,100,"hsl"] }
406
- ];
407
-
408
- var hrnd = function(a){return [Math.round(a[0]*360),bw.fixNum(a[1],2),bw.fixNum(a[2],2),Math.round(a[3]),a[4] ];}
409
-
410
- tests.forEach(function(test) {
411
- it("bw.colorRgbToHsl " + test.args.length + "args", function() {
412
- var res = bw.colorRgbToHsl.apply(null, test.args);
413
- //res = hrnd(res);
414
- assert.deepEqual(res, test.expected);
415
- });
416
- });
417
- });
418
-
419
- describe("#colorParse(colorToParseString, defaultAlpha - parse a color object e.g. #abc or HSL(12,3,43,0.3) to a bitwrench color array [,,,] ", function() {
420
- /**
421
-
422
- */
423
- var tests = [
424
- {args: ["#abc"], expected:[170, 187, 204, 255, "rgb"] },
425
- {args: ["#abc",255], expected:[170, 187, 204, 255, "rgb"] },
426
- {args: ["#abcd"], expected:[170, 187, 204, 221, "rgb"] },
427
- {args: ["#AABBCC"], expected:[170, 187, 204, 255, "rgb"] },
428
- {args: ["hsl(12,34,45,100)"], expected:[12,34,45,100,"hsl"] },
429
- {args: [" hsl ( 12 , 34, 45, 100 )"], expected:[12,34,45,100,"hsl"] },
430
- {args: [[0xaa,0xbb,0xcc]], expected: [0xaa,0xbb,0xcc,0xff,"rgb"]},
431
- {args: [[10,20,30,40,"rgb"]], expected: [10,20,30,40,"rgb"]},
432
- {args: [[300,20,30,50,"hsl"]], expected: [300,20,30,50,"hsl"]}
433
- ];
434
-
435
-
436
- tests.forEach(function(test) {
437
- it("bw.colorParse " + test.args.length + "args", function() {
438
- var res = bw.colorParse.apply(null, test.args);
439
- //res = hrnd(res);
440
- assert.deepEqual(res, test.expected);
441
- });
442
- });
443
- });
444
-
445
- describe("#colorConvertColorSpace( convert a color from one space to another)", function() {
446
- /**
447
- test conversion of RGB style colors to HSL
448
- */
449
- var tests = [
450
- {args: [[0,255,0,100,"rgb"],"hsl"], expected:[120,100,50,100,"hsl"] },
451
- {args: [[0,255,0,100,"rgb"],"rgb"], expected:[0,255,0,100,"rgb"] },
452
- {args: [[120,100,50,111,"hsl"],"rgb"], expected:[0,255,0,111,"rgb"] },
453
- {args: [[120,100,50,111,"hsl"],"hsl"], expected:[120,100,50,111,"hsl"] }
454
- ];
455
-
456
- var hrnd = function(a){return [Math.round(a[0]*360),bw.fixNum(a[1],2),bw.fixNum(a[2],2),Math.round(a[3]),a[4] ];}
457
-
458
- tests.forEach(function(test) {
459
- it("bw.colorConvertColorSpace " + test.args.length + "args", function() {
460
- var res = bw.colorConvertColorSpace.apply(null, test.args);
461
- //res = hrnd(res);
462
- assert.deepEqual(res, test.expected);
463
- });
464
- });
465
- });
466
- //====================================================================================
467
- describe("#URLParamParse(url, optKey, OptDefValue - parse URL query string (must have ? present) to get values", function() {
468
- /**
469
- test extraction or URL params. note in bitwrench this is used both for URL parsing and "command line" args parsing
470
- */
471
- var tests = [
472
- {args: ["http://bar.com:80?foo=bar&x=234&y=45"], expected:{foo:"bar",x:"234",y:"45"} },
473
- {args: ["?a=123&b=234","a"], expected:"123" },
474
- {args: ["?a=123&b=234","c"], expected: undefined },
475
- {args: ["?a=123&b=234","c","def"], expected:"def" },
476
- {args: ["?a=123&b=234&d&e=#123","d","def",true], expected:true }, // case of key with no value
477
- {args: ["?a=123&b=234&d&e=#123","e","#123",true], expected:"#123" },
478
- {args: ["https:1bca.com/a/b/c?a=134&b=234#thisisit&d=234","b","no",true], expected: "234#thisisit"},
479
- {args: ["https:1bca.com/a/b/c?a=134&b=234#thisisit&d=234","b","no",false], expected: "234"},
480
- {args: ["https:1bca.com/a/b/c?a=134&b=234#thisisit&d=234","b","no"], expected: "234" }
481
-
482
- ];
483
-
484
-
485
- tests.forEach(function(test) {
486
- it("bw.URLParamParse " + test.args.length + "args", function() {
487
- var res = bw.URLParamParse.apply(null, test.args);
488
- if (typeof res == "string")
489
- assert.equal(res, test.expected);
490
- else
491
- assert.deepEqual(res, test.expected);
492
- });
493
- });
494
- });
495
- //====================================================================================
496
- describe("#URLHash (url,defValue) - returns the hash portion of a url encoded string. If no params supplied attempts to get has from window.location.href", function() {
497
- /**
498
- see if a URL has a hash string at the end
499
- */
500
- var tests = [
501
- {args: [], expected: undefined},
502
- {args: ["http://bar.com:80?foo=bar&x=234&y=45#123"], expected:"123" },
503
- {args: ["?a=123&b=234","no"], expected:"no" },
504
- ];
505
-
506
-
507
- tests.forEach(function(test) {
508
- it("bw.URLHash " + test.args.length + "args", function() {
509
- var res = bw.URLHash.apply(null, test.args);
510
- if (typeof res == "string")
511
- assert.equal(res, test.expected);
512
- else
513
- assert.deepEqual(res, test.expected);
514
- });
515
- });
516
- });
517
- //====================================================================================
518
- describe("#URLParamPack (dict,addQuestionToFront) -packs a simple (not deep) dict in to URL form", function() {
519
- /**
520
- pack a simple dict to a URL encoded string.
521
- */
522
- var tests = [
523
- {args: [{123:"abc",234:456}], expected: "123=abc&234=456"},
524
- {args: [{123:"abc",234:456},true], expected: "?123=abc&234=456"},
525
- {args: ["foo"], expected:"" },
526
- ];
527
-
528
-
529
- tests.forEach(function(test) {
530
- it("bw.URLParamPack " + test.args.length + "args", function() {
531
- var res = bw.URLParamPack.apply(null, test.args);
532
- assert.deepEqual(res, test.expected);
533
- });
534
- });
535
- });
536
- //====================================================================================
537
- describe("#htmlSafeStr (string) -encodes chars such as & < > ' etc to HTML safe equiv. also handles spaces, linefeeds and tabs", function() {
538
- /**
539
- see if a URL has a hash string at the end
540
- */
541
- var tests = [
542
- {args: ["<>& x\tx\nabc"], expected: "&lt;&gt;&amp; x&nbsp;&nbsp;&nbsp;&nbsp;x<br>abc"},
543
- {args: ["abcdefghijklmopqurstuvwxyz1234567890-=_+[]{}|;',./?"], expected: "abcdefghijklmopqurstuvwxyz1234567890-=_+[]{}|;&#039;,./?"}
544
- ];
545
-
546
-
547
- tests.forEach(function(test) {
548
- it("bw.htmlSafeStr " + test.args.length + "args", function() {
549
- var res = bw.htmlSafeStr.apply(null, test.args);
550
- assert.deepEqual(res, test.expected);
551
- });
552
- });
553
- });
554
- //====================================================================================
555
- describe("#htmlJSON(any object) -encodes an object to viewable HTML", function() {
556
- /**
557
-
558
- */
559
- var tests = [
560
- {args: ["123#123"], expected: `<pre style='white-space:pre-wrap;'><span style="color:purple">"123#123"</span></pre>`},
561
- {args: [{1:2,3:4,5:{a:1,b:3},c:[2,3,4,{5:"abc"},6]}], expected:
562
- //yay for template strings!
563
- `<pre style='white-space:pre-wrap;'>{
564
- <span style="color:red">"1":</span> <span style="color:green">2</span>,
565
- <span style="color:red">"3":</span> <span style="color:green">4</span>,
566
- <span style="color:red">"5":</span> {
567
- <span style="color:red">"a":</span> <span style="color:green">1</span>,
568
- <span style="color:red">"b":</span> <span style="color:green">3</span>
569
- },
570
- <span style="color:red">"c":</span> [
571
- <span style="color:green">2</span>,
572
- <span style="color:green">3</span>,
573
- <span style="color:green">4</span>,
574
- {
575
- <span style="color:red">"5":</span> <span style="color:purple">"abc"</span>
576
- },
577
- <span style="color:green">6</span>
578
- ]
579
- }</pre>`}
580
- ];
581
-
582
-
583
- tests.forEach(function(test) {
584
- it("bw.htmlJSON " + test.args.length + "args", function() {
585
- var res = bw.htmlJSON.apply(null, test.args);
586
- assert.deepEqual(res, test.expected);
587
- });
588
- });
589
- });
590
- //====================================================================================
591
-
592
- describe("#makeCSS()", function() {
593
- /**
594
- makeCSS
595
- */
596
- `
597
- cssData = "h2 {color:blue;}" // string as full rule (all correctness is on the caller)
598
- cssData = ["h2 {color:blue;}"] // array entry but single string
599
- cssData = ["h2 {color:blue}", "div {width:30px}"] // 2 entries, both strings
600
- cssData = [["h2","color:blue"]] // array of rules (here length 1 rule)
601
- cssData = [["h2","color:blue"], ["h3", "font-color:red"]] // array of rules
602
- cssData = [
603
- [["h2","h4"], "color:blue"], // array or selectors, string for rule
604
- ["h3", "color:red"] // string for selector, string for rule
605
- ]
606
- cssData = [
607
- [["h1","div p"],["color:blue","display:block"]], ==> h1, div p {color: blue; diplay:block;}
608
- "h3 {color:red;}", ==> h3 {color: red;}
609
- [["div",".myClass"],"color : red"], ==> div,.myClass {color: red;}
610
- ["p > .myclass", ["color:red","display:block"]] ==> p > .myClass {color: red; display:block;}
611
- ]
612
- cssData = [
613
- [str, {}]
614
- ]
615
- cssData = [
616
- [[selectors], { dict }]
617
- ]
618
- `
619
-
620
- var tests = [
621
- {args: ["h2 {color:blue;}"], expected:"\nh2 {color:blue;}\n" },
622
- {args: [["h2 {color:blue;}"]], expected:"\nh2 {color:blue;}\n" },
623
- {args: [["h2 {color:blue}", "div {width:30px}"]], expected:"\nh2 {color:blue}\ndiv {width:30px}\n" },
624
- {args: [[["h2","color:blue"]]], expected:"\nh2 {color:blue}\n\n"},
625
- {args: [[[["h2","h4"], "color:blue"],["h3", "color:red"]]], expected: "\nh2, h4 {color:blue}\n\nh3 {color:red}\n\n"},
626
- {args: [
627
- [
628
- [["h1","div p"],["color: blue","display: block"]],
629
- "h3 {color: red;}",
630
- [["div",".myClass"],"color: red;"],
631
- ["p > .myClass", ["color: red","display: block"]]
632
- ]
633
- ], expected: "\nh1, div p {color: blue; display: block;}\n\nh3 {color: red;}\ndiv, .myClass {color: red;}\n\np > .myClass {color: red; display: block;}\n\n"
634
- },
635
- {args: [
636
- [[".myclass", {color:"red", "font-weight":700}]]
637
- ], expected :"\n.myclass {color: red; font-weight: 700;}\n\n" },
638
- {args: [
639
- [[[".myclass","div > p"], {color:"red", "font-weight":700}]]
640
- ], expected :"\n.myclass, div > p {color: red; font-weight: 700;}\n\n" }
641
-
642
- ];
643
-
644
- tests.forEach(function(test) {
645
- it("bw.makeCSS" + test.args.length + "args", function() {
646
- var res = bw.makeCSS.apply(null, test.args);
647
- assert.deepEqual(res,test.expected);
648
- });
649
- });
650
- });
651
- //====================================================================================
652
- describe("#makeCSSRule()",function(){
653
- var tests = [
654
- {args: [
655
- [".myclass", {color:"red", "font-weight":700}],{pretty:false}
656
- ], expected :".myclass{color:red;font-weight:700;}" },
657
- {args: [
658
- [[".myclass","div > p"], {color:"red", "font-weight":700}],{pretty:true}
659
- ], expected :".myclass, div > p\n{\n color: red; \n font-weight: 700; \n}\n" }
660
- ];
661
-
662
- tests.forEach(function(test) {
663
- it("bw.makeCSSRule" + test.args.length + "args", function() {
664
- var res = bw.makeCSSRule.apply(null, test.args);
665
- assert.deepEqual(res,test.expected);
666
- });
667
- });
668
- });
669
-
670
- //====================================================================================
671
- describe("#clearTimer()", function() {
672
- /**
673
- test conversion of RGB style colors to HSL
674
- */
675
- var tests = [
676
- {args: [], expected:true },
677
- {args: ["clearTimerMsg"], expected:true },
678
- ];
679
- bw.logExport({clear:true})
680
-
681
- tests.forEach(function(test) {
682
- it("bw.clearTimer " + test.args.length + "args", function() {
683
- var ref = bw.logExport()[1][1];
684
- var res = bw.clearTimer.apply(null, test.args);
685
- assert.equal((res-ref) < 3400,true);
686
- if (test.args[0]=="clearTimerMsg")
687
- assert(bw.logExport().filter(function(x){return x[1]=="clearTimerMsg"?true:false}).length > 0);//bw.logExport()[2][1]);
688
- });
689
- });
690
- });
691
- // ================================================================
692
- describe("#htmlIsVoidTag()", function() {
693
- /**
694
- gen HTML table from simple array
695
- */
696
- var tests = [
697
- {args: ["div"], expected: false},
698
- {args: ["p"], expected: false},
699
- {args: ["br"], expected: true},
700
- {args: ["meta"], expected: true}
701
- ];
702
-
703
- tests.forEach(function(test) {
704
- it("bw.htmlIsVoidTag " + test.args.length + "args", function() {
705
- var res = bw.htmlIsVoidTag.apply(null, test.args);
706
- assert.deepEqual(res, test.expected);
707
- });
708
- });
709
-
710
- });
711
- // ================================================================
712
- describe("#htmlEmit()", function() {
713
- /**
714
- gen HTML from object (or JSON)
715
- */
716
- var tests = [
717
- {args: ["test content"], expected: "test content" },
718
- {args: [{c:"test content"}], expected: "<div>test content</div>" },
719
- {args: [{t:"",c:"test content"}], expected: "test content" },
720
-
721
- ];
722
-
723
- tests.forEach(function(test) {
724
- it("bw.htmlEmit " + test.args.length + "args", function() {
725
- var res = bw.htmlEmit.apply(null, test.args).html;
726
- assert.deepEqual(res, test.expected);
727
- });
728
- });
729
-
730
- });
731
-
732
- // ================================================================
733
- describe("#htmlTable()", function() {
734
- /**
735
- gen HTML table from simple array
736
- */
737
- var tests = [
738
- {args: [[[1,2,3],[2,3,4]]], expected: "<table class=\"bw-table bw-table-stripe\" ><thead><tr><th>1</th><th>2</th><th>3</th></tr></thead><tbody><tr><td>2</td><td>3</td><td>4</td></tr></tbody></table>" }
739
- ];
740
-
741
- tests.forEach(function(test) {
742
- it("bw.htmlTable " + test.args.length + "args", function() {
743
- var res = bw.htmlTable.apply(null, test.args);
744
- assert.deepEqual(res, test.expected);
745
- });
746
- });
747
-
748
- });
749
- // ================================================================
750
- describe("#naturalCompare()", function() {
751
- /**
752
- sorting function for strings and nums in HTML table other array sorts
753
- */
754
- var tests = [
755
- {args: [-2,2], expected: -1 },
756
- {args: [2,-2], expected: 1 },
757
- {args: ["abc",-2], expected: +1 },
758
- {args: ["abc","def"], expected: -1 },
759
- {args: ["abc","abc"], expected: 0 }
760
- ];
761
-
762
- tests.forEach(function(test) {
763
- it("bw.naturalCompare " + test.args.length + "args", function() {
764
- var res = bw.naturalCompare.apply(null, test.args);
765
- assert.equal(res, test.expected);
766
- });
767
- });
768
-
769
- var test2 = [
770
- {args: [-2,3,"-3","3",0,"1xx","11xx","10xx",9], expected: ["-3", -2, 0, "1xx", 3, "3", 9, "10xx", "11xx"]}
771
- ];
772
-
773
- test2.forEach(function(test) {
774
- it("bw.naturalCompare :: full array " + test.args.length + " args", function() {
775
- assert.deepEqual(test.args.sort(bw.naturalCompare),test.expected)
776
-
777
- });
778
- });
779
-
780
-
781
- });
782
- // ================================================================
783
-
784
- describe("#bw.isNodeJS())", function() {
785
- /**
786
- bw.DOM checks
787
-
788
- */
789
-
790
- var wind;
791
- beforeEach(() => {
792
- wind = setupdom(wind);
793
- });
794
-
795
- it("isNodeJS() in window (jsdom)", () => {
796
- assert.equal(wind.bw.isNodeJS(), false); // test jsdom is using bw correctly in window context
797
- });
798
- it("isNodeJS() in nodejs", () => {
799
- assert.equal(bw.isNodeJS(), true);
800
- });
801
-
802
- it("isNodeJS() in nodejs", () => {
803
- bw.__monkey_patch_is_nodejs__.set(false);
804
- console.log(bw.__monkey_patch_is_nodejs__.get(),bw.isNodeJS())
805
- assert.equal(bw.isNodeJS(), false);
806
- bw.__monkey_patch_is_nodejs__.set("ignore");
807
- });
808
-
809
-
810
- });
811
-
812
-
813
- // ================================================================
814
- describe("#loremIpsum", function() {
815
- /**
816
- test docString raw etractor. Note this function does not parse the doc string it just returns an array of valid doc strings from the supplied string.
817
- This can be used on functions or objects via the toString() operator.
818
-
819
- e.g. var myFunction = function( .... ) { ..... function body }
820
-
821
- bitwrench.docString(myFunction.toString()) ==> returns any doc strings inside.
822
- */
823
- var tests = [
824
- {args: [25], expected: "Lorem ipsum dolor sit ame"},
825
- {args: [25,1], expected: "Orem ipsum dolor sit amet"},
826
- {args: [25,5,1], expected: "Mipsum dolor sit amet, co"},
827
- {args: [25,5,0], expected: " ipsum dolor sit amet, co"},
828
- {args: [2000,5,1], expected: "Mipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo."}
829
-
830
- ];
831
-
832
- tests.forEach(function(test) {
833
- it("bw.loremIpsum " + test.args.length + "args", function() {
834
- var res = bw.loremIpsum.apply(null, test.args);
835
- assert.deepEqual(res, test.expected);
836
- });
837
- });
838
- });
839
-
840
- // ================================================================
841
- describe("#docString", function() {
842
- /**
843
- test docString raw etractor. Note this function does not parse the doc string it just returns an array of valid doc strings from the supplied string.
844
- This can be used on functions or objects via the toString() operator.
845
-
846
- e.g. var myFunction = function( .... ) { ..... function body }
847
-
848
- bitwrench.docString(myFunction.toString()) ==> returns any doc strings inside.
849
- */
850
- var tests = [
851
- {args: ["this is not a docstring"], expected: []},
852
- {args: ["/** this is a test */ /* foo*/ /** another test */"], expected: [" this is a test ", " another test "] }
853
-
854
- ];
855
-
856
- tests.forEach(function(test) {
857
- it("bw.docString (docString extractor) " + test.args.length + "args", function() {
858
- var res = bw.docString.apply(null, test.args);
859
- assert.deepEqual(res, test.expected);
860
- });
861
- });
862
- });
863
- // ================================================================
864
- describe("#docStringParse", function() {
865
- var tests = [
866
- {args: ["/** This is a test \n*/"], expected: [{source: " This is a test ", field: "", types: "", name: "", description: ""}]}
867
- ];
868
-
869
- tests.forEach(function(test) {
870
- it("bw.docStringParse (jsdoc comment parser) " + test.args.length + " args", function() {
871
- var res = bw.docStringParse.apply(null, test.args);
872
- assert.deepEqual(res, test.expected);
873
- });
874
- });
875
-
876
- });
877
- // ================================================================
878
- describe("#isHexStr(str) return whether a string is hexadecimal number (returns number of hex digits if true)", function() {
879
- var tests = [
880
- {args: ["123abc"], expected: 6},
881
- {args: ["123abc-23","#-"], expected: 8},
882
- {args: ["123zabc-23","-"], expected: false}
883
- ];
884
-
885
- tests.forEach(function(test) {
886
- it("bw.isHexStr " + test.args.length + " args", function() {
887
- var res = bw.isHexStr.apply(null, test.args);
888
- assert.deepEqual(res, test.expected);
889
- });
890
- });
891
-
892
- });
893
- // ================================================================
894
- describe("#fixNum(num,sf) trims a number to sf number of digits ", function() {
895
- var tests = [
896
- {args: [123.345,2], expected: 123.34},
897
- {args: [-345.345,1], expected: -345.3},
898
- {args: [345,-1], expected: 340}
899
- ];
900
-
901
- tests.forEach(function(test) {
902
- it("bw.fixNum " + test.args.length + " args", function() {
903
- var res = bw.fixNum.apply(null, test.args);
904
- assert.deepEqual(res, test.expected);
905
- });
906
- });
907
-
908
- });
909
- // ================================================================
910
- describe("#multiArray() creates a multiDim array ", function() {
911
- var tests = [
912
- {args: [2,[2,3]], expected: [[2,2,2],[2,2,2]]},
913
- {args: ["test",[3,2]], expected: [["test","test"],["test","test"],["test","test"]]},
914
- {args: [function(){return 3;},[3,2]], expected: [[3,3],[3,3],[3,3]]}
915
- ];
916
-
917
- tests.forEach(function(test) {
918
- it("bw.multiArray " + test.args.length + " args", function() {
919
- var res = bw.multiArray.apply(null, test.args);
920
- assert.deepEqual(res, test.expected);
921
- });
922
- });
923
-
924
- });
925
- // ================================================================
926
- describe("#clip(x,lo,hi) clips a number between 2 values ", function() {
927
- var tests = [
928
- {args: [2,-4,5], expected: 2},
929
- {args: [-10,-4,5], expected: -4},
930
- {args: [10,-4,5], expected: 5},
931
- {args: [[1,4,8,35], 2, 20], expected: [2,4,8,20]}
932
- ];
933
-
934
- tests.forEach(function(test) {
935
- it("bw.clip " + test.args.length + " args", function() {
936
- var res = bw.clip.apply(null, test.args);
937
- assert.deepEqual(res, test.expected);
938
- });
939
- });
940
- });
941
-
942
- // ================================================================
943
- describe("#mapScale(x,inLo,inHi,outLo,OutHi,opts) scales a number btw 2 values ", function() {
944
- var tests = [
945
- {args: [1,0,10,100,200], expected: 110},
946
- {args: [[1,2,3],0,10,100,200], expected: [110,120,130]},
947
- {args: [22,20,40,200,400,{expScale: 2.0}], expected: 262.005},
948
- {args: [-22,20,40,200,400,{expScale: 3.0,clip:true}], expected: 200.081}
949
- ];
950
-
951
- tests.forEach(function(test) {
952
- it("bw.mapScale " + test.args.length + " args", function() {
953
- var res = bw.mapScale.apply(null, test.args);
954
- res = typeof res == "number" ? bw.fixNum(res,3) : res.map(function(x){return bw.fixNum(x,3)});
955
- assert.deepEqual(res, test.expected);
956
- });
957
- });
958
- });
959
- // ================================================================
960
- describe("#padNum(x,width,padOpts", function() {
961
- var tests = [
962
- {args: [123,5], expected: " 123"},
963
- {args: [1234,5], expected: " 1234"},
964
- {args: [123,5, {pad:"x"}], expected: "xx123"},
965
- {args: ["abc",5, {pad:"x"}], expected: "xxabc"}
966
- ];
967
-
968
- tests.forEach(function(test) {
969
- it("bw.padNum " + test.args.length + " args", function() {
970
- var res = bw.padNum.apply(null, test.args);
971
- assert.deepEqual(res, test.expected);
972
- });
973
- });
974
- });
975
-
976
- // ================================================================
977
- describe("#bw.trim(str,dir)", function() {
978
- var tests = [
979
- {args: [" abc "], expected: "abc"},
980
- {args: [" abc ","left"], expected: "abc "},
981
- {args: [" abc ","right"], expected: " abc"},
982
- {args: [" abc ","both"], expected: "abc"},
983
- {args: [" abc ","none"], expected: " abc "}
984
-
985
- ];
986
-
987
- tests.forEach(function(test) {
988
- it("bw.trim " + test.args.length + " args", function() {
989
- var res = bw.trim.apply(null, test.args);
990
- assert.deepEqual(res, test.expected);
991
- });
992
- });
993
- });
994
- // ================================================================
995
- describe("#padString(x,width,padOpts", function() {
996
- var tests = [
997
- {args: ["this is it",20,"left"] , expected: " this is it"},
998
- {args: ["this is it",20,"right"], expected: "this is it "},
999
- {args: ["this is it",20,"center"], expected: " this is it "},
1000
- {args: ["this is it",20,"center",{trimDir:"both",pad:"x"}], expected: "xxxxxthis is itxxxxx"},
1001
- ];
1002
-
1003
- tests.forEach(function(test) {
1004
- it("bw.padString " + test.args.length + " args", function() {
1005
- var res = bw.padString.apply(null, test.args);
1006
- assert.deepEqual(res, test.expected);
1007
- });
1008
- });
1009
- });
1010
- // ================================================================
1011
- describe("#random(x,lo,hi,opts) - generate a random number between lo, hi", function() {
1012
-
1013
-
1014
- it("bw.random () ", function() {
1015
- var res = bw.random();
1016
- assert( (res >= 0 && res <=100));
1017
- });
1018
- it("bw.random (20,30) ", function() {
1019
- var res = bw.random(20,30);
1020
- assert( (res >= 20 && res <=30));
1021
- });
1022
- it("bw.random (0,1,{setType:'float'}) ", function() {
1023
- var res = bw.random(0,1,{setType:"float"});
1024
- assert( (res >= 0 && res <=1));
1025
- });
1026
- it("bw.random (0,1,{setType:'float'}) ", function() {
1027
- var res = bw.random(30,40,{setType:"int",dims:[2,2]});
1028
- res = [res[0][0], res[0][1], res[1][0], res[1][1]];
1029
- assert( res.filter(x => (x>40) ||(x< 30)).length == 0);
1030
- });
1031
- });
1032
-
1033
- // ================================================================
1034
-
1035
- describe("#prandom(x,lo,hi,opts) - generate a random number between lo, hi, using a seed (repeated able random #s)", function() {
1036
-
1037
-
1038
- it("bw.prandom () ", function() {
1039
- var res = bw.random();
1040
- assert( res != 73);
1041
- });
1042
- it("bw.prandom (20,30) ", function() {
1043
- var res = bw.prandom(20,30);
1044
- assert( (res >= 20 && res <=30));
1045
- });
1046
- it("bw.prandom (0,1,10,{setType:'float'}) ", function() {
1047
- var res = bw.prandom(0,1,{setType:"float"});
1048
- assert( (res >= 0 && res <=1));
1049
- });
1050
- it("bw.random (0,1,{setType:'float'}) ", function() {
1051
- var res = bw.prandom(30,40,10,{setType:"int",dims:[2,2]});
1052
- res = [res[0][0], res[0][1], res[1][0], res[1][1]];
1053
- assert( res.filter(x => (x>40) ||(x< 30)).length == 0);
1054
- });
1055
- });
1056
-
1057
- // ================================================================
1058
- describe("#hashFnv32a(str, seed, returnAsHexStr) - generate a quick checksum (Fnv32a) of a string", function() {
1059
- var tests = [
1060
- {args: ["this is it"] , expected: 3562000208},
1061
- {args: ["this is it",32] , expected: 2503917409},
1062
- {args: ["this is it",33] , expected: 857015836},
1063
- {args: ["this is it",32,true] , expected: "953ebf61"}
1064
-
1065
- ];
1066
-
1067
- tests.forEach(function(test) {
1068
- it("bw.hashFnv32a " + test.args.length + " args", function() {
1069
- var res = bw.hashFnv32a.apply(null, test.args);
1070
- assert.deepEqual(res, test.expected);
1071
- });
1072
- });
1073
-
1074
- });
1075
- // ================================================================
1076
- describe("#CSSSimpleStyles (appendToHead, options) create the default bitwrench CSS styles, classes", function() {
1077
- var tests = [
1078
- {args: [] ,
1079
- expected:
1080
- `
1081
- *{box-sizing:border-box;}
1082
- .bw-def-page-setup{height:100%;width:90%;margin:0 auto;padding-left:2%;padding-right:2%;left:0;top:1%;box-sizing:border-box;}
1083
- .bw-font-serif{font-family:Times New Roman, Times, serif;}
1084
- .bw-font-sans-serif{font-family:Arial, Helvetica, sans-serif;}
1085
-
1086
- .bw-left{text-align:left;}
1087
- .bw-right{text-align:right;}
1088
- .bw-center{text-align:center;margin:0 auto;}
1089
- .bw-justify{text-align:justify;}
1090
- .bw-code{font-family:monospace;white-space:pre-wrap;}
1091
- .bw-pad1{padding-left:1%;padding-right:1%;}
1092
-
1093
- .bw-table{border-collapse:collapse;border-spacing:0;border:1px solid #444;}
1094
- .bw-table th{background-color:#bbb;padding:4px;border:1px solid #444;}
1095
- .bw-table td{padding:4px;border:1px solid #444;}
1096
- .bw-table-stripe tr:nth-child(even){background-color:#f0f0f0;}
1097
- .bw-table tr td:first-child{font-weight:700;}
1098
- .bw-table-border-round{border-radius:2px;}
1099
- .bw-table-sort-upa::after{content:\"\\2191\";}
1100
- .bw-table-sort-dna::after{content:\"\\2193\";}
1101
- .bw-table-sort-xxa::after{content:\"\\00a0\";}
1102
-
1103
- .bw-tab-item-list{margin:0;padding-inline-start:0;}
1104
- .bw-tab-item{display:inline;padding-top:0.5em;padding-left:0.75em;padding-right:0.75em;border-top-right-radius:7px;border-top-left-radius:7px;}
1105
- .bw-tab-active{font-weight:700;}
1106
- .bw-tab:hover{cursor:pointer;font-weight:700;}
1107
- .bw-tab-content-list{margin:0;padding-top:0.0em;}
1108
- .bw-tab-content{display:none;border-radius:0;}
1109
- .bw-tab-content, .bw-tab-active{background-color:#ddd;padding:0.5em;}
1110
-
1111
- .bw-accordian-container > div{padding:0.5em;}
1112
-
1113
- .bw-container{margin:0 auto;}
1114
- .bw-row{width:100%;display:block;}
1115
- .bw-row [class^=\"bw-col\"]{float:left;}
1116
- .bw-row::after{content:\"\";display:table;clear:both;}
1117
- .bw-box-1{padding-top:10px;padding-bottom:10px;border-radius:8px;}
1118
-
1119
- .bw-sign{position:inherit;display:table;height:100%;width:100%;}
1120
- .bw-sign > div{display:table-cell;vertical-align:middle;}
1121
- .bw-sign > div > div{text-align:center;}
1122
-
1123
- .bw-hide{display:none;}
1124
- .bw-show{display:block;}
1125
- .bw-h1{font-size:2.312rem;}
1126
- .bw-h2{font-size:1.965rem;}
1127
- .bw-h3{font-size:1.67rem;}
1128
- .bw-h4{font-size:1.419rem;}
1129
- .bw-h5{font-size:1.206rem;}
1130
- .bw-h6{font-size:1.025rem;}
1131
-
1132
- .bw-col-1{width:8.333%;}
1133
- .bw-col-2{width:16.666%;}
1134
- .bw-col-3{width:25%;}
1135
- .bw-col-4{width:33.333%;}
1136
- .bw-col-5{width:41.666%;}
1137
- .bw-col-6{width:50%;}
1138
- .bw-col-7{width:58.333%;}
1139
- .bw-col-8{width:66.666%;}
1140
- .bw-col-9{width:75%;}
1141
- .bw-col-10{width:83.333%;}
1142
- .bw-col-11{width:91.666%;}
1143
- .bw-col-12{width:100%;}
1144
-
1145
- .bw-color-color {color:#000}
1146
- .bw-color-background-color {background-color:#ddd}
1147
- .bw-color-active {active:#222}
1148
- .bw-thm-light
1149
- {
1150
- color: #020202 !important;;
1151
- background-color: #e2e2e2 !important;;
1152
- }
1153
- .bw-thm-dark
1154
- {
1155
- color: #e2e2e2 !important;;
1156
- background-color: #020202 !important;;
1157
- }
1158
- @media only screen and (min-width: 540px) {.bw-def-page-setup {width: 96%;}}
1159
- @media only screen and (min-width: 720px) {.bw-def-page-setup {width: 92%;}}
1160
- @media only screen and (min-width: 960px) {.bw-def-page-setup {width: 88%;}}
1161
- @media only screen and (min-width: 1100px){.bw-def-page-setup {width: 86%;}}
1162
- @media only screen and (min-width: 1600px){.bw-def-page-setup {width: 84%;}}
1163
- `
1164
-
1165
- }
1166
-
1167
- ];
1168
-
1169
- tests.forEach(function(test) {
1170
- it("CSSSimpleStyles " + test.args.length + " args", function() {
1171
- var res = bw.CSSSimpleStyles.apply(null, test.args);
1172
- assert.deepEqual(res, test.expected);
1173
- });
1174
- });
1175
-
1176
- });
1177
-
1178
- // ================================================================
1179
- describe("#CSSSimpleThemes (index, options) simple styles for live use", function() {
1180
- var tests = [
1181
- {args: [1,false,{}] ,
1182
- expected:
1183
- `*{background-color:#f8f8f8;color:#111;font-family:sans-serif;box-sizing:border-box;}
1184
- body{margin-top:1%;}
1185
- th{background-color:#ddd;}
1186
- tbody tr:nth-child(even){background-color:#ddd;}
1187
- table,td,th{border-collapse:collapse;border:1px solid #111;}
1188
- td,th{padding:4px;}
1189
- div,body,button,table,input{border-radius:2px;}`
1190
- }
1191
-
1192
- ];
1193
-
1194
- tests.forEach(function(test) {
1195
- it("CSSSimpleThemes " + test.args.length + " args", function() {
1196
- var res = bw.CSSSimpleThemes.apply(null, test.args);
1197
- assert.deepEqual(res, test.expected);
1198
- });
1199
- });
1200
-
1201
- });
1202
-
1203
- // ================================================================
1204
- describe("#bw.selectTabContent()", function() {
1205
- /**
1206
-
1207
-
1208
- */
1209
-
1210
- let window;
1211
- beforeEach(() => {
1212
- var myTabs =
1213
- `
1214
- <div class="bw-tab-container"> <!-- bw-tab-container -- bw-tab-items (array of items), bw-tab-content (array of content to show) -->
1215
- <ul class="bw-tab-item-list"> <!-- container for the tabs -->
1216
- <li class="bw-tab userTab bw-tab-active" onclick="bw.selectTabContent(this)" >Tab 1</li>
1217
- <li class="bw-tab userTab " onclick="bw.selectTabContent(this)" >Tab 2</li>
1218
- <li class="bw-tab userTab " onclick="bw.selectTabContent(this)" >Tab 3</li>
1219
- <li class="bw-tab userTab " onclick="bw.selectTabContent(this)" >Tab 4</li>
1220
- </ul>
1221
- <div class="bw-tab-content-list"> <!-- container for the tab content -->
1222
- <div class="bw-tab-content bw-show" >coontent area 1 </div> <!-- bw-show picks which tab to make active at first -->
1223
- <div class="bw-tab-content" >content area 2</div>
1224
- <div class="bw-tab-content" >content 3</div>
1225
- <div class="bw-tab-content" >content 4</div>
1226
- </div> <!-- end of tab content sect -->
1227
- </div>
1228
- `
1229
- const testDoc = `<!DOCTYPE html><html><head></head><body><span id="myTestSpan">starter</span>{$myTabs}<div class="foo">default</div></body></html>`;
1230
- window = (new JSDOM(testDoc, { runScripts: "dangerously" })).window;
1231
-
1232
- // Execute my library by inserting a <script> tag containing it.
1233
- const scriptEl = window.document.createElement("script");
1234
- scriptEl.textContent = bitwrenchFile;
1235
- window.document.head.appendChild(scriptEl);
1236
- });
1237
-
1238
- it("selectTab()", () => {
1239
-
1240
- //assert.equal(window.bw.isNodeJS(), false); // test jsdom is using bw correctly in window context
1241
- });
1242
- });
1243
- // ================================================================
1244
- describe("#version() returns version info at runtime", function() {
1245
- it("version() " + 0 + " args", function() {
1246
- var res = bw.version();
1247
- assert(res.version.split(".").length>=3);
1248
- assert((res.hasOwnProperty("about")));
1249
- assert((res.hasOwnProperty("copy")));
1250
- assert((res.hasOwnProperty("url")));
1251
- assert.equal(res.license , "BSD-2-Clause");
1252
-
1253
- });
1254
- });
1255
-