This repository was archived by the owner on Oct 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
executable file
·2086 lines (1997 loc) · 59.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>bpmv.js</title>
<!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="../bpmv.js"></script>
<script src="assets/toc.js"></script>
<link rel="stylesheet" type="text/css" href="assets/bpmv.css"></link>
<style>
</style>
</head>
<body>
<a href="https://github.com/BrynM/bpmv" target="_blank"><img style="position: fixed; top: 0; left: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_left_orange_ff7600.png" alt="Fork me on GitHub"></a>
<div class="contain">
<h1 id="page_header">bpmv.js</h1>
</div>
<div class="contain contain_docs">
<h2>Introduction</h2>
<div class="subcontain">
<div>
<h3>What's bpmv.js and why should I use it?</h3>
<p>
These are tasks that I find myself repeating over and over again.
The rules for me including code in here are simple: nothing that tries to manipulate the DOM itself and things that mainly revolve around testing or altering different kinds of states or values.
</p>
<p>
I provide no promises that I will follow my own rules or that any of this code is fit for any purpose.
This is a personal library and not a full-blown open source project.
I will add and remove what I see fit.
Consider yourself warned.
</p>
<p>
That said, I do hope that you can find something you like here.
I would recommend that you use a descreet copy and do not load the file from a pulbic source (as I may refactor on a whim).
If you wish to use a copy of this code, feel free, but also remember that it's GPL - meaning that if you distribute your altered copy in any way (such as serving it publicly), you must follow the conditions outlined in the GPL.
</p>
</div>
</div>
<h2>Full Usage Documentation</h2>
<div class="subcontain">
<div class="usage">
<h3>Optional Browser Setup</h3>
<p>
By default, the global variable `bpmv` will be created (attached to `window`).
If node.js is detected as the current environment, `exports.bpmv` will be created.
Additionally, there are two (admittadly sloppy) global settings you can use to control bpmv.
</p>
<p>
If you do not wish to have bpmv called `bpmv`, you can set BPMV_VARNAME to any string you wish.
For example:
</p>
<pre class="lined"><code>BPMV_VARNAME = 'validatorThingy';
// ...bpmv.js is loaded via >script< tag or some other method
validatorThingy.str( 'foo' ); // use it to test a string</code></pre>
</p>
<p>
At file/script load, the varialbe BPMV_ATTACH will be checked or "object-ness".
If it is an object, you can use it to attach bpmv to a structure of your choice.
For example:
</p>
<pre class="lined"><code>var BPMV_ATTACH = my.big.construct;
// ...bpmv.js is loaded via >script< tag or some other method
// loading the file _after_ setting BPMV_ATTACH is important!
// (I do realize that this pollutes the current scope some. Sorry.)
my.big.construct.bpmv.str( 'foo' ); // attached and ready for use</code></pre>
<p>
Used together, BPMV_ATTACH and BPMV_VARNAME should give you enough control to avoid any name clashing and perform any customization you'd like.
</p>
</div>
<div class="usage">
<h3>.arr ( dIsArr, okEmpty )</h3>
<p class="description">
No, this doesn't test for piracy.
bpmv.arr() tests if something is not just an object, but is an Array object and is not empty. It can also test if the thing optionally has some or a specific number of elements.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>dIsArr</td>
<td>mixed</td>
<td>The value you'd like to test.</td>
</tr>
<tr>
<td>okEmpty</td>
<td>mixed</td>
<td>
okEmpty If Boolean, is a flag for whether the array will be tested for emptiness.
If an integer, will test the array for that exact length.
</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>boolean</td>
<td>Will return true if an array with contents (or optionally passes okEmpty) and false if not or upon failure.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<div class="examples">
<pre class="lined"><code>// these return false
bpmv.arr( [] );
bpmv.arr( [ 'booty' ], 0 );
bpmv.arr( [ 'booty', 'treasure' ], 1 );
// these return true
bpmv.arr( [], true );
bpmv.arr( [], 0 );
bpmv.arr( [ 'booty' ] );
bpmv.arr( [ 'booty' ], 1 );
bpmv.arr( [ 'booty', 'treasure' ], 2 );</code></pre>
</div>
</div>
<div class="usage">
<h3>.basename ( redOrBlue )</h3>
<p class="description">
Get the basename of a filesystem path or URL.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>redOrBlue</td>
<td>string</td>
<td>
Some sort of filesystem path or URL.
The path can be in either standard (slashes) or Windows (backslashes) format.
</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>string</td>
<td>Returns the parsed dirname.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>bpmv.basename( '/' ); // returns '/'
bpmv.basename( '/path/to/a/thing' ); // returns 'thing'
bpmv.basename( '/path/to/a/thing/' ); // returns 'thing'
bpmv.basename( 'C:\\' ); // returns 'C:\'
bpmv.basename( 'C:\\Program Files\\App\\thing' ); // returns 'thing'
bpmv.basename( 'C:\\Program Files\\App\\thing\\' ); // returns 'thing'
bpmv.basename( 'http://google.com' ); // returns 'http://google.com'
bpmv.basename( 'http://google.com/' ); // returns 'http://google.com'
bpmv.basename( 'http://google.com/mail' ); // returns 'mail'
</code></pre>
</div>
<div class="usage">
<h3>.bool ( fool )</h3>
<p class="description">
Test to see if something is a proper Boolean object.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>fool</td>
<td>mixed</td>
<td>The value you'd like to test.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>boolean</td>
<td>Will return true if the value is a real Boolean object.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// these return false
bpmv.bool( 0 );
bpmv.bool( 1 );
bpmv.bool( 'true' );
bpmv.bool( 'yar' );
bpmv.bool( 'yes' );
// these return true
bpmv.bool( true );
bpmv.bool( false );</code></pre>
</div>
<div class="usage">
<h3>.brow ()</h3>
<p class="description">
Are we in a web browser (returns bool, not UA!)?
</p>
<div class="parameters">
<table>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>boolean</td>
<td>Returns true if we are in a browser environment with window and navigator objects.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>bpmv.brow(); // run in node - returns false
bpmv.brow(); // run in Chrome - returns true
bpmv.brow(); // run in a Firefox extension - returns true</code></pre>
</div>
<div class="usage">
<h3>.ccase ( hump, wspace, spit )</h3>
<p class="description">
Convert a string to camelCase.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>hump</td>
<td>string</td>
<td>The string to convert.</td>
</tr>
<tr>
<td>wspace</td>
<td>mixed</td>
<td>
The whitespace character(s) you would like to remove for the conversion.
If a character, it can be an entire string or several comma separated characters (no whitespace around your commas).
wspace can also be an Array of characters.
The default wspace is [ ' ', '_', '-', '\r', '\n' ].
</td>
</tr>
<tr>
<td>spit</td>
<td>boolean</td>
<td>If spit is true, the first letter of the string will be capitalized.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>string</td>
<td>
Returns the camel cased version of your string.
If the hump parameter is not a string, it will be returned as-is to prevent destruction ot loss.
</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>bpmv.ccase( 'This is some stuff' ); // returns 'thisIsSomeStuff'
bpmv.ccase( 'This_is_some_stuff' ); // returns 'thisIsSomeStuff'
bpmv.ccase( 'This-is-some-stuff' ); // returns 'thisIsSomeStuff'
bpmv.ccase( 'This is-some_stuff' ); // returns 'thisIsSomeStuff'
bpmv.ccase( 'This is\nstuff', [ '\n' ] ); // returns 'this isStuff'
bpmv.ccase( 'This is_stuff.', ' ', true ); // returns 'ThisIs_stuff.'
bpmv.ccase( 'look its a class_name', null, true ); // returns 'LookItsAClassName'</code></pre>
</div>
<div class="usage">
<h3>.clone ( alphaComplex, outDoors )</h3>
<p class="description">
Tell the Great and Mighty Computer to clone your troubleshooter... er... thing.
Note that cloning a function will create an anonymous function (not sure how to fix).
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>alphaComplex</td>
<td>mixed</td>
<td>The thing you want to clone.</td>
</tr>
<tr>
<td>outDoors</td>
<td>boolean</td>
<td>Whether to perform a "deep" clone (recursion warning!).</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>mixed</td>
<td>A copy of the thing or undefined on failure.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// examples</code></pre>
</div>
<div class="usage">
<h3>.cook ( muppet, chips, reruns )</h3>
<p class="description">
Get or set a simple, pathless browser cookie.
If all parms are undefined, the full set of cookies will be returned.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>muppet</td>
<td>string</td>
<td>The name of the cookie.</td>
</tr>
<tr>
<td>chips</td>
<td>string</td>
<td>The value of the cookie if you are setting one.</td>
</tr>
<tr>
<td>reruns</td>
<td>string</td>
<td>
Optional cookie expiration date to use when setting a cookie.
The default cookie expiration is 1 year from the current date.
</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>string</td>
<td>
Will return the value of the cookie.
If setting a cookie and setting fails, undefined will be returned instead of the value.
</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// examples</code></pre>
</div>
<div class="usage">
<h3>.count ( ahAHah )</h3>
<p class="description">
Count number of elements or properties an object actually owns.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>ahAHah</td>
<td>mixed</td>
<td>The object you'd like to count.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>number</td>
<td>Will return the count of elements owned by the object.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// examples</code></pre>
</div>
<div class="usage">
<h3>.date ( whEn )</h3>
<p class="description">
Test that something is a date object (or in a future addition, a valid date string - todo).
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>whEn</td>
<td>mixed</td>
<td>The value you would like to test.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>boolean</td>
<td>Will return true if the value is a real Date object.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// examples</code></pre>
</div>
<div class="usage">
<h3>.dirname ( wellDuh )</h3>
<p class="description">
Get the dirname of a filesystem path or URL.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>wellDuh</td>
<td>string</td>
<td>Some sort of filesystem path or URL.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>string</td>
<td>The parsed dirname.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// examples</code></pre>
</div>
<div class="usage">
<h3>.ego ( fans )</h3>
<p class="description">
Generate a random valid html id using characters and a timestamp.
This is the only bpmv.js function that takes an options object parameter.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>fans</td>
<td>object</td>
<td>An options object. Defaults are listed below.
<pre class="lined"><code>var defaults = {
// Length of the string to generate (see absLen for forced truncation).
'len' : 12,
// A prefix to apply to the ID string generated
'prefix' : '',
// The character set (string list of characters) to choose from for
// generating the "random" portion of the ID.
'charset' : '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
// If set to true, a delimiter and integer UNIX time stamp will be appended
// to the generated ID string.
'useTime' : true,
// If set to true, the entire return string will be truncated to the len
// setting. Note that this may truncate away desired portions such as
// timestamps. (legacy and kind of useless)
'absLen' : false,
// The delimiter to use between portions of the ID string (prefix, id and
// time stamp).
'delim' : '_'
};</code></pre></td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>string</td>
<td>The generated ID.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// returns something like 'ABC12DEF34GH_1234567890123'
bpmv.ego();
// returns something like 'ABC_1234567890123'
bpmv.ego( { len : 3 } );
// returns something like 'mine_ABC12DEF34GH_1234567890123'
bpmv.ego( { prefix : 'mine' } );
// returns something like 'inimmieimmim_1234567890123'
bpmv.ego( { charset : 'mine' } );
// returns something like 'ABC12DEF34GH'
bpmv.ego( { useTime : false } );
// returns something like 'ABC'
bpmv.ego( { len : 3, absLen : true } );
// returns something like 'ABC12DEF34GH+1234567890123'
bpmv.ego( { delim : '+' } );
// returns something like 'mine+ABC12DEF34GH+1234567890123'
bpmv.ego( { prefix : 'mine', delim : '+' } );
// let's get fancy
var egoOptions = {
len : 25
, prefix : 'BIG_NUM'
, charset : '123456789'
, useTime : false
}
bpmv.ego( egoOptions ); // returns something like 'mine+ABC12DEF34GH+1234567890123'</code></pre>
</div>
<div class="usage">
<h3>.env ()</h3>
<p class="description">
An alias to combine bpmv.node() and bpmv.brow() into a single call (for varialbe storage).
</p>
<div class="parameters">
<table>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>string</td>
<td>
Will return which "environment" is in service if known and 'undefined' if not.
Currently, only "browser" and "node" are supported.
If neither of those can be found, then undefined is returned.
</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>bpmv.env(); // returns 'browser' in a web browser
bpmv.env(); // returns 'node' in node.js
bpmv.env(); // returns undefined in Adobe Photoshop</code></pre>
</div>
<div class="usage">
<h3>.find ( pin, stack, siv )</h3>
<p class="description">
Find the property name for a given element in an object or array.
The first encountered match is what will be returned,
so be carefult that what you are looking for is unique!
If the property is not found, null is returned.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>pin</td>
<td>mixed</td>
<td>
What you are looking for.
Can be any valid value.
</td>
</tr>
<tr>
<td>stack</td>
<td>mixed</td>
<td>The object or array you are looking in.</td>
</tr>
<tr>
<td>boolean</td>
<td>siv</td>
<td>
Assume the pin is not === and instead is the keyname of what you're looking for.
If this option is true, the value of the property will be returned if found.
</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>mixed</td>
<td>The name of the property if found or null if not found.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>function foo () {}
var thing = {
'func' : foo
, 'bar' : 'stuff'
, 'baz' : 2
, 'boo' : null
}
bpmv.find( foo, thing ); // returns 'func'
bpmv.find( 'stuff', thing ); // returns 'bar'
bpmv.find( null, thing ); // returns 'boo'</code></pre>
</div>
<div class="usage">
<h3>.float ( mFreak, zeroOk )</h3>
<p class="description">
Tests strings and numbers for valid floating point format and greater than 0 (may be optionally disabled).
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>mFreak</td>
<td>mixed</td>
<td>The value you'd like to test.</td>
</tr>
<tr>
<td>zeroOk</td>
<td>boolean</td>
<td>Will return true even if the the value is 0 or less.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>boolean</td>
<td>Will return true if the value is a valid floating point number.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// these return true
bpmv.float( 1.234 );
bpmv.float( 1 );
bpmv.float( -1, true );
bpmv.float( 1.234 );
bpmv.float( '1.234' );
// these return false
bpmv.float( -1 );
bpmv.float( -1.234 );
bpmv.float( 'aa1' );</code></pre>
</div>
<div class="usage">
<h3>.func ( boOtsy )</h3>
<p class="description">
Is a thing a function?
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>boOtsy</td>
<td>mixed</td>
<td>The value you'd like to test.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>boolean</td>
<td>Will return true if the value is a real function (anonymous or named).</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// these return true
bpmv.func( Date );
bpmv.func( function () {} );
bpmv.func( document.getElementById ); // (in a browser)
// these return false
bpmv.func( 1 );
bpmv.func( 'George' );
bpmv.func( (function () {})() ); // (the function is returning a value)
// list all of the functions of the document object in a browser
for ( var p in document ) {
if ( bpmv.func(document[p]) ) {
console.log( p, document[p] );
}
}</code></pre>
</div>
<div class="usage">
<h3>.grab ( leggo, eggo )</h3>
<p class="description">
Grab a deep property from an object by its string name.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>leggo</td>
<td>string</td>
<td>The deep property you are looking for. For example "foo.bar.baz".</td>
</tr>
<tr>
<td>eggo</td>
<td>object</td>
<td>The object you're looking in.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>mixed</td>
<td>Will return the value of that property or undefined if not found.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// returns the document.getElementById() function for the current window
bpmv.grab( 'document.getElementById', window );
// returns the document.getElementById() function for the current window
bpmv.grab( 'getElementById', window.document );</code></pre>
</div>
<div class="usage">
<h3>.host ( drinks, justaSingle )</h3>
<p class="description">
Check if a string is a valid hostname with at least a TLD component.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>drinks</td>
<td>string</td>
<td>
The string you'd like to test.
Note that passing other parts of an URL, such as the protocol, path, parameters or delimiters will fail and return false.
</td>
</tr>
<tr>
<td>justaSingle</td>
<td>boolean</td>
<td>
Allow tests for just a single host name without at TLD.
</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>boolean</td>
<td>Will return true if the value is a valid host name (by default with at least two levels - name plus tld).</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// examples</code></pre>
</div>
<div class="usage">
<h3>.incall ( soil, fertilizer, weeds, flo )</h3>
<p class="description">
Increment all numeric values in either an array or the top level of an object by a given amount.
Note that this will also increment numbers inside of strings.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>soil</td>
<td>mixed</td>
<td>The array or object to increment values in.</td>
</tr>
<tr>
<td>fertilizer</td>
<td>number</td>
<td>
The amount you'd like the numbers incremented.
This can be a positive or negative value - including 0.
Floats are perfectly valid, but integer values being incremented by floats will be rounded.
To control the rounding behavior, see the flo parameter.
Defaults to 1.
</td>
</tr>
<tr>
<td>weeds</td>
<td>boolean</td>
<td>
Increment numeric strings too.
If false, only proper Number values will be incremented.
Defaults to true.
</td>
</tr>
<tr>
<td>flo</td>
<td>boolean</td>
<td>
Normally, when an integer value is being incremented by a float, the integer will be rounded using Math.round().
To force them to be converted to floating point numbers, pass this parameter as true.
Defaults to false.
</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>mixed</td>
<td>Will return the reultant version of soil.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>bpmv.incall( [ 1, 1.25, 0 ], 1.6 ); // returns [ 3, 2.85, 2 ]
bpmv.incall( [ 1, 1.25, 0, '2.2' ], 1.6 ); // returns [ 2.6, 2.85, 1.6, "2.2" ]
bpmv.incall( [ 1, 1.25, 0, '2.2' ], 1.6, true ); // returns [ 3, 2.85, 2 ]
bpmv.incall( [ 1, 1.25, 0 ], 1.6 ); // returns [ 3, 2.85, 2 ]
</code></pre>
</div>
<div class="usage">
<h3>.ini ( outie, gotDfunk )</h3>
<p class="description">
Parse ini file contents into an object if possible with optional callback.
The contents may be a string with newlines or an Array() of strings.
This always returns an object, so check for emptiness.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>outie</td>
<td>string</td>
<td>The string or array contents of an ini file.</td>
</tr>
<tr>
<td>gotDfunk</td>
<td>function</td>
<td>An optional callback function to run when parsing is complete.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>object</td>
<td>Will return an object representing the parsed ini values and structure.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// examples</code></pre>
</div>
<div class="usage">
<h3>.int ( threeD6, zeroOk )</h3>
<p class="description">
Tests strings and numbers for valid integer format and greater than 0 (may be disabled).
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>threeD6</td>
<td>mixed</td>
<td>The value you'd like to test.</td>
</tr>
<tr>
<td>zeroOk</td>
<td>boolean</td>
<td>Will return true even if the the value is 0 or less.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>boolean</td>
<td>Will return true if the value is a valid integer.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// examples</code></pre>
</div>
<div class="usage">
<h3>.ip ()</h3>
<p class="description">
Tests that a string is a valid IP address.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>numba</td>
<td>string</td>
<td>
The value you'd like to test.
Can be IPv4 decimal.
</td>
</tr>
<tr>
<td>v6</td>
<td>boolean</td>
<td>
Test for an IPV6 addresses as well.
Normally, this function tests for IPV4.
With v6 set to true, a string can be tested for both IPV6 and IPV4.
This option is to prevent executing RegExp as long as your arm unless you need it.
</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>boolean</td>
<td>Will return true if the value is a valid IP address.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// examples</code></pre>
</div>
<div class="usage">
<h3>.isadog ( namedRex )</h3>
<p class="description">
Will test if something is a RegExp object.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>namedRex</td>
<td>mixed</td>
<td>The regular expression object you'd like to test.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>boolean</td>
<td>Returns true if the object was a RegExp.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// examples</code></pre>
</div>
<div class="usage">
<h3>.isjson ( davesNotHere )</h3>
<p class="description">
Will (loosely) test if something is a JSON string.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>davesNotHere</td>
<td>string</td>
<td>The string to test.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>boolean</td>
<td>Returns true if davesNotHere was a JSON string.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// examples</code></pre>
</div>
<div class="usage">
<h3>.keys ( lock, sort )</h3>
<p class="description">
Will return an optionally sorted array containing the top level property names ("keys") from an object or array.
</p>
<div class="parameters">
<table>
<thead><tr><th>Parameter</th><th>Type</th><th>Explanation</th></tr></thead>
<tbody>
<tr>
<td>lock</td>
<td>mixed</td>
<td>The object or array you want the keys from.</td>
</tr>
<tr>
<td>sort</td>
<td>boolean</td>
<td>If true, the returned array will be sorted.</td>
</tr>
</tbody>
<tfoot>
<tr class="return"><td>RETURN:</td>
<td>array</td>
<td>Returns an array of strings containing the keys.</td>
</tr>
</tfoot>
</table>
</div>
<h5>Examples</h5>
<pre class="lined"><code>// examples</code></pre>
</div>