1+ /**
2+ _ ____ _ _ __ ____ ___
3+ | | _ \ / \ | |/ / __ _|___ \ / _ \
4+ _ | | |_) / _ \ | ' / \ \ / / __) || | | |
5+ | |_| | __/ ___ \| . \ \ V / / __/ | |_| |
6+ \___/|_| /_/ \_\_|\_\ \_/ |_____(_)___/
7+
8+ Multiuse Javascript Package
9+ https://github.com/TeskeVirtualSystem/jpak
10+
11+ The MIT License (MIT)
12+
13+ Copyright (c) 2013 Lucas Teske
14+
15+ Permission is hereby granted, free of charge, to any person obtaining a copy of
16+ this software and associated documentation files (the "Software"), to deal in
17+ the Software without restriction, including without limitation the rights to
18+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
19+ the Software, and to permit persons to whom the Software is furnished to do so,
20+ subject to the following conditions:
21+
22+ The above copyright notice and this permission notice shall be included in all
23+ copies or substantial portions of the Software.
24+
25+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
27+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
28+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
29+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31+
32+ **/
33+
34+ var JPAK = {
35+ Generics : { } ,
36+ Loader : { } ,
37+ Classes : { } ,
38+ Tools : { }
39+ } ;
40+
41+ ( function ( ) {
42+
43+ var inNode = ( typeof module !== 'undefined' && typeof module . exports !== 'undefined' ) ;
44+
45+ if ( inNode ) {
46+ JPAK . Tools . toBuffer = function ( ab ) {
47+ var buffer = new Buffer ( ab . byteLength ) ;
48+ var view = new Uint8Array ( ab ) ;
49+ for ( var i = 0 ; i < buffer . length ; ++ i ) {
50+ buffer [ i ] = view [ i ] ;
51+ }
52+ return buffer ;
53+ } ;
54+
55+ JPAK . Tools . toArrayBuffer = function ( buffer ) {
56+ var ab = new ArrayBuffer ( buffer . length ) ;
57+ var view = new Uint8Array ( ab ) ;
58+ for ( var i = 0 ; i < buffer . length ; ++ i ) {
59+ view [ i ] = buffer [ i ] ;
60+ }
61+ return ab ;
62+ } ;
63+ }
64+
65+ /*
66+ * Extends the Uint8Array to be able to be converted to a string
67+ */
68+ Uint8Array . prototype . asString = function ( ) {
69+ var o = "" ;
70+ for ( var i = 0 ; i < this . byteLength ; i ++ )
71+ o += String . fromCharCode ( this [ i ] ) ;
72+ return o ;
73+ } ;
74+
75+ /*
76+ * Puts a string inside the UInt8Array
77+ */
78+ Uint8Array . prototype . putString = function ( offset , string ) {
79+ if ( string === undefined ) {
80+ string = offset ;
81+ offset = 0 ;
82+ }
83+ for ( var i = 0 ; i < string . length ; i ++ ) {
84+ this [ offset + i ] = string . charCodeAt ( i ) ;
85+ }
86+ return offset + string . length ;
87+ } ;
88+
89+ /*
90+ * Converts itself to an object.
91+ *
92+ * To associate with a prototype.
93+ */
94+ JPAK . Generics . genericToObject = function ( ) {
95+ var output = { } ;
96+ for ( var property in this ) {
97+ if ( this . hasOwnProperty ( property ) ) {
98+ output [ property ] = this [ property ] . toObject !== undefined ? this [ property ] . toObject ( ) : this [ property ] ;
99+ }
100+ }
101+ return output ;
102+ } ;
103+
104+ /*
105+ * Fills its own properties based on a input object.
106+ *
107+ * To associate with a prototype.
108+ */
109+ JPAK . Generics . genericFromObject = function ( object ) {
110+ for ( var property in object ) {
111+ if ( object . hasOwnProperty ( property ) ) {
112+ this [ property ] = object [ property ] ;
113+ }
114+ }
115+ } ;
116+
117+
118+ /*
119+ * Converts itself to a JSON.
120+ *
121+ * To associate with a prototype.
122+ */
123+ JPAK . Generics . genericjToJSON = function ( ) {
124+ return JSON . stringify ( this . toObject ( ) ) ;
125+ } ;
126+
127+
128+ /*
129+ * Fills its own properties based on a json
130+ *
131+ * To associate with a prototype.
132+ */
133+ JPAK . Generics . genericjFromJSON = function ( json ) {
134+ this . fromObject ( JSON . parse ( json ) ) ;
135+ } ;
136+
137+
138+ } ) ( ) ;
0 commit comments