@pokash/n8n-nodes-ksef 0.2.12 → 0.2.16

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 (645) hide show
  1. package/node_modules/@oozcitak/dom/LICENSE +21 -0
  2. package/node_modules/@oozcitak/dom/README.md +32 -0
  3. package/node_modules/@oozcitak/dom/lib/algorithm/AbortAlgorithm.d.ts +21 -0
  4. package/node_modules/@oozcitak/dom/lib/algorithm/AbortAlgorithm.js +79 -0
  5. package/node_modules/@oozcitak/dom/lib/algorithm/AbortAlgorithm.js.map +1 -0
  6. package/node_modules/@oozcitak/dom/lib/algorithm/AttrAlgorithm.d.ts +8 -0
  7. package/node_modules/@oozcitak/dom/lib/algorithm/AttrAlgorithm.js +23 -0
  8. package/node_modules/@oozcitak/dom/lib/algorithm/AttrAlgorithm.js.map +1 -0
  9. package/node_modules/@oozcitak/dom/lib/algorithm/BoundaryPointAlgorithm.d.ts +8 -0
  10. package/node_modules/@oozcitak/dom/lib/algorithm/BoundaryPointAlgorithm.js +76 -0
  11. package/node_modules/@oozcitak/dom/lib/algorithm/BoundaryPointAlgorithm.js.map +1 -0
  12. package/node_modules/@oozcitak/dom/lib/algorithm/CharacterDataAlgorithm.d.ts +19 -0
  13. package/node_modules/@oozcitak/dom/lib/algorithm/CharacterDataAlgorithm.js +140 -0
  14. package/node_modules/@oozcitak/dom/lib/algorithm/CharacterDataAlgorithm.js.map +1 -0
  15. package/node_modules/@oozcitak/dom/lib/algorithm/CreateAlgorithm.d.ts +192 -0
  16. package/node_modules/@oozcitak/dom/lib/algorithm/CreateAlgorithm.js +303 -0
  17. package/node_modules/@oozcitak/dom/lib/algorithm/CreateAlgorithm.js.map +1 -0
  18. package/node_modules/@oozcitak/dom/lib/algorithm/CustomElementAlgorithm.d.ts +61 -0
  19. package/node_modules/@oozcitak/dom/lib/algorithm/CustomElementAlgorithm.js +108 -0
  20. package/node_modules/@oozcitak/dom/lib/algorithm/CustomElementAlgorithm.js.map +1 -0
  21. package/node_modules/@oozcitak/dom/lib/algorithm/DOMAlgorithm.d.ts +72 -0
  22. package/node_modules/@oozcitak/dom/lib/algorithm/DOMAlgorithm.js +288 -0
  23. package/node_modules/@oozcitak/dom/lib/algorithm/DOMAlgorithm.js.map +1 -0
  24. package/node_modules/@oozcitak/dom/lib/algorithm/DOMTokenListAlgorithm.d.ts +21 -0
  25. package/node_modules/@oozcitak/dom/lib/algorithm/DOMTokenListAlgorithm.js +61 -0
  26. package/node_modules/@oozcitak/dom/lib/algorithm/DOMTokenListAlgorithm.js.map +1 -0
  27. package/node_modules/@oozcitak/dom/lib/algorithm/DocumentAlgorithm.d.ts +29 -0
  28. package/node_modules/@oozcitak/dom/lib/algorithm/DocumentAlgorithm.js +161 -0
  29. package/node_modules/@oozcitak/dom/lib/algorithm/DocumentAlgorithm.js.map +1 -0
  30. package/node_modules/@oozcitak/dom/lib/algorithm/ElementAlgorithm.d.ts +121 -0
  31. package/node_modules/@oozcitak/dom/lib/algorithm/ElementAlgorithm.js +608 -0
  32. package/node_modules/@oozcitak/dom/lib/algorithm/ElementAlgorithm.js.map +1 -0
  33. package/node_modules/@oozcitak/dom/lib/algorithm/EventAlgorithm.d.ts +146 -0
  34. package/node_modules/@oozcitak/dom/lib/algorithm/EventAlgorithm.js +995 -0
  35. package/node_modules/@oozcitak/dom/lib/algorithm/EventAlgorithm.js.map +1 -0
  36. package/node_modules/@oozcitak/dom/lib/algorithm/EventTargetAlgorithm.d.ts +33 -0
  37. package/node_modules/@oozcitak/dom/lib/algorithm/EventTargetAlgorithm.js +142 -0
  38. package/node_modules/@oozcitak/dom/lib/algorithm/EventTargetAlgorithm.js.map +1 -0
  39. package/node_modules/@oozcitak/dom/lib/algorithm/MutationAlgorithm.d.ts +66 -0
  40. package/node_modules/@oozcitak/dom/lib/algorithm/MutationAlgorithm.js +1173 -0
  41. package/node_modules/@oozcitak/dom/lib/algorithm/MutationAlgorithm.js.map +1 -0
  42. package/node_modules/@oozcitak/dom/lib/algorithm/MutationObserverAlgorithm.d.ts +43 -0
  43. package/node_modules/@oozcitak/dom/lib/algorithm/MutationObserverAlgorithm.js +276 -0
  44. package/node_modules/@oozcitak/dom/lib/algorithm/MutationObserverAlgorithm.js.map +1 -0
  45. package/node_modules/@oozcitak/dom/lib/algorithm/NamespaceAlgorithm.d.ts +25 -0
  46. package/node_modules/@oozcitak/dom/lib/algorithm/NamespaceAlgorithm.js +85 -0
  47. package/node_modules/@oozcitak/dom/lib/algorithm/NamespaceAlgorithm.js.map +1 -0
  48. package/node_modules/@oozcitak/dom/lib/algorithm/NodeAlgorithm.d.ts +68 -0
  49. package/node_modules/@oozcitak/dom/lib/algorithm/NodeAlgorithm.js +543 -0
  50. package/node_modules/@oozcitak/dom/lib/algorithm/NodeAlgorithm.js.map +1 -0
  51. package/node_modules/@oozcitak/dom/lib/algorithm/NodeIteratorAlgorithm.d.ts +15 -0
  52. package/node_modules/@oozcitak/dom/lib/algorithm/NodeIteratorAlgorithm.js +105 -0
  53. package/node_modules/@oozcitak/dom/lib/algorithm/NodeIteratorAlgorithm.js.map +1 -0
  54. package/node_modules/@oozcitak/dom/lib/algorithm/OrderedSetAlgorithm.d.ts +27 -0
  55. package/node_modules/@oozcitak/dom/lib/algorithm/OrderedSetAlgorithm.js +125 -0
  56. package/node_modules/@oozcitak/dom/lib/algorithm/OrderedSetAlgorithm.js.map +1 -0
  57. package/node_modules/@oozcitak/dom/lib/algorithm/ParentNodeAlgorithm.d.ts +9 -0
  58. package/node_modules/@oozcitak/dom/lib/algorithm/ParentNodeAlgorithm.js +69 -0
  59. package/node_modules/@oozcitak/dom/lib/algorithm/ParentNodeAlgorithm.js.map +1 -0
  60. package/node_modules/@oozcitak/dom/lib/algorithm/RangeAlgorithm.d.ts +82 -0
  61. package/node_modules/@oozcitak/dom/lib/algorithm/RangeAlgorithm.js +829 -0
  62. package/node_modules/@oozcitak/dom/lib/algorithm/RangeAlgorithm.js.map +1 -0
  63. package/node_modules/@oozcitak/dom/lib/algorithm/SelectorsAlgorithm.d.ts +8 -0
  64. package/node_modules/@oozcitak/dom/lib/algorithm/SelectorsAlgorithm.js +21 -0
  65. package/node_modules/@oozcitak/dom/lib/algorithm/SelectorsAlgorithm.js.map +1 -0
  66. package/node_modules/@oozcitak/dom/lib/algorithm/ShadowTreeAlgorithm.d.ts +57 -0
  67. package/node_modules/@oozcitak/dom/lib/algorithm/ShadowTreeAlgorithm.js +316 -0
  68. package/node_modules/@oozcitak/dom/lib/algorithm/ShadowTreeAlgorithm.js.map +1 -0
  69. package/node_modules/@oozcitak/dom/lib/algorithm/TextAlgorithm.d.ts +30 -0
  70. package/node_modules/@oozcitak/dom/lib/algorithm/TextAlgorithm.js +226 -0
  71. package/node_modules/@oozcitak/dom/lib/algorithm/TextAlgorithm.js.map +1 -0
  72. package/node_modules/@oozcitak/dom/lib/algorithm/TraversalAlgorithm.d.ts +8 -0
  73. package/node_modules/@oozcitak/dom/lib/algorithm/TraversalAlgorithm.js +62 -0
  74. package/node_modules/@oozcitak/dom/lib/algorithm/TraversalAlgorithm.js.map +1 -0
  75. package/node_modules/@oozcitak/dom/lib/algorithm/TreeAlgorithm.d.ts +268 -0
  76. package/node_modules/@oozcitak/dom/lib/algorithm/TreeAlgorithm.js +853 -0
  77. package/node_modules/@oozcitak/dom/lib/algorithm/TreeAlgorithm.js.map +1 -0
  78. package/node_modules/@oozcitak/dom/lib/algorithm/TreeWalkerAlgorithm.d.ts +17 -0
  79. package/node_modules/@oozcitak/dom/lib/algorithm/TreeWalkerAlgorithm.js +147 -0
  80. package/node_modules/@oozcitak/dom/lib/algorithm/TreeWalkerAlgorithm.js.map +1 -0
  81. package/node_modules/@oozcitak/dom/lib/algorithm/WebIDLAlgorithm.d.ts +8 -0
  82. package/node_modules/@oozcitak/dom/lib/algorithm/WebIDLAlgorithm.js +14 -0
  83. package/node_modules/@oozcitak/dom/lib/algorithm/WebIDLAlgorithm.js.map +1 -0
  84. package/node_modules/@oozcitak/dom/lib/algorithm/XMLAlgorithm.d.ts +25 -0
  85. package/node_modules/@oozcitak/dom/lib/algorithm/XMLAlgorithm.js +164 -0
  86. package/node_modules/@oozcitak/dom/lib/algorithm/XMLAlgorithm.js.map +1 -0
  87. package/node_modules/@oozcitak/dom/lib/algorithm/index.d.ts +28 -0
  88. package/node_modules/@oozcitak/dom/lib/algorithm/index.js +34 -0
  89. package/node_modules/@oozcitak/dom/lib/algorithm/index.js.map +1 -0
  90. package/node_modules/@oozcitak/dom/lib/dom/AbortControllerImpl.d.ts +15 -0
  91. package/node_modules/@oozcitak/dom/lib/dom/AbortControllerImpl.js +32 -0
  92. package/node_modules/@oozcitak/dom/lib/dom/AbortControllerImpl.js.map +1 -0
  93. package/node_modules/@oozcitak/dom/lib/dom/AbortSignalImpl.d.ts +23 -0
  94. package/node_modules/@oozcitak/dom/lib/dom/AbortSignalImpl.js +59 -0
  95. package/node_modules/@oozcitak/dom/lib/dom/AbortSignalImpl.js.map +1 -0
  96. package/node_modules/@oozcitak/dom/lib/dom/AbstractRangeImpl.d.ts +23 -0
  97. package/node_modules/@oozcitak/dom/lib/dom/AbstractRangeImpl.js +70 -0
  98. package/node_modules/@oozcitak/dom/lib/dom/AbstractRangeImpl.js.map +1 -0
  99. package/node_modules/@oozcitak/dom/lib/dom/AttrImpl.d.ts +45 -0
  100. package/node_modules/@oozcitak/dom/lib/dom/AttrImpl.js +118 -0
  101. package/node_modules/@oozcitak/dom/lib/dom/AttrImpl.js.map +1 -0
  102. package/node_modules/@oozcitak/dom/lib/dom/CDATASectionImpl.d.ts +21 -0
  103. package/node_modules/@oozcitak/dom/lib/dom/CDATASectionImpl.js +51 -0
  104. package/node_modules/@oozcitak/dom/lib/dom/CDATASectionImpl.js.map +1 -0
  105. package/node_modules/@oozcitak/dom/lib/dom/CharacterDataImpl.d.ts +35 -0
  106. package/node_modules/@oozcitak/dom/lib/dom/CharacterDataImpl.js +132 -0
  107. package/node_modules/@oozcitak/dom/lib/dom/CharacterDataImpl.js.map +1 -0
  108. package/node_modules/@oozcitak/dom/lib/dom/ChildNodeImpl.d.ts +16 -0
  109. package/node_modules/@oozcitak/dom/lib/dom/ChildNodeImpl.js +165 -0
  110. package/node_modules/@oozcitak/dom/lib/dom/ChildNodeImpl.js.map +1 -0
  111. package/node_modules/@oozcitak/dom/lib/dom/CommentImpl.d.ts +21 -0
  112. package/node_modules/@oozcitak/dom/lib/dom/CommentImpl.js +52 -0
  113. package/node_modules/@oozcitak/dom/lib/dom/CommentImpl.js.map +1 -0
  114. package/node_modules/@oozcitak/dom/lib/dom/CustomEventImpl.d.ts +16 -0
  115. package/node_modules/@oozcitak/dom/lib/dom/CustomEventImpl.js +60 -0
  116. package/node_modules/@oozcitak/dom/lib/dom/CustomEventImpl.js.map +1 -0
  117. package/node_modules/@oozcitak/dom/lib/dom/DOMException.d.ts +171 -0
  118. package/node_modules/@oozcitak/dom/lib/dom/DOMException.js +347 -0
  119. package/node_modules/@oozcitak/dom/lib/dom/DOMException.js.map +1 -0
  120. package/node_modules/@oozcitak/dom/lib/dom/DOMImpl.d.ts +48 -0
  121. package/node_modules/@oozcitak/dom/lib/dom/DOMImpl.js +100 -0
  122. package/node_modules/@oozcitak/dom/lib/dom/DOMImpl.js.map +1 -0
  123. package/node_modules/@oozcitak/dom/lib/dom/DOMImplementationImpl.d.ts +29 -0
  124. package/node_modules/@oozcitak/dom/lib/dom/DOMImplementationImpl.js +149 -0
  125. package/node_modules/@oozcitak/dom/lib/dom/DOMImplementationImpl.js.map +1 -0
  126. package/node_modules/@oozcitak/dom/lib/dom/DOMTokenListImpl.d.ts +46 -0
  127. package/node_modules/@oozcitak/dom/lib/dom/DOMTokenListImpl.js +312 -0
  128. package/node_modules/@oozcitak/dom/lib/dom/DOMTokenListImpl.js.map +1 -0
  129. package/node_modules/@oozcitak/dom/lib/dom/DocumentFragmentImpl.d.ts +32 -0
  130. package/node_modules/@oozcitak/dom/lib/dom/DocumentFragmentImpl.js +103 -0
  131. package/node_modules/@oozcitak/dom/lib/dom/DocumentFragmentImpl.js.map +1 -0
  132. package/node_modules/@oozcitak/dom/lib/dom/DocumentImpl.d.ts +116 -0
  133. package/node_modules/@oozcitak/dom/lib/dom/DocumentImpl.js +545 -0
  134. package/node_modules/@oozcitak/dom/lib/dom/DocumentImpl.js.map +1 -0
  135. package/node_modules/@oozcitak/dom/lib/dom/DocumentOrShadowRootImpl.d.ts +11 -0
  136. package/node_modules/@oozcitak/dom/lib/dom/DocumentOrShadowRootImpl.js +17 -0
  137. package/node_modules/@oozcitak/dom/lib/dom/DocumentOrShadowRootImpl.js.map +1 -0
  138. package/node_modules/@oozcitak/dom/lib/dom/DocumentTypeImpl.d.ts +39 -0
  139. package/node_modules/@oozcitak/dom/lib/dom/DocumentTypeImpl.js +109 -0
  140. package/node_modules/@oozcitak/dom/lib/dom/DocumentTypeImpl.js.map +1 -0
  141. package/node_modules/@oozcitak/dom/lib/dom/ElementImpl.d.ts +132 -0
  142. package/node_modules/@oozcitak/dom/lib/dom/ElementImpl.js +714 -0
  143. package/node_modules/@oozcitak/dom/lib/dom/ElementImpl.js.map +1 -0
  144. package/node_modules/@oozcitak/dom/lib/dom/EventImpl.d.ts +74 -0
  145. package/node_modules/@oozcitak/dom/lib/dom/EventImpl.js +313 -0
  146. package/node_modules/@oozcitak/dom/lib/dom/EventImpl.js.map +1 -0
  147. package/node_modules/@oozcitak/dom/lib/dom/EventTargetImpl.d.ts +30 -0
  148. package/node_modules/@oozcitak/dom/lib/dom/EventTargetImpl.js +133 -0
  149. package/node_modules/@oozcitak/dom/lib/dom/EventTargetImpl.js.map +1 -0
  150. package/node_modules/@oozcitak/dom/lib/dom/HTMLCollectionImpl.d.ts +44 -0
  151. package/node_modules/@oozcitak/dom/lib/dom/HTMLCollectionImpl.js +157 -0
  152. package/node_modules/@oozcitak/dom/lib/dom/HTMLCollectionImpl.js.map +1 -0
  153. package/node_modules/@oozcitak/dom/lib/dom/MutationObserverImpl.d.ts +22 -0
  154. package/node_modules/@oozcitak/dom/lib/dom/MutationObserverImpl.js +184 -0
  155. package/node_modules/@oozcitak/dom/lib/dom/MutationObserverImpl.js.map +1 -0
  156. package/node_modules/@oozcitak/dom/lib/dom/MutationRecordImpl.d.ts +73 -0
  157. package/node_modules/@oozcitak/dom/lib/dom/MutationRecordImpl.js +116 -0
  158. package/node_modules/@oozcitak/dom/lib/dom/MutationRecordImpl.js.map +1 -0
  159. package/node_modules/@oozcitak/dom/lib/dom/NamedNodeMapImpl.d.ts +34 -0
  160. package/node_modules/@oozcitak/dom/lib/dom/NamedNodeMapImpl.js +112 -0
  161. package/node_modules/@oozcitak/dom/lib/dom/NamedNodeMapImpl.js.map +1 -0
  162. package/node_modules/@oozcitak/dom/lib/dom/NodeFilterImpl.d.ts +50 -0
  163. package/node_modules/@oozcitak/dom/lib/dom/NodeFilterImpl.js +64 -0
  164. package/node_modules/@oozcitak/dom/lib/dom/NodeFilterImpl.js.map +1 -0
  165. package/node_modules/@oozcitak/dom/lib/dom/NodeImpl.d.ts +252 -0
  166. package/node_modules/@oozcitak/dom/lib/dom/NodeImpl.js +891 -0
  167. package/node_modules/@oozcitak/dom/lib/dom/NodeImpl.js.map +1 -0
  168. package/node_modules/@oozcitak/dom/lib/dom/NodeIteratorImpl.d.ts +34 -0
  169. package/node_modules/@oozcitak/dom/lib/dom/NodeIteratorImpl.js +86 -0
  170. package/node_modules/@oozcitak/dom/lib/dom/NodeIteratorImpl.js.map +1 -0
  171. package/node_modules/@oozcitak/dom/lib/dom/NodeListImpl.d.ts +46 -0
  172. package/node_modules/@oozcitak/dom/lib/dom/NodeListImpl.js +198 -0
  173. package/node_modules/@oozcitak/dom/lib/dom/NodeListImpl.js.map +1 -0
  174. package/node_modules/@oozcitak/dom/lib/dom/NodeListStaticImpl.d.ts +49 -0
  175. package/node_modules/@oozcitak/dom/lib/dom/NodeListStaticImpl.js +188 -0
  176. package/node_modules/@oozcitak/dom/lib/dom/NodeListStaticImpl.js.map +1 -0
  177. package/node_modules/@oozcitak/dom/lib/dom/NonDocumentTypeChildNodeImpl.d.ts +12 -0
  178. package/node_modules/@oozcitak/dom/lib/dom/NonDocumentTypeChildNodeImpl.js +53 -0
  179. package/node_modules/@oozcitak/dom/lib/dom/NonDocumentTypeChildNodeImpl.js.map +1 -0
  180. package/node_modules/@oozcitak/dom/lib/dom/NonElementParentNodeImpl.d.ts +9 -0
  181. package/node_modules/@oozcitak/dom/lib/dom/NonElementParentNodeImpl.js +31 -0
  182. package/node_modules/@oozcitak/dom/lib/dom/NonElementParentNodeImpl.js.map +1 -0
  183. package/node_modules/@oozcitak/dom/lib/dom/ParentNodeImpl.d.ts +24 -0
  184. package/node_modules/@oozcitak/dom/lib/dom/ParentNodeImpl.js +158 -0
  185. package/node_modules/@oozcitak/dom/lib/dom/ParentNodeImpl.js.map +1 -0
  186. package/node_modules/@oozcitak/dom/lib/dom/ProcessingInstructionImpl.d.ts +25 -0
  187. package/node_modules/@oozcitak/dom/lib/dom/ProcessingInstructionImpl.js +59 -0
  188. package/node_modules/@oozcitak/dom/lib/dom/ProcessingInstructionImpl.js.map +1 -0
  189. package/node_modules/@oozcitak/dom/lib/dom/RangeImpl.d.ts +71 -0
  190. package/node_modules/@oozcitak/dom/lib/dom/RangeImpl.js +649 -0
  191. package/node_modules/@oozcitak/dom/lib/dom/RangeImpl.js.map +1 -0
  192. package/node_modules/@oozcitak/dom/lib/dom/ShadowRootImpl.d.ts +33 -0
  193. package/node_modules/@oozcitak/dom/lib/dom/ShadowRootImpl.js +82 -0
  194. package/node_modules/@oozcitak/dom/lib/dom/ShadowRootImpl.js.map +1 -0
  195. package/node_modules/@oozcitak/dom/lib/dom/SlotableImpl.d.ts +16 -0
  196. package/node_modules/@oozcitak/dom/lib/dom/SlotableImpl.js +35 -0
  197. package/node_modules/@oozcitak/dom/lib/dom/SlotableImpl.js.map +1 -0
  198. package/node_modules/@oozcitak/dom/lib/dom/StaticRangeImpl.d.ts +13 -0
  199. package/node_modules/@oozcitak/dom/lib/dom/StaticRangeImpl.js +48 -0
  200. package/node_modules/@oozcitak/dom/lib/dom/StaticRangeImpl.js.map +1 -0
  201. package/node_modules/@oozcitak/dom/lib/dom/TextImpl.d.ts +28 -0
  202. package/node_modules/@oozcitak/dom/lib/dom/TextImpl.js +109 -0
  203. package/node_modules/@oozcitak/dom/lib/dom/TextImpl.js.map +1 -0
  204. package/node_modules/@oozcitak/dom/lib/dom/TraverserImpl.d.ts +23 -0
  205. package/node_modules/@oozcitak/dom/lib/dom/TraverserImpl.js +41 -0
  206. package/node_modules/@oozcitak/dom/lib/dom/TraverserImpl.js.map +1 -0
  207. package/node_modules/@oozcitak/dom/lib/dom/TreeWalkerImpl.d.ts +36 -0
  208. package/node_modules/@oozcitak/dom/lib/dom/TreeWalkerImpl.js +249 -0
  209. package/node_modules/@oozcitak/dom/lib/dom/TreeWalkerImpl.js.map +1 -0
  210. package/node_modules/@oozcitak/dom/lib/dom/WindowImpl.d.ts +26 -0
  211. package/node_modules/@oozcitak/dom/lib/dom/WindowImpl.js +57 -0
  212. package/node_modules/@oozcitak/dom/lib/dom/WindowImpl.js.map +1 -0
  213. package/node_modules/@oozcitak/dom/lib/dom/XMLDocumentImpl.d.ts +11 -0
  214. package/node_modules/@oozcitak/dom/lib/dom/XMLDocumentImpl.js +31 -0
  215. package/node_modules/@oozcitak/dom/lib/dom/XMLDocumentImpl.js.map +1 -0
  216. package/node_modules/@oozcitak/dom/lib/dom/index.d.ts +36 -0
  217. package/node_modules/@oozcitak/dom/lib/dom/index.js +102 -0
  218. package/node_modules/@oozcitak/dom/lib/dom/index.js.map +1 -0
  219. package/node_modules/@oozcitak/dom/lib/dom/interfaces.d.ts +2218 -0
  220. package/node_modules/@oozcitak/dom/lib/dom/interfaces.js +91 -0
  221. package/node_modules/@oozcitak/dom/lib/dom/interfaces.js.map +1 -0
  222. package/node_modules/@oozcitak/dom/lib/index.d.ts +3 -0
  223. package/node_modules/@oozcitak/dom/lib/index.js +11 -0
  224. package/node_modules/@oozcitak/dom/lib/index.js.map +1 -0
  225. package/node_modules/@oozcitak/dom/lib/parser/DOMParserImpl.d.ts +11 -0
  226. package/node_modules/@oozcitak/dom/lib/parser/DOMParserImpl.js +37 -0
  227. package/node_modules/@oozcitak/dom/lib/parser/DOMParserImpl.js.map +1 -0
  228. package/node_modules/@oozcitak/dom/lib/parser/XMLParserImpl.d.ts +26 -0
  229. package/node_modules/@oozcitak/dom/lib/parser/XMLParserImpl.js +240 -0
  230. package/node_modules/@oozcitak/dom/lib/parser/XMLParserImpl.js.map +1 -0
  231. package/node_modules/@oozcitak/dom/lib/parser/XMLStringLexer.d.ts +159 -0
  232. package/node_modules/@oozcitak/dom/lib/parser/XMLStringLexer.js +512 -0
  233. package/node_modules/@oozcitak/dom/lib/parser/XMLStringLexer.js.map +1 -0
  234. package/node_modules/@oozcitak/dom/lib/parser/index.d.ts +1 -0
  235. package/node_modules/@oozcitak/dom/lib/parser/index.js +6 -0
  236. package/node_modules/@oozcitak/dom/lib/parser/index.js.map +1 -0
  237. package/node_modules/@oozcitak/dom/lib/parser/interfaces.d.ts +131 -0
  238. package/node_modules/@oozcitak/dom/lib/parser/interfaces.js +18 -0
  239. package/node_modules/@oozcitak/dom/lib/parser/interfaces.js.map +1 -0
  240. package/node_modules/@oozcitak/dom/lib/serializer/LocalNameSet.d.ts +27 -0
  241. package/node_modules/@oozcitak/dom/lib/serializer/LocalNameSet.js +56 -0
  242. package/node_modules/@oozcitak/dom/lib/serializer/LocalNameSet.js.map +1 -0
  243. package/node_modules/@oozcitak/dom/lib/serializer/NamespacePrefixMap.d.ts +52 -0
  244. package/node_modules/@oozcitak/dom/lib/serializer/NamespacePrefixMap.js +151 -0
  245. package/node_modules/@oozcitak/dom/lib/serializer/NamespacePrefixMap.js.map +1 -0
  246. package/node_modules/@oozcitak/dom/lib/serializer/XMLSerializerImpl.d.ts +166 -0
  247. package/node_modules/@oozcitak/dom/lib/serializer/XMLSerializerImpl.js +1479 -0
  248. package/node_modules/@oozcitak/dom/lib/serializer/XMLSerializerImpl.js.map +1 -0
  249. package/node_modules/@oozcitak/dom/lib/serializer/index.d.ts +1 -0
  250. package/node_modules/@oozcitak/dom/lib/serializer/index.js +6 -0
  251. package/node_modules/@oozcitak/dom/lib/serializer/index.js.map +1 -0
  252. package/node_modules/@oozcitak/dom/lib/serializer/interfaces.d.ts +15 -0
  253. package/node_modules/@oozcitak/dom/lib/serializer/interfaces.js +3 -0
  254. package/node_modules/@oozcitak/dom/lib/serializer/interfaces.js.map +1 -0
  255. package/node_modules/@oozcitak/dom/lib/util/Cast.d.ts +12 -0
  256. package/node_modules/@oozcitak/dom/lib/util/Cast.js +26 -0
  257. package/node_modules/@oozcitak/dom/lib/util/Cast.js.map +1 -0
  258. package/node_modules/@oozcitak/dom/lib/util/EmptySet.d.ts +13 -0
  259. package/node_modules/@oozcitak/dom/lib/util/EmptySet.js +61 -0
  260. package/node_modules/@oozcitak/dom/lib/util/EmptySet.js.map +1 -0
  261. package/node_modules/@oozcitak/dom/lib/util/Guard.d.ts +135 -0
  262. package/node_modules/@oozcitak/dom/lib/util/Guard.js +192 -0
  263. package/node_modules/@oozcitak/dom/lib/util/Guard.js.map +1 -0
  264. package/node_modules/@oozcitak/dom/lib/util/index.d.ts +3 -0
  265. package/node_modules/@oozcitak/dom/lib/util/index.js +9 -0
  266. package/node_modules/@oozcitak/dom/lib/util/index.js.map +1 -0
  267. package/node_modules/@oozcitak/dom/package.json +72 -0
  268. package/node_modules/@oozcitak/infra/LICENSE +21 -0
  269. package/node_modules/@oozcitak/infra/README.md +13 -0
  270. package/node_modules/@oozcitak/infra/lib/Base64.d.ts +12 -0
  271. package/node_modules/@oozcitak/infra/lib/Base64.js +82 -0
  272. package/node_modules/@oozcitak/infra/lib/Base64.js.map +1 -0
  273. package/node_modules/@oozcitak/infra/lib/Byte.d.ts +6 -0
  274. package/node_modules/@oozcitak/infra/lib/Byte.js +15 -0
  275. package/node_modules/@oozcitak/infra/lib/Byte.js.map +1 -0
  276. package/node_modules/@oozcitak/infra/lib/ByteSequence.d.ts +45 -0
  277. package/node_modules/@oozcitak/infra/lib/ByteSequence.js +171 -0
  278. package/node_modules/@oozcitak/infra/lib/ByteSequence.js.map +1 -0
  279. package/node_modules/@oozcitak/infra/lib/CodePoints.d.ts +82 -0
  280. package/node_modules/@oozcitak/infra/lib/CodePoints.js +85 -0
  281. package/node_modules/@oozcitak/infra/lib/CodePoints.js.map +1 -0
  282. package/node_modules/@oozcitak/infra/lib/JSON.d.ts +24 -0
  283. package/node_modules/@oozcitak/infra/lib/JSON.js +123 -0
  284. package/node_modules/@oozcitak/infra/lib/JSON.js.map +1 -0
  285. package/node_modules/@oozcitak/infra/lib/List.d.ts +101 -0
  286. package/node_modules/@oozcitak/infra/lib/List.js +325 -0
  287. package/node_modules/@oozcitak/infra/lib/List.js.map +1 -0
  288. package/node_modules/@oozcitak/infra/lib/Map.d.ts +87 -0
  289. package/node_modules/@oozcitak/infra/lib/Map.js +308 -0
  290. package/node_modules/@oozcitak/infra/lib/Map.js.map +1 -0
  291. package/node_modules/@oozcitak/infra/lib/Namespace.d.ts +6 -0
  292. package/node_modules/@oozcitak/infra/lib/Namespace.js +9 -0
  293. package/node_modules/@oozcitak/infra/lib/Namespace.js.map +1 -0
  294. package/node_modules/@oozcitak/infra/lib/Queue.d.ts +13 -0
  295. package/node_modules/@oozcitak/infra/lib/Queue.js +22 -0
  296. package/node_modules/@oozcitak/infra/lib/Queue.js.map +1 -0
  297. package/node_modules/@oozcitak/infra/lib/Set.d.ts +136 -0
  298. package/node_modules/@oozcitak/infra/lib/Set.js +467 -0
  299. package/node_modules/@oozcitak/infra/lib/Set.js.map +1 -0
  300. package/node_modules/@oozcitak/infra/lib/Stack.d.ts +13 -0
  301. package/node_modules/@oozcitak/infra/lib/Stack.js +22 -0
  302. package/node_modules/@oozcitak/infra/lib/Stack.js.map +1 -0
  303. package/node_modules/@oozcitak/infra/lib/String.d.ts +129 -0
  304. package/node_modules/@oozcitak/infra/lib/String.js +472 -0
  305. package/node_modules/@oozcitak/infra/lib/String.js.map +1 -0
  306. package/node_modules/@oozcitak/infra/lib/index.d.ts +13 -0
  307. package/node_modules/@oozcitak/infra/lib/index.js +34 -0
  308. package/node_modules/@oozcitak/infra/lib/index.js.map +1 -0
  309. package/node_modules/@oozcitak/infra/package.json +54 -0
  310. package/node_modules/@oozcitak/url/LICENSE +21 -0
  311. package/node_modules/@oozcitak/url/README.md +27 -0
  312. package/node_modules/@oozcitak/url/lib/URLAlgorithm.d.ts +267 -0
  313. package/node_modules/@oozcitak/url/lib/URLAlgorithm.js +2758 -0
  314. package/node_modules/@oozcitak/url/lib/URLAlgorithm.js.map +1 -0
  315. package/node_modules/@oozcitak/url/lib/URLImpl.d.ts +53 -0
  316. package/node_modules/@oozcitak/url/lib/URLImpl.js +377 -0
  317. package/node_modules/@oozcitak/url/lib/URLImpl.js.map +1 -0
  318. package/node_modules/@oozcitak/url/lib/URLSearchParamsImpl.d.ts +38 -0
  319. package/node_modules/@oozcitak/url/lib/URLSearchParamsImpl.js +303 -0
  320. package/node_modules/@oozcitak/url/lib/URLSearchParamsImpl.js.map +1 -0
  321. package/node_modules/@oozcitak/url/lib/index.d.ts +2 -0
  322. package/node_modules/@oozcitak/url/lib/index.js +7 -0
  323. package/node_modules/@oozcitak/url/lib/index.js.map +1 -0
  324. package/node_modules/@oozcitak/url/lib/interfaces.d.ts +195 -0
  325. package/node_modules/@oozcitak/url/lib/interfaces.js +31 -0
  326. package/node_modules/@oozcitak/url/lib/interfaces.js.map +1 -0
  327. package/node_modules/@oozcitak/url/package.json +55 -0
  328. package/node_modules/@oozcitak/util/LICENSE +21 -0
  329. package/node_modules/@oozcitak/util/README.md +10 -0
  330. package/node_modules/@oozcitak/util/lib/CompareCache.d.ts +32 -0
  331. package/node_modules/@oozcitak/util/lib/CompareCache.js +59 -0
  332. package/node_modules/@oozcitak/util/lib/CompareCache.js.map +1 -0
  333. package/node_modules/@oozcitak/util/lib/FixedSizeSet.d.ts +64 -0
  334. package/node_modules/@oozcitak/util/lib/FixedSizeSet.js +174 -0
  335. package/node_modules/@oozcitak/util/lib/FixedSizeSet.js.map +1 -0
  336. package/node_modules/@oozcitak/util/lib/Lazy.d.ts +18 -0
  337. package/node_modules/@oozcitak/util/lib/Lazy.js +34 -0
  338. package/node_modules/@oozcitak/util/lib/Lazy.js.map +1 -0
  339. package/node_modules/@oozcitak/util/lib/ObjectCache.d.ts +71 -0
  340. package/node_modules/@oozcitak/util/lib/ObjectCache.js +181 -0
  341. package/node_modules/@oozcitak/util/lib/ObjectCache.js.map +1 -0
  342. package/node_modules/@oozcitak/util/lib/StringWalker.d.ts +49 -0
  343. package/node_modules/@oozcitak/util/lib/StringWalker.js +105 -0
  344. package/node_modules/@oozcitak/util/lib/StringWalker.js.map +1 -0
  345. package/node_modules/@oozcitak/util/lib/index.d.ts +178 -0
  346. package/node_modules/@oozcitak/util/lib/index.js +439 -0
  347. package/node_modules/@oozcitak/util/lib/index.js.map +1 -0
  348. package/node_modules/@oozcitak/util/package.json +50 -0
  349. package/node_modules/@xmldom/is-dom-node/LICENSE.md +21 -0
  350. package/node_modules/@xmldom/is-dom-node/README.md +91 -0
  351. package/node_modules/@xmldom/is-dom-node/dist/index.d.ts +33 -0
  352. package/node_modules/@xmldom/is-dom-node/dist/index.js +91 -0
  353. package/node_modules/@xmldom/is-dom-node/dist/index.js.map +1 -0
  354. package/node_modules/@xmldom/is-dom-node/package.json +69 -0
  355. package/node_modules/@xmldom/xmldom/CHANGELOG.md +468 -0
  356. package/node_modules/@xmldom/xmldom/LICENSE +8 -0
  357. package/node_modules/@xmldom/xmldom/SECURITY.md +50 -0
  358. package/node_modules/@xmldom/xmldom/index.d.ts +43 -0
  359. package/node_modules/@xmldom/xmldom/lib/.eslintrc.yml +2 -0
  360. package/node_modules/@xmldom/xmldom/lib/conventions.js +203 -0
  361. package/node_modules/@xmldom/xmldom/lib/dom-parser.js +322 -0
  362. package/node_modules/@xmldom/xmldom/lib/dom.js +1879 -0
  363. package/node_modules/@xmldom/xmldom/lib/entities.js +2166 -0
  364. package/node_modules/@xmldom/xmldom/lib/index.js +4 -0
  365. package/node_modules/@xmldom/xmldom/lib/sax.js +662 -0
  366. package/node_modules/@xmldom/xmldom/package.json +71 -0
  367. package/node_modules/@xmldom/xmldom/readme.md +356 -0
  368. package/node_modules/esprima/ChangeLog +235 -0
  369. package/node_modules/esprima/LICENSE.BSD +21 -0
  370. package/node_modules/esprima/README.md +46 -0
  371. package/node_modules/esprima/bin/esparse.js +139 -0
  372. package/node_modules/esprima/bin/esvalidate.js +236 -0
  373. package/node_modules/esprima/dist/esprima.js +6709 -0
  374. package/node_modules/esprima/package.json +112 -0
  375. package/node_modules/node-forge/LICENSE +331 -0
  376. package/node_modules/node-forge/README.md +2071 -0
  377. package/node_modules/node-forge/dist/forge.all.min.js +2 -0
  378. package/node_modules/node-forge/dist/forge.all.min.js.map +1 -0
  379. package/node_modules/node-forge/dist/forge.min.js +2 -0
  380. package/node_modules/node-forge/dist/forge.min.js.map +1 -0
  381. package/node_modules/node-forge/dist/prime.worker.min.js +2 -0
  382. package/node_modules/node-forge/dist/prime.worker.min.js.map +1 -0
  383. package/node_modules/node-forge/flash/swf/SocketPool.swf +0 -0
  384. package/node_modules/node-forge/lib/aes.js +1091 -0
  385. package/node_modules/node-forge/lib/aesCipherSuites.js +282 -0
  386. package/node_modules/node-forge/lib/asn1-validator.js +91 -0
  387. package/node_modules/node-forge/lib/asn1.js +1503 -0
  388. package/node_modules/node-forge/lib/baseN.js +186 -0
  389. package/node_modules/node-forge/lib/cipher.js +230 -0
  390. package/node_modules/node-forge/lib/cipherModes.js +999 -0
  391. package/node_modules/node-forge/lib/des.js +496 -0
  392. package/node_modules/node-forge/lib/ed25519.js +1072 -0
  393. package/node_modules/node-forge/lib/forge.js +13 -0
  394. package/node_modules/node-forge/lib/form.js +149 -0
  395. package/node_modules/node-forge/lib/hmac.js +146 -0
  396. package/node_modules/node-forge/lib/http.js +1346 -0
  397. package/node_modules/node-forge/lib/index.all.js +16 -0
  398. package/node_modules/node-forge/lib/index.js +33 -0
  399. package/node_modules/node-forge/lib/jsbn.js +1264 -0
  400. package/node_modules/node-forge/lib/kem.js +168 -0
  401. package/node_modules/node-forge/lib/log.js +319 -0
  402. package/node_modules/node-forge/lib/md.all.js +13 -0
  403. package/node_modules/node-forge/lib/md.js +11 -0
  404. package/node_modules/node-forge/lib/md5.js +289 -0
  405. package/node_modules/node-forge/lib/mgf.js +12 -0
  406. package/node_modules/node-forge/lib/mgf1.js +57 -0
  407. package/node_modules/node-forge/lib/oids.js +179 -0
  408. package/node_modules/node-forge/lib/pbe.js +1023 -0
  409. package/node_modules/node-forge/lib/pbkdf2.js +211 -0
  410. package/node_modules/node-forge/lib/pem.js +237 -0
  411. package/node_modules/node-forge/lib/pkcs1.js +276 -0
  412. package/node_modules/node-forge/lib/pkcs12.js +1078 -0
  413. package/node_modules/node-forge/lib/pkcs7.js +1260 -0
  414. package/node_modules/node-forge/lib/pkcs7asn1.js +410 -0
  415. package/node_modules/node-forge/lib/pki.js +102 -0
  416. package/node_modules/node-forge/lib/prime.js +297 -0
  417. package/node_modules/node-forge/lib/prime.worker.js +168 -0
  418. package/node_modules/node-forge/lib/prng.js +419 -0
  419. package/node_modules/node-forge/lib/pss.js +241 -0
  420. package/node_modules/node-forge/lib/random.js +191 -0
  421. package/node_modules/node-forge/lib/rc2.js +410 -0
  422. package/node_modules/node-forge/lib/rsa.js +1949 -0
  423. package/node_modules/node-forge/lib/sha1.js +319 -0
  424. package/node_modules/node-forge/lib/sha256.js +327 -0
  425. package/node_modules/node-forge/lib/sha512.js +561 -0
  426. package/node_modules/node-forge/lib/socket.js +287 -0
  427. package/node_modules/node-forge/lib/ssh.js +236 -0
  428. package/node_modules/node-forge/lib/tls.js +4282 -0
  429. package/node_modules/node-forge/lib/tlssocket.js +249 -0
  430. package/node_modules/node-forge/lib/util.js +2652 -0
  431. package/node_modules/node-forge/lib/x509.js +3242 -0
  432. package/node_modules/node-forge/lib/xhr.js +738 -0
  433. package/node_modules/node-forge/package.json +123 -0
  434. package/node_modules/sprintf-js/.npmignore +1 -0
  435. package/node_modules/sprintf-js/LICENSE +24 -0
  436. package/node_modules/sprintf-js/README.md +88 -0
  437. package/node_modules/sprintf-js/bower.json +14 -0
  438. package/node_modules/sprintf-js/demo/angular.html +20 -0
  439. package/node_modules/sprintf-js/dist/angular-sprintf.min.js +4 -0
  440. package/node_modules/sprintf-js/dist/angular-sprintf.min.js.map +1 -0
  441. package/node_modules/sprintf-js/dist/angular-sprintf.min.map +1 -0
  442. package/node_modules/sprintf-js/dist/sprintf.min.js +4 -0
  443. package/node_modules/sprintf-js/dist/sprintf.min.js.map +1 -0
  444. package/node_modules/sprintf-js/dist/sprintf.min.map +1 -0
  445. package/node_modules/sprintf-js/gruntfile.js +36 -0
  446. package/node_modules/sprintf-js/package.json +22 -0
  447. package/node_modules/sprintf-js/src/angular-sprintf.js +18 -0
  448. package/node_modules/sprintf-js/src/sprintf.js +208 -0
  449. package/node_modules/sprintf-js/test/test.js +82 -0
  450. package/node_modules/xml-crypto/LICENSE +22 -0
  451. package/node_modules/xml-crypto/README.md +557 -0
  452. package/node_modules/xml-crypto/lib/c14n-canonicalization.d.ts +39 -0
  453. package/node_modules/xml-crypto/lib/c14n-canonicalization.js +230 -0
  454. package/node_modules/xml-crypto/lib/c14n-canonicalization.js.map +1 -0
  455. package/node_modules/xml-crypto/lib/enveloped-signature.d.ts +7 -0
  456. package/node_modules/xml-crypto/lib/enveloped-signature.js +43 -0
  457. package/node_modules/xml-crypto/lib/enveloped-signature.js.map +1 -0
  458. package/node_modules/xml-crypto/lib/exclusive-canonicalization.d.ts +38 -0
  459. package/node_modules/xml-crypto/lib/exclusive-canonicalization.js +246 -0
  460. package/node_modules/xml-crypto/lib/exclusive-canonicalization.js.map +1 -0
  461. package/node_modules/xml-crypto/lib/hash-algorithms.d.ts +13 -0
  462. package/node_modules/xml-crypto/lib/hash-algorithms.js +47 -0
  463. package/node_modules/xml-crypto/lib/hash-algorithms.js.map +1 -0
  464. package/node_modules/xml-crypto/lib/index.d.ts +5 -0
  465. package/node_modules/xml-crypto/lib/index.js +28 -0
  466. package/node_modules/xml-crypto/lib/index.js.map +1 -0
  467. package/node_modules/xml-crypto/lib/signature-algorithms.d.ts +47 -0
  468. package/node_modules/xml-crypto/lib/signature-algorithms.js +86 -0
  469. package/node_modules/xml-crypto/lib/signature-algorithms.js.map +1 -0
  470. package/node_modules/xml-crypto/lib/signed-xml.d.ts +225 -0
  471. package/node_modules/xml-crypto/lib/signed-xml.js +960 -0
  472. package/node_modules/xml-crypto/lib/signed-xml.js.map +1 -0
  473. package/node_modules/xml-crypto/lib/types.d.ts +125 -0
  474. package/node_modules/xml-crypto/lib/types.js +57 -0
  475. package/node_modules/xml-crypto/lib/types.js.map +1 -0
  476. package/node_modules/xml-crypto/lib/utils.d.ts +65 -0
  477. package/node_modules/xml-crypto/lib/utils.js +256 -0
  478. package/node_modules/xml-crypto/lib/utils.js.map +1 -0
  479. package/node_modules/xml-crypto/node_modules/xpath/LICENSE +22 -0
  480. package/node_modules/xml-crypto/node_modules/xpath/README.md +133 -0
  481. package/node_modules/xml-crypto/node_modules/xpath/docs/XPathEvaluator.md +62 -0
  482. package/node_modules/xml-crypto/node_modules/xpath/docs/XPathResult.md +47 -0
  483. package/node_modules/xml-crypto/node_modules/xpath/docs/function resolvers.md +88 -0
  484. package/node_modules/xml-crypto/node_modules/xpath/docs/namespace resolvers.md +69 -0
  485. package/node_modules/xml-crypto/node_modules/xpath/docs/parsed expressions.md +21 -0
  486. package/node_modules/xml-crypto/node_modules/xpath/docs/variable resolvers.md +89 -0
  487. package/node_modules/xml-crypto/node_modules/xpath/docs/xpath methods.md +39 -0
  488. package/node_modules/xml-crypto/node_modules/xpath/package.json +39 -0
  489. package/node_modules/xml-crypto/node_modules/xpath/test.js +1186 -0
  490. package/node_modules/xml-crypto/node_modules/xpath/xpath.d.ts +51 -0
  491. package/node_modules/xml-crypto/node_modules/xpath/xpath.js +4938 -0
  492. package/node_modules/xml-crypto/package.json +73 -0
  493. package/node_modules/xmlbuilder2/CHANGELOG.md +309 -0
  494. package/node_modules/xmlbuilder2/LICENSE +21 -0
  495. package/node_modules/xmlbuilder2/README.md +183 -0
  496. package/node_modules/xmlbuilder2/lib/builder/BuilderFunctions.d.ts +236 -0
  497. package/node_modules/xmlbuilder2/lib/builder/BuilderFunctions.js +108 -0
  498. package/node_modules/xmlbuilder2/lib/builder/BuilderFunctions.js.map +1 -0
  499. package/node_modules/xmlbuilder2/lib/builder/BuilderFunctionsCB.d.ts +17 -0
  500. package/node_modules/xmlbuilder2/lib/builder/BuilderFunctionsCB.js +26 -0
  501. package/node_modules/xmlbuilder2/lib/builder/BuilderFunctionsCB.js.map +1 -0
  502. package/node_modules/xmlbuilder2/lib/builder/XMLBuilderCBImpl.d.ts +124 -0
  503. package/node_modules/xmlbuilder2/lib/builder/XMLBuilderCBImpl.js +782 -0
  504. package/node_modules/xmlbuilder2/lib/builder/XMLBuilderCBImpl.js.map +1 -0
  505. package/node_modules/xmlbuilder2/lib/builder/XMLBuilderImpl.d.ts +143 -0
  506. package/node_modules/xmlbuilder2/lib/builder/XMLBuilderImpl.js +841 -0
  507. package/node_modules/xmlbuilder2/lib/builder/XMLBuilderImpl.js.map +1 -0
  508. package/node_modules/xmlbuilder2/lib/builder/dom.d.ts +8 -0
  509. package/node_modules/xmlbuilder2/lib/builder/dom.js +67 -0
  510. package/node_modules/xmlbuilder2/lib/builder/dom.js.map +1 -0
  511. package/node_modules/xmlbuilder2/lib/builder/index.d.ts +4 -0
  512. package/node_modules/xmlbuilder2/lib/builder/index.js +15 -0
  513. package/node_modules/xmlbuilder2/lib/builder/index.js.map +1 -0
  514. package/node_modules/xmlbuilder2/lib/constants.d.ts +1 -0
  515. package/node_modules/xmlbuilder2/lib/constants.js +4 -0
  516. package/node_modules/xmlbuilder2/lib/constants.js.map +1 -0
  517. package/node_modules/xmlbuilder2/lib/index.d.ts +1 -0
  518. package/node_modules/xmlbuilder2/lib/index.js +10 -0
  519. package/node_modules/xmlbuilder2/lib/index.js.map +1 -0
  520. package/node_modules/xmlbuilder2/lib/interfaces.d.ts +1355 -0
  521. package/node_modules/xmlbuilder2/lib/interfaces.js +76 -0
  522. package/node_modules/xmlbuilder2/lib/interfaces.js.map +1 -0
  523. package/node_modules/xmlbuilder2/lib/readers/BaseReader.d.ts +109 -0
  524. package/node_modules/xmlbuilder2/lib/readers/BaseReader.js +167 -0
  525. package/node_modules/xmlbuilder2/lib/readers/BaseReader.js.map +1 -0
  526. package/node_modules/xmlbuilder2/lib/readers/JSONReader.d.ts +14 -0
  527. package/node_modules/xmlbuilder2/lib/readers/JSONReader.js +38 -0
  528. package/node_modules/xmlbuilder2/lib/readers/JSONReader.js.map +1 -0
  529. package/node_modules/xmlbuilder2/lib/readers/ObjectReader.d.ts +15 -0
  530. package/node_modules/xmlbuilder2/lib/readers/ObjectReader.js +168 -0
  531. package/node_modules/xmlbuilder2/lib/readers/ObjectReader.js.map +1 -0
  532. package/node_modules/xmlbuilder2/lib/readers/XMLReader.d.ts +14 -0
  533. package/node_modules/xmlbuilder2/lib/readers/XMLReader.js +206 -0
  534. package/node_modules/xmlbuilder2/lib/readers/XMLReader.js.map +1 -0
  535. package/node_modules/xmlbuilder2/lib/readers/YAMLReader.d.ts +14 -0
  536. package/node_modules/xmlbuilder2/lib/readers/YAMLReader.js +44 -0
  537. package/node_modules/xmlbuilder2/lib/readers/YAMLReader.js.map +1 -0
  538. package/node_modules/xmlbuilder2/lib/readers/index.d.ts +4 -0
  539. package/node_modules/xmlbuilder2/lib/readers/index.js +11 -0
  540. package/node_modules/xmlbuilder2/lib/readers/index.js.map +1 -0
  541. package/node_modules/xmlbuilder2/lib/writers/BaseCBWriter.d.ts +110 -0
  542. package/node_modules/xmlbuilder2/lib/writers/BaseCBWriter.js +23 -0
  543. package/node_modules/xmlbuilder2/lib/writers/BaseCBWriter.js.map +1 -0
  544. package/node_modules/xmlbuilder2/lib/writers/BaseWriter.d.ts +276 -0
  545. package/node_modules/xmlbuilder2/lib/writers/BaseWriter.js +1603 -0
  546. package/node_modules/xmlbuilder2/lib/writers/BaseWriter.js.map +1 -0
  547. package/node_modules/xmlbuilder2/lib/writers/JSONCBWriter.d.ts +68 -0
  548. package/node_modules/xmlbuilder2/lib/writers/JSONCBWriter.js +172 -0
  549. package/node_modules/xmlbuilder2/lib/writers/JSONCBWriter.js.map +1 -0
  550. package/node_modules/xmlbuilder2/lib/writers/JSONWriter.d.ts +67 -0
  551. package/node_modules/xmlbuilder2/lib/writers/JSONWriter.js +222 -0
  552. package/node_modules/xmlbuilder2/lib/writers/JSONWriter.js.map +1 -0
  553. package/node_modules/xmlbuilder2/lib/writers/MapWriter.d.ts +27 -0
  554. package/node_modules/xmlbuilder2/lib/writers/MapWriter.js +84 -0
  555. package/node_modules/xmlbuilder2/lib/writers/MapWriter.js.map +1 -0
  556. package/node_modules/xmlbuilder2/lib/writers/ObjectWriter.d.ts +56 -0
  557. package/node_modules/xmlbuilder2/lib/writers/ObjectWriter.js +483 -0
  558. package/node_modules/xmlbuilder2/lib/writers/ObjectWriter.js.map +1 -0
  559. package/node_modules/xmlbuilder2/lib/writers/XMLCBWriter.d.ts +51 -0
  560. package/node_modules/xmlbuilder2/lib/writers/XMLCBWriter.js +165 -0
  561. package/node_modules/xmlbuilder2/lib/writers/XMLCBWriter.js.map +1 -0
  562. package/node_modules/xmlbuilder2/lib/writers/XMLWriter.d.ts +60 -0
  563. package/node_modules/xmlbuilder2/lib/writers/XMLWriter.js +236 -0
  564. package/node_modules/xmlbuilder2/lib/writers/XMLWriter.js.map +1 -0
  565. package/node_modules/xmlbuilder2/lib/writers/YAMLCBWriter.d.ts +61 -0
  566. package/node_modules/xmlbuilder2/lib/writers/YAMLCBWriter.js +161 -0
  567. package/node_modules/xmlbuilder2/lib/writers/YAMLCBWriter.js.map +1 -0
  568. package/node_modules/xmlbuilder2/lib/writers/YAMLWriter.d.ts +55 -0
  569. package/node_modules/xmlbuilder2/lib/writers/YAMLWriter.js +186 -0
  570. package/node_modules/xmlbuilder2/lib/writers/YAMLWriter.js.map +1 -0
  571. package/node_modules/xmlbuilder2/lib/writers/index.d.ts +5 -0
  572. package/node_modules/xmlbuilder2/lib/writers/index.js +13 -0
  573. package/node_modules/xmlbuilder2/lib/writers/index.js.map +1 -0
  574. package/node_modules/xmlbuilder2/lib/xmlbuilder2.min.js +8 -0
  575. package/node_modules/xmlbuilder2/node_modules/argparse/CHANGELOG.md +185 -0
  576. package/node_modules/xmlbuilder2/node_modules/argparse/LICENSE +21 -0
  577. package/node_modules/xmlbuilder2/node_modules/argparse/README.md +257 -0
  578. package/node_modules/xmlbuilder2/node_modules/argparse/index.js +3 -0
  579. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/append/constant.js +47 -0
  580. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/append.js +53 -0
  581. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/count.js +40 -0
  582. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/help.js +47 -0
  583. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/store/constant.js +43 -0
  584. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/store/false.js +27 -0
  585. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/store/true.js +26 -0
  586. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/store.js +50 -0
  587. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/subparsers.js +149 -0
  588. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/version.js +47 -0
  589. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action.js +146 -0
  590. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action_container.js +482 -0
  591. package/node_modules/xmlbuilder2/node_modules/argparse/lib/argparse.js +14 -0
  592. package/node_modules/xmlbuilder2/node_modules/argparse/lib/argument/error.js +50 -0
  593. package/node_modules/xmlbuilder2/node_modules/argparse/lib/argument/exclusive.js +54 -0
  594. package/node_modules/xmlbuilder2/node_modules/argparse/lib/argument/group.js +75 -0
  595. package/node_modules/xmlbuilder2/node_modules/argparse/lib/argument_parser.js +1161 -0
  596. package/node_modules/xmlbuilder2/node_modules/argparse/lib/const.js +21 -0
  597. package/node_modules/xmlbuilder2/node_modules/argparse/lib/help/added_formatters.js +87 -0
  598. package/node_modules/xmlbuilder2/node_modules/argparse/lib/help/formatter.js +795 -0
  599. package/node_modules/xmlbuilder2/node_modules/argparse/lib/namespace.js +76 -0
  600. package/node_modules/xmlbuilder2/node_modules/argparse/lib/utils.js +57 -0
  601. package/node_modules/xmlbuilder2/node_modules/argparse/package.json +34 -0
  602. package/node_modules/xmlbuilder2/node_modules/js-yaml/CHANGELOG.md +557 -0
  603. package/node_modules/xmlbuilder2/node_modules/js-yaml/LICENSE +21 -0
  604. package/node_modules/xmlbuilder2/node_modules/js-yaml/README.md +299 -0
  605. package/node_modules/xmlbuilder2/node_modules/js-yaml/bin/js-yaml.js +132 -0
  606. package/node_modules/xmlbuilder2/node_modules/js-yaml/dist/js-yaml.js +3989 -0
  607. package/node_modules/xmlbuilder2/node_modules/js-yaml/dist/js-yaml.min.js +1 -0
  608. package/node_modules/xmlbuilder2/node_modules/js-yaml/index.js +7 -0
  609. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/common.js +59 -0
  610. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/dumper.js +850 -0
  611. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/exception.js +43 -0
  612. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/loader.js +1644 -0
  613. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/mark.js +76 -0
  614. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/schema/core.js +18 -0
  615. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/schema/default_full.js +25 -0
  616. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/schema/default_safe.js +28 -0
  617. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/schema/failsafe.js +17 -0
  618. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/schema/json.js +25 -0
  619. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/schema.js +108 -0
  620. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/binary.js +138 -0
  621. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/bool.js +35 -0
  622. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/float.js +116 -0
  623. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/int.js +173 -0
  624. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/js/function.js +93 -0
  625. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/js/regexp.js +60 -0
  626. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/js/undefined.js +28 -0
  627. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/map.js +8 -0
  628. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/merge.js +12 -0
  629. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/null.js +34 -0
  630. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/omap.js +44 -0
  631. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/pairs.js +53 -0
  632. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/seq.js +8 -0
  633. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/set.js +29 -0
  634. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/str.js +8 -0
  635. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/timestamp.js +88 -0
  636. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type.js +61 -0
  637. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml.js +39 -0
  638. package/node_modules/xmlbuilder2/node_modules/js-yaml/package.json +49 -0
  639. package/node_modules/xmlbuilder2/package.json +82 -0
  640. package/node_modules/xpath/LICENSE +22 -0
  641. package/node_modules/xpath/README.md +133 -0
  642. package/node_modules/xpath/package.json +43 -0
  643. package/node_modules/xpath/xpath.d.ts +51 -0
  644. package/node_modules/xpath/xpath.js +5041 -0
  645. package/package.json +9 -2
@@ -0,0 +1,2652 @@
1
+ /**
2
+ * Utility functions for web applications.
3
+ *
4
+ * @author Dave Longley
5
+ *
6
+ * Copyright (c) 2010-2018 Digital Bazaar, Inc.
7
+ */
8
+ var forge = require('./forge');
9
+ var baseN = require('./baseN');
10
+
11
+ /* Utilities API */
12
+ var util = module.exports = forge.util = forge.util || {};
13
+
14
+ // define setImmediate and nextTick
15
+ (function() {
16
+ // use native nextTick (unless we're in webpack)
17
+ // webpack (or better node-libs-browser polyfill) sets process.browser.
18
+ // this way we can detect webpack properly
19
+ if(typeof process !== 'undefined' && process.nextTick && !process.browser) {
20
+ util.nextTick = process.nextTick;
21
+ if(typeof setImmediate === 'function') {
22
+ util.setImmediate = setImmediate;
23
+ } else {
24
+ // polyfill setImmediate with nextTick, older versions of node
25
+ // (those w/o setImmediate) won't totally starve IO
26
+ util.setImmediate = util.nextTick;
27
+ }
28
+ return;
29
+ }
30
+
31
+ // polyfill nextTick with native setImmediate
32
+ if(typeof setImmediate === 'function') {
33
+ util.setImmediate = function() { return setImmediate.apply(undefined, arguments); };
34
+ util.nextTick = function(callback) {
35
+ return setImmediate(callback);
36
+ };
37
+ return;
38
+ }
39
+
40
+ /* Note: A polyfill upgrade pattern is used here to allow combining
41
+ polyfills. For example, MutationObserver is fast, but blocks UI updates,
42
+ so it needs to allow UI updates periodically, so it falls back on
43
+ postMessage or setTimeout. */
44
+
45
+ // polyfill with setTimeout
46
+ util.setImmediate = function(callback) {
47
+ setTimeout(callback, 0);
48
+ };
49
+
50
+ // upgrade polyfill to use postMessage
51
+ if(typeof window !== 'undefined' &&
52
+ typeof window.postMessage === 'function') {
53
+ var msg = 'forge.setImmediate';
54
+ var callbacks = [];
55
+ util.setImmediate = function(callback) {
56
+ callbacks.push(callback);
57
+ // only send message when one hasn't been sent in
58
+ // the current turn of the event loop
59
+ if(callbacks.length === 1) {
60
+ window.postMessage(msg, '*');
61
+ }
62
+ };
63
+ function handler(event) {
64
+ if(event.source === window && event.data === msg) {
65
+ event.stopPropagation();
66
+ var copy = callbacks.slice();
67
+ callbacks.length = 0;
68
+ copy.forEach(function(callback) {
69
+ callback();
70
+ });
71
+ }
72
+ }
73
+ window.addEventListener('message', handler, true);
74
+ }
75
+
76
+ // upgrade polyfill to use MutationObserver
77
+ if(typeof MutationObserver !== 'undefined') {
78
+ // polyfill with MutationObserver
79
+ var now = Date.now();
80
+ var attr = true;
81
+ var div = document.createElement('div');
82
+ var callbacks = [];
83
+ new MutationObserver(function() {
84
+ var copy = callbacks.slice();
85
+ callbacks.length = 0;
86
+ copy.forEach(function(callback) {
87
+ callback();
88
+ });
89
+ }).observe(div, {attributes: true});
90
+ var oldSetImmediate = util.setImmediate;
91
+ util.setImmediate = function(callback) {
92
+ if(Date.now() - now > 15) {
93
+ now = Date.now();
94
+ oldSetImmediate(callback);
95
+ } else {
96
+ callbacks.push(callback);
97
+ // only trigger observer when it hasn't been triggered in
98
+ // the current turn of the event loop
99
+ if(callbacks.length === 1) {
100
+ div.setAttribute('a', attr = !attr);
101
+ }
102
+ }
103
+ };
104
+ }
105
+
106
+ util.nextTick = util.setImmediate;
107
+ })();
108
+
109
+ // check if running under Node.js
110
+ util.isNodejs =
111
+ typeof process !== 'undefined' && process.versions && process.versions.node;
112
+
113
+
114
+ // 'self' will also work in Web Workers (instance of WorkerGlobalScope) while
115
+ // it will point to `window` in the main thread.
116
+ // To remain compatible with older browsers, we fall back to 'window' if 'self'
117
+ // is not available.
118
+ util.globalScope = (function() {
119
+ if(util.isNodejs) {
120
+ return global;
121
+ }
122
+
123
+ return typeof self === 'undefined' ? window : self;
124
+ })();
125
+
126
+ // define isArray
127
+ util.isArray = Array.isArray || function(x) {
128
+ return Object.prototype.toString.call(x) === '[object Array]';
129
+ };
130
+
131
+ // define isArrayBuffer
132
+ util.isArrayBuffer = function(x) {
133
+ return typeof ArrayBuffer !== 'undefined' && x instanceof ArrayBuffer;
134
+ };
135
+
136
+ // define isArrayBufferView
137
+ util.isArrayBufferView = function(x) {
138
+ return x && util.isArrayBuffer(x.buffer) && x.byteLength !== undefined;
139
+ };
140
+
141
+ /**
142
+ * Ensure a bits param is 8, 16, 24, or 32. Used to validate input for
143
+ * algorithms where bit manipulation, JavaScript limitations, and/or algorithm
144
+ * design only allow for byte operations of a limited size.
145
+ *
146
+ * @param n number of bits.
147
+ *
148
+ * Throw Error if n invalid.
149
+ */
150
+ function _checkBitsParam(n) {
151
+ if(!(n === 8 || n === 16 || n === 24 || n === 32)) {
152
+ throw new Error('Only 8, 16, 24, or 32 bits supported: ' + n);
153
+ }
154
+ }
155
+
156
+ // TODO: set ByteBuffer to best available backing
157
+ util.ByteBuffer = ByteStringBuffer;
158
+
159
+ /** Buffer w/BinaryString backing */
160
+
161
+ /**
162
+ * Constructor for a binary string backed byte buffer.
163
+ *
164
+ * @param [b] the bytes to wrap (either encoded as string, one byte per
165
+ * character, or as an ArrayBuffer or Typed Array).
166
+ */
167
+ function ByteStringBuffer(b) {
168
+ // TODO: update to match DataBuffer API
169
+
170
+ // the data in this buffer
171
+ this.data = '';
172
+ // the pointer for reading from this buffer
173
+ this.read = 0;
174
+
175
+ if(typeof b === 'string') {
176
+ this.data = b;
177
+ } else if(util.isArrayBuffer(b) || util.isArrayBufferView(b)) {
178
+ if(typeof Buffer !== 'undefined' && b instanceof Buffer) {
179
+ this.data = b.toString('binary');
180
+ } else {
181
+ // convert native buffer to forge buffer
182
+ // FIXME: support native buffers internally instead
183
+ var arr = new Uint8Array(b);
184
+ try {
185
+ this.data = String.fromCharCode.apply(null, arr);
186
+ } catch(e) {
187
+ for(var i = 0; i < arr.length; ++i) {
188
+ this.putByte(arr[i]);
189
+ }
190
+ }
191
+ }
192
+ } else if(b instanceof ByteStringBuffer ||
193
+ (typeof b === 'object' && typeof b.data === 'string' &&
194
+ typeof b.read === 'number')) {
195
+ // copy existing buffer
196
+ this.data = b.data;
197
+ this.read = b.read;
198
+ }
199
+
200
+ // used for v8 optimization
201
+ this._constructedStringLength = 0;
202
+ }
203
+ util.ByteStringBuffer = ByteStringBuffer;
204
+
205
+ /* Note: This is an optimization for V8-based browsers. When V8 concatenates
206
+ a string, the strings are only joined logically using a "cons string" or
207
+ "constructed/concatenated string". These containers keep references to one
208
+ another and can result in very large memory usage. For example, if a 2MB
209
+ string is constructed by concatenating 4 bytes together at a time, the
210
+ memory usage will be ~44MB; so ~22x increase. The strings are only joined
211
+ together when an operation requiring their joining takes place, such as
212
+ substr(). This function is called when adding data to this buffer to ensure
213
+ these types of strings are periodically joined to reduce the memory
214
+ footprint. */
215
+ var _MAX_CONSTRUCTED_STRING_LENGTH = 4096;
216
+ util.ByteStringBuffer.prototype._optimizeConstructedString = function(x) {
217
+ this._constructedStringLength += x;
218
+ if(this._constructedStringLength > _MAX_CONSTRUCTED_STRING_LENGTH) {
219
+ // this substr() should cause the constructed string to join
220
+ this.data.substr(0, 1);
221
+ this._constructedStringLength = 0;
222
+ }
223
+ };
224
+
225
+ /**
226
+ * Gets the number of bytes in this buffer.
227
+ *
228
+ * @return the number of bytes in this buffer.
229
+ */
230
+ util.ByteStringBuffer.prototype.length = function() {
231
+ return this.data.length - this.read;
232
+ };
233
+
234
+ /**
235
+ * Gets whether or not this buffer is empty.
236
+ *
237
+ * @return true if this buffer is empty, false if not.
238
+ */
239
+ util.ByteStringBuffer.prototype.isEmpty = function() {
240
+ return this.length() <= 0;
241
+ };
242
+
243
+ /**
244
+ * Puts a byte in this buffer.
245
+ *
246
+ * @param b the byte to put.
247
+ *
248
+ * @return this buffer.
249
+ */
250
+ util.ByteStringBuffer.prototype.putByte = function(b) {
251
+ return this.putBytes(String.fromCharCode(b));
252
+ };
253
+
254
+ /**
255
+ * Puts a byte in this buffer N times.
256
+ *
257
+ * @param b the byte to put.
258
+ * @param n the number of bytes of value b to put.
259
+ *
260
+ * @return this buffer.
261
+ */
262
+ util.ByteStringBuffer.prototype.fillWithByte = function(b, n) {
263
+ b = String.fromCharCode(b);
264
+ var d = this.data;
265
+ while(n > 0) {
266
+ if(n & 1) {
267
+ d += b;
268
+ }
269
+ n >>>= 1;
270
+ if(n > 0) {
271
+ b += b;
272
+ }
273
+ }
274
+ this.data = d;
275
+ this._optimizeConstructedString(n);
276
+ return this;
277
+ };
278
+
279
+ /**
280
+ * Puts bytes in this buffer.
281
+ *
282
+ * @param bytes the bytes (as a binary encoded string) to put.
283
+ *
284
+ * @return this buffer.
285
+ */
286
+ util.ByteStringBuffer.prototype.putBytes = function(bytes) {
287
+ this.data += bytes;
288
+ this._optimizeConstructedString(bytes.length);
289
+ return this;
290
+ };
291
+
292
+ /**
293
+ * Puts a UTF-16 encoded string into this buffer.
294
+ *
295
+ * @param str the string to put.
296
+ *
297
+ * @return this buffer.
298
+ */
299
+ util.ByteStringBuffer.prototype.putString = function(str) {
300
+ return this.putBytes(util.encodeUtf8(str));
301
+ };
302
+
303
+ /**
304
+ * Puts a 16-bit integer in this buffer in big-endian order.
305
+ *
306
+ * @param i the 16-bit integer.
307
+ *
308
+ * @return this buffer.
309
+ */
310
+ util.ByteStringBuffer.prototype.putInt16 = function(i) {
311
+ return this.putBytes(
312
+ String.fromCharCode(i >> 8 & 0xFF) +
313
+ String.fromCharCode(i & 0xFF));
314
+ };
315
+
316
+ /**
317
+ * Puts a 24-bit integer in this buffer in big-endian order.
318
+ *
319
+ * @param i the 24-bit integer.
320
+ *
321
+ * @return this buffer.
322
+ */
323
+ util.ByteStringBuffer.prototype.putInt24 = function(i) {
324
+ return this.putBytes(
325
+ String.fromCharCode(i >> 16 & 0xFF) +
326
+ String.fromCharCode(i >> 8 & 0xFF) +
327
+ String.fromCharCode(i & 0xFF));
328
+ };
329
+
330
+ /**
331
+ * Puts a 32-bit integer in this buffer in big-endian order.
332
+ *
333
+ * @param i the 32-bit integer.
334
+ *
335
+ * @return this buffer.
336
+ */
337
+ util.ByteStringBuffer.prototype.putInt32 = function(i) {
338
+ return this.putBytes(
339
+ String.fromCharCode(i >> 24 & 0xFF) +
340
+ String.fromCharCode(i >> 16 & 0xFF) +
341
+ String.fromCharCode(i >> 8 & 0xFF) +
342
+ String.fromCharCode(i & 0xFF));
343
+ };
344
+
345
+ /**
346
+ * Puts a 16-bit integer in this buffer in little-endian order.
347
+ *
348
+ * @param i the 16-bit integer.
349
+ *
350
+ * @return this buffer.
351
+ */
352
+ util.ByteStringBuffer.prototype.putInt16Le = function(i) {
353
+ return this.putBytes(
354
+ String.fromCharCode(i & 0xFF) +
355
+ String.fromCharCode(i >> 8 & 0xFF));
356
+ };
357
+
358
+ /**
359
+ * Puts a 24-bit integer in this buffer in little-endian order.
360
+ *
361
+ * @param i the 24-bit integer.
362
+ *
363
+ * @return this buffer.
364
+ */
365
+ util.ByteStringBuffer.prototype.putInt24Le = function(i) {
366
+ return this.putBytes(
367
+ String.fromCharCode(i & 0xFF) +
368
+ String.fromCharCode(i >> 8 & 0xFF) +
369
+ String.fromCharCode(i >> 16 & 0xFF));
370
+ };
371
+
372
+ /**
373
+ * Puts a 32-bit integer in this buffer in little-endian order.
374
+ *
375
+ * @param i the 32-bit integer.
376
+ *
377
+ * @return this buffer.
378
+ */
379
+ util.ByteStringBuffer.prototype.putInt32Le = function(i) {
380
+ return this.putBytes(
381
+ String.fromCharCode(i & 0xFF) +
382
+ String.fromCharCode(i >> 8 & 0xFF) +
383
+ String.fromCharCode(i >> 16 & 0xFF) +
384
+ String.fromCharCode(i >> 24 & 0xFF));
385
+ };
386
+
387
+ /**
388
+ * Puts an n-bit integer in this buffer in big-endian order.
389
+ *
390
+ * @param i the n-bit integer.
391
+ * @param n the number of bits in the integer (8, 16, 24, or 32).
392
+ *
393
+ * @return this buffer.
394
+ */
395
+ util.ByteStringBuffer.prototype.putInt = function(i, n) {
396
+ _checkBitsParam(n);
397
+ var bytes = '';
398
+ do {
399
+ n -= 8;
400
+ bytes += String.fromCharCode((i >> n) & 0xFF);
401
+ } while(n > 0);
402
+ return this.putBytes(bytes);
403
+ };
404
+
405
+ /**
406
+ * Puts a signed n-bit integer in this buffer in big-endian order. Two's
407
+ * complement representation is used.
408
+ *
409
+ * @param i the n-bit integer.
410
+ * @param n the number of bits in the integer (8, 16, 24, or 32).
411
+ *
412
+ * @return this buffer.
413
+ */
414
+ util.ByteStringBuffer.prototype.putSignedInt = function(i, n) {
415
+ // putInt checks n
416
+ if(i < 0) {
417
+ i += 2 << (n - 1);
418
+ }
419
+ return this.putInt(i, n);
420
+ };
421
+
422
+ /**
423
+ * Puts the given buffer into this buffer.
424
+ *
425
+ * @param buffer the buffer to put into this one.
426
+ *
427
+ * @return this buffer.
428
+ */
429
+ util.ByteStringBuffer.prototype.putBuffer = function(buffer) {
430
+ return this.putBytes(buffer.getBytes());
431
+ };
432
+
433
+ /**
434
+ * Gets a byte from this buffer and advances the read pointer by 1.
435
+ *
436
+ * @return the byte.
437
+ */
438
+ util.ByteStringBuffer.prototype.getByte = function() {
439
+ return this.data.charCodeAt(this.read++);
440
+ };
441
+
442
+ /**
443
+ * Gets a uint16 from this buffer in big-endian order and advances the read
444
+ * pointer by 2.
445
+ *
446
+ * @return the uint16.
447
+ */
448
+ util.ByteStringBuffer.prototype.getInt16 = function() {
449
+ var rval = (
450
+ this.data.charCodeAt(this.read) << 8 ^
451
+ this.data.charCodeAt(this.read + 1));
452
+ this.read += 2;
453
+ return rval;
454
+ };
455
+
456
+ /**
457
+ * Gets a uint24 from this buffer in big-endian order and advances the read
458
+ * pointer by 3.
459
+ *
460
+ * @return the uint24.
461
+ */
462
+ util.ByteStringBuffer.prototype.getInt24 = function() {
463
+ var rval = (
464
+ this.data.charCodeAt(this.read) << 16 ^
465
+ this.data.charCodeAt(this.read + 1) << 8 ^
466
+ this.data.charCodeAt(this.read + 2));
467
+ this.read += 3;
468
+ return rval;
469
+ };
470
+
471
+ /**
472
+ * Gets a uint32 from this buffer in big-endian order and advances the read
473
+ * pointer by 4.
474
+ *
475
+ * @return the word.
476
+ */
477
+ util.ByteStringBuffer.prototype.getInt32 = function() {
478
+ var rval = (
479
+ this.data.charCodeAt(this.read) << 24 ^
480
+ this.data.charCodeAt(this.read + 1) << 16 ^
481
+ this.data.charCodeAt(this.read + 2) << 8 ^
482
+ this.data.charCodeAt(this.read + 3));
483
+ this.read += 4;
484
+ return rval;
485
+ };
486
+
487
+ /**
488
+ * Gets a uint16 from this buffer in little-endian order and advances the read
489
+ * pointer by 2.
490
+ *
491
+ * @return the uint16.
492
+ */
493
+ util.ByteStringBuffer.prototype.getInt16Le = function() {
494
+ var rval = (
495
+ this.data.charCodeAt(this.read) ^
496
+ this.data.charCodeAt(this.read + 1) << 8);
497
+ this.read += 2;
498
+ return rval;
499
+ };
500
+
501
+ /**
502
+ * Gets a uint24 from this buffer in little-endian order and advances the read
503
+ * pointer by 3.
504
+ *
505
+ * @return the uint24.
506
+ */
507
+ util.ByteStringBuffer.prototype.getInt24Le = function() {
508
+ var rval = (
509
+ this.data.charCodeAt(this.read) ^
510
+ this.data.charCodeAt(this.read + 1) << 8 ^
511
+ this.data.charCodeAt(this.read + 2) << 16);
512
+ this.read += 3;
513
+ return rval;
514
+ };
515
+
516
+ /**
517
+ * Gets a uint32 from this buffer in little-endian order and advances the read
518
+ * pointer by 4.
519
+ *
520
+ * @return the word.
521
+ */
522
+ util.ByteStringBuffer.prototype.getInt32Le = function() {
523
+ var rval = (
524
+ this.data.charCodeAt(this.read) ^
525
+ this.data.charCodeAt(this.read + 1) << 8 ^
526
+ this.data.charCodeAt(this.read + 2) << 16 ^
527
+ this.data.charCodeAt(this.read + 3) << 24);
528
+ this.read += 4;
529
+ return rval;
530
+ };
531
+
532
+ /**
533
+ * Gets an n-bit integer from this buffer in big-endian order and advances the
534
+ * read pointer by ceil(n/8).
535
+ *
536
+ * @param n the number of bits in the integer (8, 16, 24, or 32).
537
+ *
538
+ * @return the integer.
539
+ */
540
+ util.ByteStringBuffer.prototype.getInt = function(n) {
541
+ _checkBitsParam(n);
542
+ var rval = 0;
543
+ do {
544
+ // TODO: Use (rval * 0x100) if adding support for 33 to 53 bits.
545
+ rval = (rval << 8) + this.data.charCodeAt(this.read++);
546
+ n -= 8;
547
+ } while(n > 0);
548
+ return rval;
549
+ };
550
+
551
+ /**
552
+ * Gets a signed n-bit integer from this buffer in big-endian order, using
553
+ * two's complement, and advances the read pointer by n/8.
554
+ *
555
+ * @param n the number of bits in the integer (8, 16, 24, or 32).
556
+ *
557
+ * @return the integer.
558
+ */
559
+ util.ByteStringBuffer.prototype.getSignedInt = function(n) {
560
+ // getInt checks n
561
+ var x = this.getInt(n);
562
+ var max = 2 << (n - 2);
563
+ if(x >= max) {
564
+ x -= max << 1;
565
+ }
566
+ return x;
567
+ };
568
+
569
+ /**
570
+ * Reads bytes out as a binary encoded string and clears them from the
571
+ * buffer. Note that the resulting string is binary encoded (in node.js this
572
+ * encoding is referred to as `binary`, it is *not* `utf8`).
573
+ *
574
+ * @param count the number of bytes to read, undefined or null for all.
575
+ *
576
+ * @return a binary encoded string of bytes.
577
+ */
578
+ util.ByteStringBuffer.prototype.getBytes = function(count) {
579
+ var rval;
580
+ if(count) {
581
+ // read count bytes
582
+ count = Math.min(this.length(), count);
583
+ rval = this.data.slice(this.read, this.read + count);
584
+ this.read += count;
585
+ } else if(count === 0) {
586
+ rval = '';
587
+ } else {
588
+ // read all bytes, optimize to only copy when needed
589
+ rval = (this.read === 0) ? this.data : this.data.slice(this.read);
590
+ this.clear();
591
+ }
592
+ return rval;
593
+ };
594
+
595
+ /**
596
+ * Gets a binary encoded string of the bytes from this buffer without
597
+ * modifying the read pointer.
598
+ *
599
+ * @param count the number of bytes to get, omit to get all.
600
+ *
601
+ * @return a string full of binary encoded characters.
602
+ */
603
+ util.ByteStringBuffer.prototype.bytes = function(count) {
604
+ return (typeof(count) === 'undefined' ?
605
+ this.data.slice(this.read) :
606
+ this.data.slice(this.read, this.read + count));
607
+ };
608
+
609
+ /**
610
+ * Gets a byte at the given index without modifying the read pointer.
611
+ *
612
+ * @param i the byte index.
613
+ *
614
+ * @return the byte.
615
+ */
616
+ util.ByteStringBuffer.prototype.at = function(i) {
617
+ return this.data.charCodeAt(this.read + i);
618
+ };
619
+
620
+ /**
621
+ * Puts a byte at the given index without modifying the read pointer.
622
+ *
623
+ * @param i the byte index.
624
+ * @param b the byte to put.
625
+ *
626
+ * @return this buffer.
627
+ */
628
+ util.ByteStringBuffer.prototype.setAt = function(i, b) {
629
+ this.data = this.data.substr(0, this.read + i) +
630
+ String.fromCharCode(b) +
631
+ this.data.substr(this.read + i + 1);
632
+ return this;
633
+ };
634
+
635
+ /**
636
+ * Gets the last byte without modifying the read pointer.
637
+ *
638
+ * @return the last byte.
639
+ */
640
+ util.ByteStringBuffer.prototype.last = function() {
641
+ return this.data.charCodeAt(this.data.length - 1);
642
+ };
643
+
644
+ /**
645
+ * Creates a copy of this buffer.
646
+ *
647
+ * @return the copy.
648
+ */
649
+ util.ByteStringBuffer.prototype.copy = function() {
650
+ var c = util.createBuffer(this.data);
651
+ c.read = this.read;
652
+ return c;
653
+ };
654
+
655
+ /**
656
+ * Compacts this buffer.
657
+ *
658
+ * @return this buffer.
659
+ */
660
+ util.ByteStringBuffer.prototype.compact = function() {
661
+ if(this.read > 0) {
662
+ this.data = this.data.slice(this.read);
663
+ this.read = 0;
664
+ }
665
+ return this;
666
+ };
667
+
668
+ /**
669
+ * Clears this buffer.
670
+ *
671
+ * @return this buffer.
672
+ */
673
+ util.ByteStringBuffer.prototype.clear = function() {
674
+ this.data = '';
675
+ this.read = 0;
676
+ return this;
677
+ };
678
+
679
+ /**
680
+ * Shortens this buffer by trimming bytes off of the end of this buffer.
681
+ *
682
+ * @param count the number of bytes to trim off.
683
+ *
684
+ * @return this buffer.
685
+ */
686
+ util.ByteStringBuffer.prototype.truncate = function(count) {
687
+ var len = Math.max(0, this.length() - count);
688
+ this.data = this.data.substr(this.read, len);
689
+ this.read = 0;
690
+ return this;
691
+ };
692
+
693
+ /**
694
+ * Converts this buffer to a hexadecimal string.
695
+ *
696
+ * @return a hexadecimal string.
697
+ */
698
+ util.ByteStringBuffer.prototype.toHex = function() {
699
+ var rval = '';
700
+ for(var i = this.read; i < this.data.length; ++i) {
701
+ var b = this.data.charCodeAt(i);
702
+ if(b < 16) {
703
+ rval += '0';
704
+ }
705
+ rval += b.toString(16);
706
+ }
707
+ return rval;
708
+ };
709
+
710
+ /**
711
+ * Converts this buffer to a UTF-16 string (standard JavaScript string).
712
+ *
713
+ * @return a UTF-16 string.
714
+ */
715
+ util.ByteStringBuffer.prototype.toString = function() {
716
+ return util.decodeUtf8(this.bytes());
717
+ };
718
+
719
+ /** End Buffer w/BinaryString backing */
720
+
721
+ /** Buffer w/UInt8Array backing */
722
+
723
+ /**
724
+ * FIXME: Experimental. Do not use yet.
725
+ *
726
+ * Constructor for an ArrayBuffer-backed byte buffer.
727
+ *
728
+ * The buffer may be constructed from a string, an ArrayBuffer, DataView, or a
729
+ * TypedArray.
730
+ *
731
+ * If a string is given, its encoding should be provided as an option,
732
+ * otherwise it will default to 'binary'. A 'binary' string is encoded such
733
+ * that each character is one byte in length and size.
734
+ *
735
+ * If an ArrayBuffer, DataView, or TypedArray is given, it will be used
736
+ * *directly* without any copying. Note that, if a write to the buffer requires
737
+ * more space, the buffer will allocate a new backing ArrayBuffer to
738
+ * accommodate. The starting read and write offsets for the buffer may be
739
+ * given as options.
740
+ *
741
+ * @param [b] the initial bytes for this buffer.
742
+ * @param options the options to use:
743
+ * [readOffset] the starting read offset to use (default: 0).
744
+ * [writeOffset] the starting write offset to use (default: the
745
+ * length of the first parameter).
746
+ * [growSize] the minimum amount, in bytes, to grow the buffer by to
747
+ * accommodate writes (default: 1024).
748
+ * [encoding] the encoding ('binary', 'utf8', 'utf16', 'hex') for the
749
+ * first parameter, if it is a string (default: 'binary').
750
+ */
751
+ function DataBuffer(b, options) {
752
+ // default options
753
+ options = options || {};
754
+
755
+ // pointers for read from/write to buffer
756
+ this.read = options.readOffset || 0;
757
+ this.growSize = options.growSize || 1024;
758
+
759
+ var isArrayBuffer = util.isArrayBuffer(b);
760
+ var isArrayBufferView = util.isArrayBufferView(b);
761
+ if(isArrayBuffer || isArrayBufferView) {
762
+ // use ArrayBuffer directly
763
+ if(isArrayBuffer) {
764
+ this.data = new DataView(b);
765
+ } else {
766
+ // TODO: adjust read/write offset based on the type of view
767
+ // or specify that this must be done in the options ... that the
768
+ // offsets are byte-based
769
+ this.data = new DataView(b.buffer, b.byteOffset, b.byteLength);
770
+ }
771
+ this.write = ('writeOffset' in options ?
772
+ options.writeOffset : this.data.byteLength);
773
+ return;
774
+ }
775
+
776
+ // initialize to empty array buffer and add any given bytes using putBytes
777
+ this.data = new DataView(new ArrayBuffer(0));
778
+ this.write = 0;
779
+
780
+ if(b !== null && b !== undefined) {
781
+ this.putBytes(b);
782
+ }
783
+
784
+ if('writeOffset' in options) {
785
+ this.write = options.writeOffset;
786
+ }
787
+ }
788
+ util.DataBuffer = DataBuffer;
789
+
790
+ /**
791
+ * Gets the number of bytes in this buffer.
792
+ *
793
+ * @return the number of bytes in this buffer.
794
+ */
795
+ util.DataBuffer.prototype.length = function() {
796
+ return this.write - this.read;
797
+ };
798
+
799
+ /**
800
+ * Gets whether or not this buffer is empty.
801
+ *
802
+ * @return true if this buffer is empty, false if not.
803
+ */
804
+ util.DataBuffer.prototype.isEmpty = function() {
805
+ return this.length() <= 0;
806
+ };
807
+
808
+ /**
809
+ * Ensures this buffer has enough empty space to accommodate the given number
810
+ * of bytes. An optional parameter may be given that indicates a minimum
811
+ * amount to grow the buffer if necessary. If the parameter is not given,
812
+ * the buffer will be grown by some previously-specified default amount
813
+ * or heuristic.
814
+ *
815
+ * @param amount the number of bytes to accommodate.
816
+ * @param [growSize] the minimum amount, in bytes, to grow the buffer by if
817
+ * necessary.
818
+ */
819
+ util.DataBuffer.prototype.accommodate = function(amount, growSize) {
820
+ if(this.length() >= amount) {
821
+ return this;
822
+ }
823
+ growSize = Math.max(growSize || this.growSize, amount);
824
+
825
+ // grow buffer
826
+ var src = new Uint8Array(
827
+ this.data.buffer, this.data.byteOffset, this.data.byteLength);
828
+ var dst = new Uint8Array(this.length() + growSize);
829
+ dst.set(src);
830
+ this.data = new DataView(dst.buffer);
831
+
832
+ return this;
833
+ };
834
+
835
+ /**
836
+ * Puts a byte in this buffer.
837
+ *
838
+ * @param b the byte to put.
839
+ *
840
+ * @return this buffer.
841
+ */
842
+ util.DataBuffer.prototype.putByte = function(b) {
843
+ this.accommodate(1);
844
+ this.data.setUint8(this.write++, b);
845
+ return this;
846
+ };
847
+
848
+ /**
849
+ * Puts a byte in this buffer N times.
850
+ *
851
+ * @param b the byte to put.
852
+ * @param n the number of bytes of value b to put.
853
+ *
854
+ * @return this buffer.
855
+ */
856
+ util.DataBuffer.prototype.fillWithByte = function(b, n) {
857
+ this.accommodate(n);
858
+ for(var i = 0; i < n; ++i) {
859
+ this.data.setUint8(b);
860
+ }
861
+ return this;
862
+ };
863
+
864
+ /**
865
+ * Puts bytes in this buffer. The bytes may be given as a string, an
866
+ * ArrayBuffer, a DataView, or a TypedArray.
867
+ *
868
+ * @param bytes the bytes to put.
869
+ * @param [encoding] the encoding for the first parameter ('binary', 'utf8',
870
+ * 'utf16', 'hex'), if it is a string (default: 'binary').
871
+ *
872
+ * @return this buffer.
873
+ */
874
+ util.DataBuffer.prototype.putBytes = function(bytes, encoding) {
875
+ if(util.isArrayBufferView(bytes)) {
876
+ var src = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
877
+ var len = src.byteLength - src.byteOffset;
878
+ this.accommodate(len);
879
+ var dst = new Uint8Array(this.data.buffer, this.write);
880
+ dst.set(src);
881
+ this.write += len;
882
+ return this;
883
+ }
884
+
885
+ if(util.isArrayBuffer(bytes)) {
886
+ var src = new Uint8Array(bytes);
887
+ this.accommodate(src.byteLength);
888
+ var dst = new Uint8Array(this.data.buffer);
889
+ dst.set(src, this.write);
890
+ this.write += src.byteLength;
891
+ return this;
892
+ }
893
+
894
+ // bytes is a util.DataBuffer or equivalent
895
+ if(bytes instanceof util.DataBuffer ||
896
+ (typeof bytes === 'object' &&
897
+ typeof bytes.read === 'number' && typeof bytes.write === 'number' &&
898
+ util.isArrayBufferView(bytes.data))) {
899
+ var src = new Uint8Array(bytes.data.byteLength, bytes.read, bytes.length());
900
+ this.accommodate(src.byteLength);
901
+ var dst = new Uint8Array(bytes.data.byteLength, this.write);
902
+ dst.set(src);
903
+ this.write += src.byteLength;
904
+ return this;
905
+ }
906
+
907
+ if(bytes instanceof util.ByteStringBuffer) {
908
+ // copy binary string and process as the same as a string parameter below
909
+ bytes = bytes.data;
910
+ encoding = 'binary';
911
+ }
912
+
913
+ // string conversion
914
+ encoding = encoding || 'binary';
915
+ if(typeof bytes === 'string') {
916
+ var view;
917
+
918
+ // decode from string
919
+ if(encoding === 'hex') {
920
+ this.accommodate(Math.ceil(bytes.length / 2));
921
+ view = new Uint8Array(this.data.buffer, this.write);
922
+ this.write += util.binary.hex.decode(bytes, view, this.write);
923
+ return this;
924
+ }
925
+ if(encoding === 'base64') {
926
+ this.accommodate(Math.ceil(bytes.length / 4) * 3);
927
+ view = new Uint8Array(this.data.buffer, this.write);
928
+ this.write += util.binary.base64.decode(bytes, view, this.write);
929
+ return this;
930
+ }
931
+
932
+ // encode text as UTF-8 bytes
933
+ if(encoding === 'utf8') {
934
+ // encode as UTF-8 then decode string as raw binary
935
+ bytes = util.encodeUtf8(bytes);
936
+ encoding = 'binary';
937
+ }
938
+
939
+ // decode string as raw binary
940
+ if(encoding === 'binary' || encoding === 'raw') {
941
+ // one byte per character
942
+ this.accommodate(bytes.length);
943
+ view = new Uint8Array(this.data.buffer, this.write);
944
+ this.write += util.binary.raw.decode(view);
945
+ return this;
946
+ }
947
+
948
+ // encode text as UTF-16 bytes
949
+ if(encoding === 'utf16') {
950
+ // two bytes per character
951
+ this.accommodate(bytes.length * 2);
952
+ view = new Uint16Array(this.data.buffer, this.write);
953
+ this.write += util.text.utf16.encode(view);
954
+ return this;
955
+ }
956
+
957
+ throw new Error('Invalid encoding: ' + encoding);
958
+ }
959
+
960
+ throw Error('Invalid parameter: ' + bytes);
961
+ };
962
+
963
+ /**
964
+ * Puts the given buffer into this buffer.
965
+ *
966
+ * @param buffer the buffer to put into this one.
967
+ *
968
+ * @return this buffer.
969
+ */
970
+ util.DataBuffer.prototype.putBuffer = function(buffer) {
971
+ this.putBytes(buffer);
972
+ buffer.clear();
973
+ return this;
974
+ };
975
+
976
+ /**
977
+ * Puts a string into this buffer.
978
+ *
979
+ * @param str the string to put.
980
+ * @param [encoding] the encoding for the string (default: 'utf16').
981
+ *
982
+ * @return this buffer.
983
+ */
984
+ util.DataBuffer.prototype.putString = function(str) {
985
+ return this.putBytes(str, 'utf16');
986
+ };
987
+
988
+ /**
989
+ * Puts a 16-bit integer in this buffer in big-endian order.
990
+ *
991
+ * @param i the 16-bit integer.
992
+ *
993
+ * @return this buffer.
994
+ */
995
+ util.DataBuffer.prototype.putInt16 = function(i) {
996
+ this.accommodate(2);
997
+ this.data.setInt16(this.write, i);
998
+ this.write += 2;
999
+ return this;
1000
+ };
1001
+
1002
+ /**
1003
+ * Puts a 24-bit integer in this buffer in big-endian order.
1004
+ *
1005
+ * @param i the 24-bit integer.
1006
+ *
1007
+ * @return this buffer.
1008
+ */
1009
+ util.DataBuffer.prototype.putInt24 = function(i) {
1010
+ this.accommodate(3);
1011
+ this.data.setInt16(this.write, i >> 8 & 0xFFFF);
1012
+ this.data.setInt8(this.write, i >> 16 & 0xFF);
1013
+ this.write += 3;
1014
+ return this;
1015
+ };
1016
+
1017
+ /**
1018
+ * Puts a 32-bit integer in this buffer in big-endian order.
1019
+ *
1020
+ * @param i the 32-bit integer.
1021
+ *
1022
+ * @return this buffer.
1023
+ */
1024
+ util.DataBuffer.prototype.putInt32 = function(i) {
1025
+ this.accommodate(4);
1026
+ this.data.setInt32(this.write, i);
1027
+ this.write += 4;
1028
+ return this;
1029
+ };
1030
+
1031
+ /**
1032
+ * Puts a 16-bit integer in this buffer in little-endian order.
1033
+ *
1034
+ * @param i the 16-bit integer.
1035
+ *
1036
+ * @return this buffer.
1037
+ */
1038
+ util.DataBuffer.prototype.putInt16Le = function(i) {
1039
+ this.accommodate(2);
1040
+ this.data.setInt16(this.write, i, true);
1041
+ this.write += 2;
1042
+ return this;
1043
+ };
1044
+
1045
+ /**
1046
+ * Puts a 24-bit integer in this buffer in little-endian order.
1047
+ *
1048
+ * @param i the 24-bit integer.
1049
+ *
1050
+ * @return this buffer.
1051
+ */
1052
+ util.DataBuffer.prototype.putInt24Le = function(i) {
1053
+ this.accommodate(3);
1054
+ this.data.setInt8(this.write, i >> 16 & 0xFF);
1055
+ this.data.setInt16(this.write, i >> 8 & 0xFFFF, true);
1056
+ this.write += 3;
1057
+ return this;
1058
+ };
1059
+
1060
+ /**
1061
+ * Puts a 32-bit integer in this buffer in little-endian order.
1062
+ *
1063
+ * @param i the 32-bit integer.
1064
+ *
1065
+ * @return this buffer.
1066
+ */
1067
+ util.DataBuffer.prototype.putInt32Le = function(i) {
1068
+ this.accommodate(4);
1069
+ this.data.setInt32(this.write, i, true);
1070
+ this.write += 4;
1071
+ return this;
1072
+ };
1073
+
1074
+ /**
1075
+ * Puts an n-bit integer in this buffer in big-endian order.
1076
+ *
1077
+ * @param i the n-bit integer.
1078
+ * @param n the number of bits in the integer (8, 16, 24, or 32).
1079
+ *
1080
+ * @return this buffer.
1081
+ */
1082
+ util.DataBuffer.prototype.putInt = function(i, n) {
1083
+ _checkBitsParam(n);
1084
+ this.accommodate(n / 8);
1085
+ do {
1086
+ n -= 8;
1087
+ this.data.setInt8(this.write++, (i >> n) & 0xFF);
1088
+ } while(n > 0);
1089
+ return this;
1090
+ };
1091
+
1092
+ /**
1093
+ * Puts a signed n-bit integer in this buffer in big-endian order. Two's
1094
+ * complement representation is used.
1095
+ *
1096
+ * @param i the n-bit integer.
1097
+ * @param n the number of bits in the integer.
1098
+ *
1099
+ * @return this buffer.
1100
+ */
1101
+ util.DataBuffer.prototype.putSignedInt = function(i, n) {
1102
+ _checkBitsParam(n);
1103
+ this.accommodate(n / 8);
1104
+ if(i < 0) {
1105
+ i += 2 << (n - 1);
1106
+ }
1107
+ return this.putInt(i, n);
1108
+ };
1109
+
1110
+ /**
1111
+ * Gets a byte from this buffer and advances the read pointer by 1.
1112
+ *
1113
+ * @return the byte.
1114
+ */
1115
+ util.DataBuffer.prototype.getByte = function() {
1116
+ return this.data.getInt8(this.read++);
1117
+ };
1118
+
1119
+ /**
1120
+ * Gets a uint16 from this buffer in big-endian order and advances the read
1121
+ * pointer by 2.
1122
+ *
1123
+ * @return the uint16.
1124
+ */
1125
+ util.DataBuffer.prototype.getInt16 = function() {
1126
+ var rval = this.data.getInt16(this.read);
1127
+ this.read += 2;
1128
+ return rval;
1129
+ };
1130
+
1131
+ /**
1132
+ * Gets a uint24 from this buffer in big-endian order and advances the read
1133
+ * pointer by 3.
1134
+ *
1135
+ * @return the uint24.
1136
+ */
1137
+ util.DataBuffer.prototype.getInt24 = function() {
1138
+ var rval = (
1139
+ this.data.getInt16(this.read) << 8 ^
1140
+ this.data.getInt8(this.read + 2));
1141
+ this.read += 3;
1142
+ return rval;
1143
+ };
1144
+
1145
+ /**
1146
+ * Gets a uint32 from this buffer in big-endian order and advances the read
1147
+ * pointer by 4.
1148
+ *
1149
+ * @return the word.
1150
+ */
1151
+ util.DataBuffer.prototype.getInt32 = function() {
1152
+ var rval = this.data.getInt32(this.read);
1153
+ this.read += 4;
1154
+ return rval;
1155
+ };
1156
+
1157
+ /**
1158
+ * Gets a uint16 from this buffer in little-endian order and advances the read
1159
+ * pointer by 2.
1160
+ *
1161
+ * @return the uint16.
1162
+ */
1163
+ util.DataBuffer.prototype.getInt16Le = function() {
1164
+ var rval = this.data.getInt16(this.read, true);
1165
+ this.read += 2;
1166
+ return rval;
1167
+ };
1168
+
1169
+ /**
1170
+ * Gets a uint24 from this buffer in little-endian order and advances the read
1171
+ * pointer by 3.
1172
+ *
1173
+ * @return the uint24.
1174
+ */
1175
+ util.DataBuffer.prototype.getInt24Le = function() {
1176
+ var rval = (
1177
+ this.data.getInt8(this.read) ^
1178
+ this.data.getInt16(this.read + 1, true) << 8);
1179
+ this.read += 3;
1180
+ return rval;
1181
+ };
1182
+
1183
+ /**
1184
+ * Gets a uint32 from this buffer in little-endian order and advances the read
1185
+ * pointer by 4.
1186
+ *
1187
+ * @return the word.
1188
+ */
1189
+ util.DataBuffer.prototype.getInt32Le = function() {
1190
+ var rval = this.data.getInt32(this.read, true);
1191
+ this.read += 4;
1192
+ return rval;
1193
+ };
1194
+
1195
+ /**
1196
+ * Gets an n-bit integer from this buffer in big-endian order and advances the
1197
+ * read pointer by n/8.
1198
+ *
1199
+ * @param n the number of bits in the integer (8, 16, 24, or 32).
1200
+ *
1201
+ * @return the integer.
1202
+ */
1203
+ util.DataBuffer.prototype.getInt = function(n) {
1204
+ _checkBitsParam(n);
1205
+ var rval = 0;
1206
+ do {
1207
+ // TODO: Use (rval * 0x100) if adding support for 33 to 53 bits.
1208
+ rval = (rval << 8) + this.data.getInt8(this.read++);
1209
+ n -= 8;
1210
+ } while(n > 0);
1211
+ return rval;
1212
+ };
1213
+
1214
+ /**
1215
+ * Gets a signed n-bit integer from this buffer in big-endian order, using
1216
+ * two's complement, and advances the read pointer by n/8.
1217
+ *
1218
+ * @param n the number of bits in the integer (8, 16, 24, or 32).
1219
+ *
1220
+ * @return the integer.
1221
+ */
1222
+ util.DataBuffer.prototype.getSignedInt = function(n) {
1223
+ // getInt checks n
1224
+ var x = this.getInt(n);
1225
+ var max = 2 << (n - 2);
1226
+ if(x >= max) {
1227
+ x -= max << 1;
1228
+ }
1229
+ return x;
1230
+ };
1231
+
1232
+ /**
1233
+ * Reads bytes out as a binary encoded string and clears them from the
1234
+ * buffer.
1235
+ *
1236
+ * @param count the number of bytes to read, undefined or null for all.
1237
+ *
1238
+ * @return a binary encoded string of bytes.
1239
+ */
1240
+ util.DataBuffer.prototype.getBytes = function(count) {
1241
+ // TODO: deprecate this method, it is poorly named and
1242
+ // this.toString('binary') replaces it
1243
+ // add a toTypedArray()/toArrayBuffer() function
1244
+ var rval;
1245
+ if(count) {
1246
+ // read count bytes
1247
+ count = Math.min(this.length(), count);
1248
+ rval = this.data.slice(this.read, this.read + count);
1249
+ this.read += count;
1250
+ } else if(count === 0) {
1251
+ rval = '';
1252
+ } else {
1253
+ // read all bytes, optimize to only copy when needed
1254
+ rval = (this.read === 0) ? this.data : this.data.slice(this.read);
1255
+ this.clear();
1256
+ }
1257
+ return rval;
1258
+ };
1259
+
1260
+ /**
1261
+ * Gets a binary encoded string of the bytes from this buffer without
1262
+ * modifying the read pointer.
1263
+ *
1264
+ * @param count the number of bytes to get, omit to get all.
1265
+ *
1266
+ * @return a string full of binary encoded characters.
1267
+ */
1268
+ util.DataBuffer.prototype.bytes = function(count) {
1269
+ // TODO: deprecate this method, it is poorly named, add "getString()"
1270
+ return (typeof(count) === 'undefined' ?
1271
+ this.data.slice(this.read) :
1272
+ this.data.slice(this.read, this.read + count));
1273
+ };
1274
+
1275
+ /**
1276
+ * Gets a byte at the given index without modifying the read pointer.
1277
+ *
1278
+ * @param i the byte index.
1279
+ *
1280
+ * @return the byte.
1281
+ */
1282
+ util.DataBuffer.prototype.at = function(i) {
1283
+ return this.data.getUint8(this.read + i);
1284
+ };
1285
+
1286
+ /**
1287
+ * Puts a byte at the given index without modifying the read pointer.
1288
+ *
1289
+ * @param i the byte index.
1290
+ * @param b the byte to put.
1291
+ *
1292
+ * @return this buffer.
1293
+ */
1294
+ util.DataBuffer.prototype.setAt = function(i, b) {
1295
+ this.data.setUint8(i, b);
1296
+ return this;
1297
+ };
1298
+
1299
+ /**
1300
+ * Gets the last byte without modifying the read pointer.
1301
+ *
1302
+ * @return the last byte.
1303
+ */
1304
+ util.DataBuffer.prototype.last = function() {
1305
+ return this.data.getUint8(this.write - 1);
1306
+ };
1307
+
1308
+ /**
1309
+ * Creates a copy of this buffer.
1310
+ *
1311
+ * @return the copy.
1312
+ */
1313
+ util.DataBuffer.prototype.copy = function() {
1314
+ return new util.DataBuffer(this);
1315
+ };
1316
+
1317
+ /**
1318
+ * Compacts this buffer.
1319
+ *
1320
+ * @return this buffer.
1321
+ */
1322
+ util.DataBuffer.prototype.compact = function() {
1323
+ if(this.read > 0) {
1324
+ var src = new Uint8Array(this.data.buffer, this.read);
1325
+ var dst = new Uint8Array(src.byteLength);
1326
+ dst.set(src);
1327
+ this.data = new DataView(dst);
1328
+ this.write -= this.read;
1329
+ this.read = 0;
1330
+ }
1331
+ return this;
1332
+ };
1333
+
1334
+ /**
1335
+ * Clears this buffer.
1336
+ *
1337
+ * @return this buffer.
1338
+ */
1339
+ util.DataBuffer.prototype.clear = function() {
1340
+ this.data = new DataView(new ArrayBuffer(0));
1341
+ this.read = this.write = 0;
1342
+ return this;
1343
+ };
1344
+
1345
+ /**
1346
+ * Shortens this buffer by trimming bytes off of the end of this buffer.
1347
+ *
1348
+ * @param count the number of bytes to trim off.
1349
+ *
1350
+ * @return this buffer.
1351
+ */
1352
+ util.DataBuffer.prototype.truncate = function(count) {
1353
+ this.write = Math.max(0, this.length() - count);
1354
+ this.read = Math.min(this.read, this.write);
1355
+ return this;
1356
+ };
1357
+
1358
+ /**
1359
+ * Converts this buffer to a hexadecimal string.
1360
+ *
1361
+ * @return a hexadecimal string.
1362
+ */
1363
+ util.DataBuffer.prototype.toHex = function() {
1364
+ var rval = '';
1365
+ for(var i = this.read; i < this.data.byteLength; ++i) {
1366
+ var b = this.data.getUint8(i);
1367
+ if(b < 16) {
1368
+ rval += '0';
1369
+ }
1370
+ rval += b.toString(16);
1371
+ }
1372
+ return rval;
1373
+ };
1374
+
1375
+ /**
1376
+ * Converts this buffer to a string, using the given encoding. If no
1377
+ * encoding is given, 'utf8' (UTF-8) is used.
1378
+ *
1379
+ * @param [encoding] the encoding to use: 'binary', 'utf8', 'utf16', 'hex',
1380
+ * 'base64' (default: 'utf8').
1381
+ *
1382
+ * @return a string representation of the bytes in this buffer.
1383
+ */
1384
+ util.DataBuffer.prototype.toString = function(encoding) {
1385
+ var view = new Uint8Array(this.data, this.read, this.length());
1386
+ encoding = encoding || 'utf8';
1387
+
1388
+ // encode to string
1389
+ if(encoding === 'binary' || encoding === 'raw') {
1390
+ return util.binary.raw.encode(view);
1391
+ }
1392
+ if(encoding === 'hex') {
1393
+ return util.binary.hex.encode(view);
1394
+ }
1395
+ if(encoding === 'base64') {
1396
+ return util.binary.base64.encode(view);
1397
+ }
1398
+
1399
+ // decode to text
1400
+ if(encoding === 'utf8') {
1401
+ return util.text.utf8.decode(view);
1402
+ }
1403
+ if(encoding === 'utf16') {
1404
+ return util.text.utf16.decode(view);
1405
+ }
1406
+
1407
+ throw new Error('Invalid encoding: ' + encoding);
1408
+ };
1409
+
1410
+ /** End Buffer w/UInt8Array backing */
1411
+
1412
+ /**
1413
+ * Creates a buffer that stores bytes. A value may be given to populate the
1414
+ * buffer with data. This value can either be string of encoded bytes or a
1415
+ * regular string of characters. When passing a string of binary encoded
1416
+ * bytes, the encoding `raw` should be given. This is also the default. When
1417
+ * passing a string of characters, the encoding `utf8` should be given.
1418
+ *
1419
+ * @param [input] a string with encoded bytes to store in the buffer.
1420
+ * @param [encoding] (default: 'raw', other: 'utf8').
1421
+ */
1422
+ util.createBuffer = function(input, encoding) {
1423
+ // TODO: deprecate, use new ByteBuffer() instead
1424
+ encoding = encoding || 'raw';
1425
+ if(input !== undefined && encoding === 'utf8') {
1426
+ input = util.encodeUtf8(input);
1427
+ }
1428
+ return new util.ByteBuffer(input);
1429
+ };
1430
+
1431
+ /**
1432
+ * Fills a string with a particular value. If you want the string to be a byte
1433
+ * string, pass in String.fromCharCode(theByte).
1434
+ *
1435
+ * @param c the character to fill the string with, use String.fromCharCode
1436
+ * to fill the string with a byte value.
1437
+ * @param n the number of characters of value c to fill with.
1438
+ *
1439
+ * @return the filled string.
1440
+ */
1441
+ util.fillString = function(c, n) {
1442
+ var s = '';
1443
+ while(n > 0) {
1444
+ if(n & 1) {
1445
+ s += c;
1446
+ }
1447
+ n >>>= 1;
1448
+ if(n > 0) {
1449
+ c += c;
1450
+ }
1451
+ }
1452
+ return s;
1453
+ };
1454
+
1455
+ /**
1456
+ * Performs a per byte XOR between two byte strings and returns the result as a
1457
+ * string of bytes.
1458
+ *
1459
+ * @param s1 first string of bytes.
1460
+ * @param s2 second string of bytes.
1461
+ * @param n the number of bytes to XOR.
1462
+ *
1463
+ * @return the XOR'd result.
1464
+ */
1465
+ util.xorBytes = function(s1, s2, n) {
1466
+ var s3 = '';
1467
+ var b = '';
1468
+ var t = '';
1469
+ var i = 0;
1470
+ var c = 0;
1471
+ for(; n > 0; --n, ++i) {
1472
+ b = s1.charCodeAt(i) ^ s2.charCodeAt(i);
1473
+ if(c >= 10) {
1474
+ s3 += t;
1475
+ t = '';
1476
+ c = 0;
1477
+ }
1478
+ t += String.fromCharCode(b);
1479
+ ++c;
1480
+ }
1481
+ s3 += t;
1482
+ return s3;
1483
+ };
1484
+
1485
+ /**
1486
+ * Converts a hex string into a 'binary' encoded string of bytes.
1487
+ *
1488
+ * @param hex the hexadecimal string to convert.
1489
+ *
1490
+ * @return the binary-encoded string of bytes.
1491
+ */
1492
+ util.hexToBytes = function(hex) {
1493
+ // TODO: deprecate: "Deprecated. Use util.binary.hex.decode instead."
1494
+ var rval = '';
1495
+ var i = 0;
1496
+ if(hex.length & 1 == 1) {
1497
+ // odd number of characters, convert first character alone
1498
+ i = 1;
1499
+ rval += String.fromCharCode(parseInt(hex[0], 16));
1500
+ }
1501
+ // convert 2 characters (1 byte) at a time
1502
+ for(; i < hex.length; i += 2) {
1503
+ rval += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
1504
+ }
1505
+ return rval;
1506
+ };
1507
+
1508
+ /**
1509
+ * Converts a 'binary' encoded string of bytes to hex.
1510
+ *
1511
+ * @param bytes the byte string to convert.
1512
+ *
1513
+ * @return the string of hexadecimal characters.
1514
+ */
1515
+ util.bytesToHex = function(bytes) {
1516
+ // TODO: deprecate: "Deprecated. Use util.binary.hex.encode instead."
1517
+ return util.createBuffer(bytes).toHex();
1518
+ };
1519
+
1520
+ /**
1521
+ * Converts an 32-bit integer to 4-big-endian byte string.
1522
+ *
1523
+ * @param i the integer.
1524
+ *
1525
+ * @return the byte string.
1526
+ */
1527
+ util.int32ToBytes = function(i) {
1528
+ return (
1529
+ String.fromCharCode(i >> 24 & 0xFF) +
1530
+ String.fromCharCode(i >> 16 & 0xFF) +
1531
+ String.fromCharCode(i >> 8 & 0xFF) +
1532
+ String.fromCharCode(i & 0xFF));
1533
+ };
1534
+
1535
+ // base64 characters, reverse mapping
1536
+ var _base64 =
1537
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
1538
+ var _base64Idx = [
1539
+ /*43 -43 = 0*/
1540
+ /*'+', 1, 2, 3,'/' */
1541
+ 62, -1, -1, -1, 63,
1542
+
1543
+ /*'0','1','2','3','4','5','6','7','8','9' */
1544
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
1545
+
1546
+ /*15, 16, 17,'=', 19, 20, 21 */
1547
+ -1, -1, -1, 64, -1, -1, -1,
1548
+
1549
+ /*65 - 43 = 22*/
1550
+ /*'A','B','C','D','E','F','G','H','I','J','K','L','M', */
1551
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1552
+
1553
+ /*'N','O','P','Q','R','S','T','U','V','W','X','Y','Z' */
1554
+ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
1555
+
1556
+ /*91 - 43 = 48 */
1557
+ /*48, 49, 50, 51, 52, 53 */
1558
+ -1, -1, -1, -1, -1, -1,
1559
+
1560
+ /*97 - 43 = 54*/
1561
+ /*'a','b','c','d','e','f','g','h','i','j','k','l','m' */
1562
+ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
1563
+
1564
+ /*'n','o','p','q','r','s','t','u','v','w','x','y','z' */
1565
+ 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
1566
+ ];
1567
+
1568
+ // base58 characters (Bitcoin alphabet)
1569
+ var _base58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
1570
+
1571
+ /**
1572
+ * Base64 encodes a 'binary' encoded string of bytes.
1573
+ *
1574
+ * @param input the binary encoded string of bytes to base64-encode.
1575
+ * @param maxline the maximum number of encoded characters per line to use,
1576
+ * defaults to none.
1577
+ *
1578
+ * @return the base64-encoded output.
1579
+ */
1580
+ util.encode64 = function(input, maxline) {
1581
+ // TODO: deprecate: "Deprecated. Use util.binary.base64.encode instead."
1582
+ var line = '';
1583
+ var output = '';
1584
+ var chr1, chr2, chr3;
1585
+ var i = 0;
1586
+ while(i < input.length) {
1587
+ chr1 = input.charCodeAt(i++);
1588
+ chr2 = input.charCodeAt(i++);
1589
+ chr3 = input.charCodeAt(i++);
1590
+
1591
+ // encode 4 character group
1592
+ line += _base64.charAt(chr1 >> 2);
1593
+ line += _base64.charAt(((chr1 & 3) << 4) | (chr2 >> 4));
1594
+ if(isNaN(chr2)) {
1595
+ line += '==';
1596
+ } else {
1597
+ line += _base64.charAt(((chr2 & 15) << 2) | (chr3 >> 6));
1598
+ line += isNaN(chr3) ? '=' : _base64.charAt(chr3 & 63);
1599
+ }
1600
+
1601
+ if(maxline && line.length > maxline) {
1602
+ output += line.substr(0, maxline) + '\r\n';
1603
+ line = line.substr(maxline);
1604
+ }
1605
+ }
1606
+ output += line;
1607
+ return output;
1608
+ };
1609
+
1610
+ /**
1611
+ * Base64 decodes a string into a 'binary' encoded string of bytes.
1612
+ *
1613
+ * @param input the base64-encoded input.
1614
+ *
1615
+ * @return the binary encoded string.
1616
+ */
1617
+ util.decode64 = function(input) {
1618
+ // TODO: deprecate: "Deprecated. Use util.binary.base64.decode instead."
1619
+
1620
+ // remove all non-base64 characters
1621
+ input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
1622
+
1623
+ var output = '';
1624
+ var enc1, enc2, enc3, enc4;
1625
+ var i = 0;
1626
+
1627
+ while(i < input.length) {
1628
+ enc1 = _base64Idx[input.charCodeAt(i++) - 43];
1629
+ enc2 = _base64Idx[input.charCodeAt(i++) - 43];
1630
+ enc3 = _base64Idx[input.charCodeAt(i++) - 43];
1631
+ enc4 = _base64Idx[input.charCodeAt(i++) - 43];
1632
+
1633
+ output += String.fromCharCode((enc1 << 2) | (enc2 >> 4));
1634
+ if(enc3 !== 64) {
1635
+ // decoded at least 2 bytes
1636
+ output += String.fromCharCode(((enc2 & 15) << 4) | (enc3 >> 2));
1637
+ if(enc4 !== 64) {
1638
+ // decoded 3 bytes
1639
+ output += String.fromCharCode(((enc3 & 3) << 6) | enc4);
1640
+ }
1641
+ }
1642
+ }
1643
+
1644
+ return output;
1645
+ };
1646
+
1647
+ /**
1648
+ * Encodes the given string of characters (a standard JavaScript
1649
+ * string) as a binary encoded string where the bytes represent
1650
+ * a UTF-8 encoded string of characters. Non-ASCII characters will be
1651
+ * encoded as multiple bytes according to UTF-8.
1652
+ *
1653
+ * @param str a standard string of characters to encode.
1654
+ *
1655
+ * @return the binary encoded string.
1656
+ */
1657
+ util.encodeUtf8 = function(str) {
1658
+ return unescape(encodeURIComponent(str));
1659
+ };
1660
+
1661
+ /**
1662
+ * Decodes a binary encoded string that contains bytes that
1663
+ * represent a UTF-8 encoded string of characters -- into a
1664
+ * string of characters (a standard JavaScript string).
1665
+ *
1666
+ * @param str the binary encoded string to decode.
1667
+ *
1668
+ * @return the resulting standard string of characters.
1669
+ */
1670
+ util.decodeUtf8 = function(str) {
1671
+ return decodeURIComponent(escape(str));
1672
+ };
1673
+
1674
+ // binary encoding/decoding tools
1675
+ // FIXME: Experimental. Do not use yet.
1676
+ util.binary = {
1677
+ raw: {},
1678
+ hex: {},
1679
+ base64: {},
1680
+ base58: {},
1681
+ baseN : {
1682
+ encode: baseN.encode,
1683
+ decode: baseN.decode
1684
+ }
1685
+ };
1686
+
1687
+ /**
1688
+ * Encodes a Uint8Array as a binary-encoded string. This encoding uses
1689
+ * a value between 0 and 255 for each character.
1690
+ *
1691
+ * @param bytes the Uint8Array to encode.
1692
+ *
1693
+ * @return the binary-encoded string.
1694
+ */
1695
+ util.binary.raw.encode = function(bytes) {
1696
+ return String.fromCharCode.apply(null, bytes);
1697
+ };
1698
+
1699
+ /**
1700
+ * Decodes a binary-encoded string to a Uint8Array. This encoding uses
1701
+ * a value between 0 and 255 for each character.
1702
+ *
1703
+ * @param str the binary-encoded string to decode.
1704
+ * @param [output] an optional Uint8Array to write the output to; if it
1705
+ * is too small, an exception will be thrown.
1706
+ * @param [offset] the start offset for writing to the output (default: 0).
1707
+ *
1708
+ * @return the Uint8Array or the number of bytes written if output was given.
1709
+ */
1710
+ util.binary.raw.decode = function(str, output, offset) {
1711
+ var out = output;
1712
+ if(!out) {
1713
+ out = new Uint8Array(str.length);
1714
+ }
1715
+ offset = offset || 0;
1716
+ var j = offset;
1717
+ for(var i = 0; i < str.length; ++i) {
1718
+ out[j++] = str.charCodeAt(i);
1719
+ }
1720
+ return output ? (j - offset) : out;
1721
+ };
1722
+
1723
+ /**
1724
+ * Encodes a 'binary' string, ArrayBuffer, DataView, TypedArray, or
1725
+ * ByteBuffer as a string of hexadecimal characters.
1726
+ *
1727
+ * @param bytes the bytes to convert.
1728
+ *
1729
+ * @return the string of hexadecimal characters.
1730
+ */
1731
+ util.binary.hex.encode = util.bytesToHex;
1732
+
1733
+ /**
1734
+ * Decodes a hex-encoded string to a Uint8Array.
1735
+ *
1736
+ * @param hex the hexadecimal string to convert.
1737
+ * @param [output] an optional Uint8Array to write the output to; if it
1738
+ * is too small, an exception will be thrown.
1739
+ * @param [offset] the start offset for writing to the output (default: 0).
1740
+ *
1741
+ * @return the Uint8Array or the number of bytes written if output was given.
1742
+ */
1743
+ util.binary.hex.decode = function(hex, output, offset) {
1744
+ var out = output;
1745
+ if(!out) {
1746
+ out = new Uint8Array(Math.ceil(hex.length / 2));
1747
+ }
1748
+ offset = offset || 0;
1749
+ var i = 0, j = offset;
1750
+ if(hex.length & 1) {
1751
+ // odd number of characters, convert first character alone
1752
+ i = 1;
1753
+ out[j++] = parseInt(hex[0], 16);
1754
+ }
1755
+ // convert 2 characters (1 byte) at a time
1756
+ for(; i < hex.length; i += 2) {
1757
+ out[j++] = parseInt(hex.substr(i, 2), 16);
1758
+ }
1759
+ return output ? (j - offset) : out;
1760
+ };
1761
+
1762
+ /**
1763
+ * Base64-encodes a Uint8Array.
1764
+ *
1765
+ * @param input the Uint8Array to encode.
1766
+ * @param maxline the maximum number of encoded characters per line to use,
1767
+ * defaults to none.
1768
+ *
1769
+ * @return the base64-encoded output string.
1770
+ */
1771
+ util.binary.base64.encode = function(input, maxline) {
1772
+ var line = '';
1773
+ var output = '';
1774
+ var chr1, chr2, chr3;
1775
+ var i = 0;
1776
+ while(i < input.byteLength) {
1777
+ chr1 = input[i++];
1778
+ chr2 = input[i++];
1779
+ chr3 = input[i++];
1780
+
1781
+ // encode 4 character group
1782
+ line += _base64.charAt(chr1 >> 2);
1783
+ line += _base64.charAt(((chr1 & 3) << 4) | (chr2 >> 4));
1784
+ if(isNaN(chr2)) {
1785
+ line += '==';
1786
+ } else {
1787
+ line += _base64.charAt(((chr2 & 15) << 2) | (chr3 >> 6));
1788
+ line += isNaN(chr3) ? '=' : _base64.charAt(chr3 & 63);
1789
+ }
1790
+
1791
+ if(maxline && line.length > maxline) {
1792
+ output += line.substr(0, maxline) + '\r\n';
1793
+ line = line.substr(maxline);
1794
+ }
1795
+ }
1796
+ output += line;
1797
+ return output;
1798
+ };
1799
+
1800
+ /**
1801
+ * Decodes a base64-encoded string to a Uint8Array.
1802
+ *
1803
+ * @param input the base64-encoded input string.
1804
+ * @param [output] an optional Uint8Array to write the output to; if it
1805
+ * is too small, an exception will be thrown.
1806
+ * @param [offset] the start offset for writing to the output (default: 0).
1807
+ *
1808
+ * @return the Uint8Array or the number of bytes written if output was given.
1809
+ */
1810
+ util.binary.base64.decode = function(input, output, offset) {
1811
+ var out = output;
1812
+ if(!out) {
1813
+ out = new Uint8Array(Math.ceil(input.length / 4) * 3);
1814
+ }
1815
+
1816
+ // remove all non-base64 characters
1817
+ input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
1818
+
1819
+ offset = offset || 0;
1820
+ var enc1, enc2, enc3, enc4;
1821
+ var i = 0, j = offset;
1822
+
1823
+ while(i < input.length) {
1824
+ enc1 = _base64Idx[input.charCodeAt(i++) - 43];
1825
+ enc2 = _base64Idx[input.charCodeAt(i++) - 43];
1826
+ enc3 = _base64Idx[input.charCodeAt(i++) - 43];
1827
+ enc4 = _base64Idx[input.charCodeAt(i++) - 43];
1828
+
1829
+ out[j++] = (enc1 << 2) | (enc2 >> 4);
1830
+ if(enc3 !== 64) {
1831
+ // decoded at least 2 bytes
1832
+ out[j++] = ((enc2 & 15) << 4) | (enc3 >> 2);
1833
+ if(enc4 !== 64) {
1834
+ // decoded 3 bytes
1835
+ out[j++] = ((enc3 & 3) << 6) | enc4;
1836
+ }
1837
+ }
1838
+ }
1839
+
1840
+ // make sure result is the exact decoded length
1841
+ return output ? (j - offset) : out.subarray(0, j);
1842
+ };
1843
+
1844
+ // add support for base58 encoding/decoding with Bitcoin alphabet
1845
+ util.binary.base58.encode = function(input, maxline) {
1846
+ return util.binary.baseN.encode(input, _base58, maxline);
1847
+ };
1848
+ util.binary.base58.decode = function(input, maxline) {
1849
+ return util.binary.baseN.decode(input, _base58, maxline);
1850
+ };
1851
+
1852
+ // text encoding/decoding tools
1853
+ // FIXME: Experimental. Do not use yet.
1854
+ util.text = {
1855
+ utf8: {},
1856
+ utf16: {}
1857
+ };
1858
+
1859
+ /**
1860
+ * Encodes the given string as UTF-8 in a Uint8Array.
1861
+ *
1862
+ * @param str the string to encode.
1863
+ * @param [output] an optional Uint8Array to write the output to; if it
1864
+ * is too small, an exception will be thrown.
1865
+ * @param [offset] the start offset for writing to the output (default: 0).
1866
+ *
1867
+ * @return the Uint8Array or the number of bytes written if output was given.
1868
+ */
1869
+ util.text.utf8.encode = function(str, output, offset) {
1870
+ str = util.encodeUtf8(str);
1871
+ var out = output;
1872
+ if(!out) {
1873
+ out = new Uint8Array(str.length);
1874
+ }
1875
+ offset = offset || 0;
1876
+ var j = offset;
1877
+ for(var i = 0; i < str.length; ++i) {
1878
+ out[j++] = str.charCodeAt(i);
1879
+ }
1880
+ return output ? (j - offset) : out;
1881
+ };
1882
+
1883
+ /**
1884
+ * Decodes the UTF-8 contents from a Uint8Array.
1885
+ *
1886
+ * @param bytes the Uint8Array to decode.
1887
+ *
1888
+ * @return the resulting string.
1889
+ */
1890
+ util.text.utf8.decode = function(bytes) {
1891
+ return util.decodeUtf8(String.fromCharCode.apply(null, bytes));
1892
+ };
1893
+
1894
+ /**
1895
+ * Encodes the given string as UTF-16 in a Uint8Array.
1896
+ *
1897
+ * @param str the string to encode.
1898
+ * @param [output] an optional Uint8Array to write the output to; if it
1899
+ * is too small, an exception will be thrown.
1900
+ * @param [offset] the start offset for writing to the output (default: 0).
1901
+ *
1902
+ * @return the Uint8Array or the number of bytes written if output was given.
1903
+ */
1904
+ util.text.utf16.encode = function(str, output, offset) {
1905
+ var out = output;
1906
+ if(!out) {
1907
+ out = new Uint8Array(str.length * 2);
1908
+ }
1909
+ var view = new Uint16Array(out.buffer);
1910
+ offset = offset || 0;
1911
+ var j = offset;
1912
+ var k = offset;
1913
+ for(var i = 0; i < str.length; ++i) {
1914
+ view[k++] = str.charCodeAt(i);
1915
+ j += 2;
1916
+ }
1917
+ return output ? (j - offset) : out;
1918
+ };
1919
+
1920
+ /**
1921
+ * Decodes the UTF-16 contents from a Uint8Array.
1922
+ *
1923
+ * @param bytes the Uint8Array to decode.
1924
+ *
1925
+ * @return the resulting string.
1926
+ */
1927
+ util.text.utf16.decode = function(bytes) {
1928
+ return String.fromCharCode.apply(null, new Uint16Array(bytes.buffer));
1929
+ };
1930
+
1931
+ /**
1932
+ * Deflates the given data using a flash interface.
1933
+ *
1934
+ * @param api the flash interface.
1935
+ * @param bytes the data.
1936
+ * @param raw true to return only raw deflate data, false to include zlib
1937
+ * header and trailer.
1938
+ *
1939
+ * @return the deflated data as a string.
1940
+ */
1941
+ util.deflate = function(api, bytes, raw) {
1942
+ bytes = util.decode64(api.deflate(util.encode64(bytes)).rval);
1943
+
1944
+ // strip zlib header and trailer if necessary
1945
+ if(raw) {
1946
+ // zlib header is 2 bytes (CMF,FLG) where FLG indicates that
1947
+ // there is a 4-byte DICT (alder-32) block before the data if
1948
+ // its 5th bit is set
1949
+ var start = 2;
1950
+ var flg = bytes.charCodeAt(1);
1951
+ if(flg & 0x20) {
1952
+ start = 6;
1953
+ }
1954
+ // zlib trailer is 4 bytes of adler-32
1955
+ bytes = bytes.substring(start, bytes.length - 4);
1956
+ }
1957
+
1958
+ return bytes;
1959
+ };
1960
+
1961
+ /**
1962
+ * Inflates the given data using a flash interface.
1963
+ *
1964
+ * @param api the flash interface.
1965
+ * @param bytes the data.
1966
+ * @param raw true if the incoming data has no zlib header or trailer and is
1967
+ * raw DEFLATE data.
1968
+ *
1969
+ * @return the inflated data as a string, null on error.
1970
+ */
1971
+ util.inflate = function(api, bytes, raw) {
1972
+ // TODO: add zlib header and trailer if necessary/possible
1973
+ var rval = api.inflate(util.encode64(bytes)).rval;
1974
+ return (rval === null) ? null : util.decode64(rval);
1975
+ };
1976
+
1977
+ /**
1978
+ * Sets a storage object.
1979
+ *
1980
+ * @param api the storage interface.
1981
+ * @param id the storage ID to use.
1982
+ * @param obj the storage object, null to remove.
1983
+ */
1984
+ var _setStorageObject = function(api, id, obj) {
1985
+ if(!api) {
1986
+ throw new Error('WebStorage not available.');
1987
+ }
1988
+
1989
+ var rval;
1990
+ if(obj === null) {
1991
+ rval = api.removeItem(id);
1992
+ } else {
1993
+ // json-encode and base64-encode object
1994
+ obj = util.encode64(JSON.stringify(obj));
1995
+ rval = api.setItem(id, obj);
1996
+ }
1997
+
1998
+ // handle potential flash error
1999
+ if(typeof(rval) !== 'undefined' && rval.rval !== true) {
2000
+ var error = new Error(rval.error.message);
2001
+ error.id = rval.error.id;
2002
+ error.name = rval.error.name;
2003
+ throw error;
2004
+ }
2005
+ };
2006
+
2007
+ /**
2008
+ * Gets a storage object.
2009
+ *
2010
+ * @param api the storage interface.
2011
+ * @param id the storage ID to use.
2012
+ *
2013
+ * @return the storage object entry or null if none exists.
2014
+ */
2015
+ var _getStorageObject = function(api, id) {
2016
+ if(!api) {
2017
+ throw new Error('WebStorage not available.');
2018
+ }
2019
+
2020
+ // get the existing entry
2021
+ var rval = api.getItem(id);
2022
+
2023
+ /* Note: We check api.init because we can't do (api == localStorage)
2024
+ on IE because of "Class doesn't support Automation" exception. Only
2025
+ the flash api has an init method so this works too, but we need a
2026
+ better solution in the future. */
2027
+
2028
+ // flash returns item wrapped in an object, handle special case
2029
+ if(api.init) {
2030
+ if(rval.rval === null) {
2031
+ if(rval.error) {
2032
+ var error = new Error(rval.error.message);
2033
+ error.id = rval.error.id;
2034
+ error.name = rval.error.name;
2035
+ throw error;
2036
+ }
2037
+ // no error, but also no item
2038
+ rval = null;
2039
+ } else {
2040
+ rval = rval.rval;
2041
+ }
2042
+ }
2043
+
2044
+ // handle decoding
2045
+ if(rval !== null) {
2046
+ // base64-decode and json-decode data
2047
+ rval = JSON.parse(util.decode64(rval));
2048
+ }
2049
+
2050
+ return rval;
2051
+ };
2052
+
2053
+ /**
2054
+ * Stores an item in local storage.
2055
+ *
2056
+ * @param api the storage interface.
2057
+ * @param id the storage ID to use.
2058
+ * @param key the key for the item.
2059
+ * @param data the data for the item (any javascript object/primitive).
2060
+ */
2061
+ var _setItem = function(api, id, key, data) {
2062
+ // get storage object
2063
+ var obj = _getStorageObject(api, id);
2064
+ if(obj === null) {
2065
+ // create a new storage object
2066
+ obj = {};
2067
+ }
2068
+ // update key
2069
+ obj[key] = data;
2070
+
2071
+ // set storage object
2072
+ _setStorageObject(api, id, obj);
2073
+ };
2074
+
2075
+ /**
2076
+ * Gets an item from local storage.
2077
+ *
2078
+ * @param api the storage interface.
2079
+ * @param id the storage ID to use.
2080
+ * @param key the key for the item.
2081
+ *
2082
+ * @return the item.
2083
+ */
2084
+ var _getItem = function(api, id, key) {
2085
+ // get storage object
2086
+ var rval = _getStorageObject(api, id);
2087
+ if(rval !== null) {
2088
+ // return data at key
2089
+ rval = (key in rval) ? rval[key] : null;
2090
+ }
2091
+
2092
+ return rval;
2093
+ };
2094
+
2095
+ /**
2096
+ * Removes an item from local storage.
2097
+ *
2098
+ * @param api the storage interface.
2099
+ * @param id the storage ID to use.
2100
+ * @param key the key for the item.
2101
+ */
2102
+ var _removeItem = function(api, id, key) {
2103
+ // get storage object
2104
+ var obj = _getStorageObject(api, id);
2105
+ if(obj !== null && key in obj) {
2106
+ // remove key
2107
+ delete obj[key];
2108
+
2109
+ // see if entry has no keys remaining
2110
+ var empty = true;
2111
+ for(var prop in obj) {
2112
+ empty = false;
2113
+ break;
2114
+ }
2115
+ if(empty) {
2116
+ // remove entry entirely if no keys are left
2117
+ obj = null;
2118
+ }
2119
+
2120
+ // set storage object
2121
+ _setStorageObject(api, id, obj);
2122
+ }
2123
+ };
2124
+
2125
+ /**
2126
+ * Clears the local disk storage identified by the given ID.
2127
+ *
2128
+ * @param api the storage interface.
2129
+ * @param id the storage ID to use.
2130
+ */
2131
+ var _clearItems = function(api, id) {
2132
+ _setStorageObject(api, id, null);
2133
+ };
2134
+
2135
+ /**
2136
+ * Calls a storage function.
2137
+ *
2138
+ * @param func the function to call.
2139
+ * @param args the arguments for the function.
2140
+ * @param location the location argument.
2141
+ *
2142
+ * @return the return value from the function.
2143
+ */
2144
+ var _callStorageFunction = function(func, args, location) {
2145
+ var rval = null;
2146
+
2147
+ // default storage types
2148
+ if(typeof(location) === 'undefined') {
2149
+ location = ['web', 'flash'];
2150
+ }
2151
+
2152
+ // apply storage types in order of preference
2153
+ var type;
2154
+ var done = false;
2155
+ var exception = null;
2156
+ for(var idx in location) {
2157
+ type = location[idx];
2158
+ try {
2159
+ if(type === 'flash' || type === 'both') {
2160
+ if(args[0] === null) {
2161
+ throw new Error('Flash local storage not available.');
2162
+ }
2163
+ rval = func.apply(this, args);
2164
+ done = (type === 'flash');
2165
+ }
2166
+ if(type === 'web' || type === 'both') {
2167
+ args[0] = localStorage;
2168
+ rval = func.apply(this, args);
2169
+ done = true;
2170
+ }
2171
+ } catch(ex) {
2172
+ exception = ex;
2173
+ }
2174
+ if(done) {
2175
+ break;
2176
+ }
2177
+ }
2178
+
2179
+ if(!done) {
2180
+ throw exception;
2181
+ }
2182
+
2183
+ return rval;
2184
+ };
2185
+
2186
+ /**
2187
+ * Stores an item on local disk.
2188
+ *
2189
+ * The available types of local storage include 'flash', 'web', and 'both'.
2190
+ *
2191
+ * The type 'flash' refers to flash local storage (SharedObject). In order
2192
+ * to use flash local storage, the 'api' parameter must be valid. The type
2193
+ * 'web' refers to WebStorage, if supported by the browser. The type 'both'
2194
+ * refers to storing using both 'flash' and 'web', not just one or the
2195
+ * other.
2196
+ *
2197
+ * The location array should list the storage types to use in order of
2198
+ * preference:
2199
+ *
2200
+ * ['flash']: flash only storage
2201
+ * ['web']: web only storage
2202
+ * ['both']: try to store in both
2203
+ * ['flash','web']: store in flash first, but if not available, 'web'
2204
+ * ['web','flash']: store in web first, but if not available, 'flash'
2205
+ *
2206
+ * The location array defaults to: ['web', 'flash']
2207
+ *
2208
+ * @param api the flash interface, null to use only WebStorage.
2209
+ * @param id the storage ID to use.
2210
+ * @param key the key for the item.
2211
+ * @param data the data for the item (any javascript object/primitive).
2212
+ * @param location an array with the preferred types of storage to use.
2213
+ */
2214
+ util.setItem = function(api, id, key, data, location) {
2215
+ _callStorageFunction(_setItem, arguments, location);
2216
+ };
2217
+
2218
+ /**
2219
+ * Gets an item on local disk.
2220
+ *
2221
+ * Set setItem() for details on storage types.
2222
+ *
2223
+ * @param api the flash interface, null to use only WebStorage.
2224
+ * @param id the storage ID to use.
2225
+ * @param key the key for the item.
2226
+ * @param location an array with the preferred types of storage to use.
2227
+ *
2228
+ * @return the item.
2229
+ */
2230
+ util.getItem = function(api, id, key, location) {
2231
+ return _callStorageFunction(_getItem, arguments, location);
2232
+ };
2233
+
2234
+ /**
2235
+ * Removes an item on local disk.
2236
+ *
2237
+ * Set setItem() for details on storage types.
2238
+ *
2239
+ * @param api the flash interface.
2240
+ * @param id the storage ID to use.
2241
+ * @param key the key for the item.
2242
+ * @param location an array with the preferred types of storage to use.
2243
+ */
2244
+ util.removeItem = function(api, id, key, location) {
2245
+ _callStorageFunction(_removeItem, arguments, location);
2246
+ };
2247
+
2248
+ /**
2249
+ * Clears the local disk storage identified by the given ID.
2250
+ *
2251
+ * Set setItem() for details on storage types.
2252
+ *
2253
+ * @param api the flash interface if flash is available.
2254
+ * @param id the storage ID to use.
2255
+ * @param location an array with the preferred types of storage to use.
2256
+ */
2257
+ util.clearItems = function(api, id, location) {
2258
+ _callStorageFunction(_clearItems, arguments, location);
2259
+ };
2260
+
2261
+ /**
2262
+ * Check if an object is empty.
2263
+ *
2264
+ * Taken from:
2265
+ * http://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object-from-json/679937#679937
2266
+ *
2267
+ * @param object the object to check.
2268
+ */
2269
+ util.isEmpty = function(obj) {
2270
+ for(var prop in obj) {
2271
+ if(obj.hasOwnProperty(prop)) {
2272
+ return false;
2273
+ }
2274
+ }
2275
+ return true;
2276
+ };
2277
+
2278
+ /**
2279
+ * Format with simple printf-style interpolation.
2280
+ *
2281
+ * %%: literal '%'
2282
+ * %s,%o: convert next argument into a string.
2283
+ *
2284
+ * @param format the string to format.
2285
+ * @param ... arguments to interpolate into the format string.
2286
+ */
2287
+ util.format = function(format) {
2288
+ var re = /%./g;
2289
+ // current match
2290
+ var match;
2291
+ // current part
2292
+ var part;
2293
+ // current arg index
2294
+ var argi = 0;
2295
+ // collected parts to recombine later
2296
+ var parts = [];
2297
+ // last index found
2298
+ var last = 0;
2299
+ // loop while matches remain
2300
+ while((match = re.exec(format))) {
2301
+ part = format.substring(last, re.lastIndex - 2);
2302
+ // don't add empty strings (ie, parts between %s%s)
2303
+ if(part.length > 0) {
2304
+ parts.push(part);
2305
+ }
2306
+ last = re.lastIndex;
2307
+ // switch on % code
2308
+ var code = match[0][1];
2309
+ switch(code) {
2310
+ case 's':
2311
+ case 'o':
2312
+ // check if enough arguments were given
2313
+ if(argi < arguments.length) {
2314
+ parts.push(arguments[argi++ + 1]);
2315
+ } else {
2316
+ parts.push('<?>');
2317
+ }
2318
+ break;
2319
+ // FIXME: do proper formatting for numbers, etc
2320
+ //case 'f':
2321
+ //case 'd':
2322
+ case '%':
2323
+ parts.push('%');
2324
+ break;
2325
+ default:
2326
+ parts.push('<%' + code + '?>');
2327
+ }
2328
+ }
2329
+ // add trailing part of format string
2330
+ parts.push(format.substring(last));
2331
+ return parts.join('');
2332
+ };
2333
+
2334
+ /**
2335
+ * Formats a number.
2336
+ *
2337
+ * http://snipplr.com/view/5945/javascript-numberformat--ported-from-php/
2338
+ */
2339
+ util.formatNumber = function(number, decimals, dec_point, thousands_sep) {
2340
+ // http://kevin.vanzonneveld.net
2341
+ // + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
2342
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
2343
+ // + bugfix by: Michael White (http://crestidg.com)
2344
+ // + bugfix by: Benjamin Lupton
2345
+ // + bugfix by: Allan Jensen (http://www.winternet.no)
2346
+ // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
2347
+ // * example 1: number_format(1234.5678, 2, '.', '');
2348
+ // * returns 1: 1234.57
2349
+
2350
+ var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
2351
+ var d = dec_point === undefined ? ',' : dec_point;
2352
+ var t = thousands_sep === undefined ?
2353
+ '.' : thousands_sep, s = n < 0 ? '-' : '';
2354
+ var i = parseInt((n = Math.abs(+n || 0).toFixed(c)), 10) + '';
2355
+ var j = (i.length > 3) ? i.length % 3 : 0;
2356
+ return s + (j ? i.substr(0, j) + t : '') +
2357
+ i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + t) +
2358
+ (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '');
2359
+ };
2360
+
2361
+ /**
2362
+ * Formats a byte size.
2363
+ *
2364
+ * http://snipplr.com/view/5949/format-humanize-file-byte-size-presentation-in-javascript/
2365
+ */
2366
+ util.formatSize = function(size) {
2367
+ if(size >= 1073741824) {
2368
+ size = util.formatNumber(size / 1073741824, 2, '.', '') + ' GiB';
2369
+ } else if(size >= 1048576) {
2370
+ size = util.formatNumber(size / 1048576, 2, '.', '') + ' MiB';
2371
+ } else if(size >= 1024) {
2372
+ size = util.formatNumber(size / 1024, 0) + ' KiB';
2373
+ } else {
2374
+ size = util.formatNumber(size, 0) + ' bytes';
2375
+ }
2376
+ return size;
2377
+ };
2378
+
2379
+ /**
2380
+ * Converts an IPv4 or IPv6 string representation into bytes (in network order).
2381
+ *
2382
+ * @param ip the IPv4 or IPv6 address to convert.
2383
+ *
2384
+ * @return the 4-byte IPv6 or 16-byte IPv6 address or null if the address can't
2385
+ * be parsed.
2386
+ */
2387
+ util.bytesFromIP = function(ip) {
2388
+ if(ip.indexOf('.') !== -1) {
2389
+ return util.bytesFromIPv4(ip);
2390
+ }
2391
+ if(ip.indexOf(':') !== -1) {
2392
+ return util.bytesFromIPv6(ip);
2393
+ }
2394
+ return null;
2395
+ };
2396
+
2397
+ /**
2398
+ * Converts an IPv4 string representation into bytes (in network order).
2399
+ *
2400
+ * @param ip the IPv4 address to convert.
2401
+ *
2402
+ * @return the 4-byte address or null if the address can't be parsed.
2403
+ */
2404
+ util.bytesFromIPv4 = function(ip) {
2405
+ ip = ip.split('.');
2406
+ if(ip.length !== 4) {
2407
+ return null;
2408
+ }
2409
+ var b = util.createBuffer();
2410
+ for(var i = 0; i < ip.length; ++i) {
2411
+ var num = parseInt(ip[i], 10);
2412
+ if(isNaN(num)) {
2413
+ return null;
2414
+ }
2415
+ b.putByte(num);
2416
+ }
2417
+ return b.getBytes();
2418
+ };
2419
+
2420
+ /**
2421
+ * Converts an IPv6 string representation into bytes (in network order).
2422
+ *
2423
+ * @param ip the IPv6 address to convert.
2424
+ *
2425
+ * @return the 16-byte address or null if the address can't be parsed.
2426
+ */
2427
+ util.bytesFromIPv6 = function(ip) {
2428
+ var blanks = 0;
2429
+ ip = ip.split(':').filter(function(e) {
2430
+ if(e.length === 0) ++blanks;
2431
+ return true;
2432
+ });
2433
+ var zeros = (8 - ip.length + blanks) * 2;
2434
+ var b = util.createBuffer();
2435
+ for(var i = 0; i < 8; ++i) {
2436
+ if(!ip[i] || ip[i].length === 0) {
2437
+ b.fillWithByte(0, zeros);
2438
+ zeros = 0;
2439
+ continue;
2440
+ }
2441
+ var bytes = util.hexToBytes(ip[i]);
2442
+ if(bytes.length < 2) {
2443
+ b.putByte(0);
2444
+ }
2445
+ b.putBytes(bytes);
2446
+ }
2447
+ return b.getBytes();
2448
+ };
2449
+
2450
+ /**
2451
+ * Converts 4-bytes into an IPv4 string representation or 16-bytes into
2452
+ * an IPv6 string representation. The bytes must be in network order.
2453
+ *
2454
+ * @param bytes the bytes to convert.
2455
+ *
2456
+ * @return the IPv4 or IPv6 string representation if 4 or 16 bytes,
2457
+ * respectively, are given, otherwise null.
2458
+ */
2459
+ util.bytesToIP = function(bytes) {
2460
+ if(bytes.length === 4) {
2461
+ return util.bytesToIPv4(bytes);
2462
+ }
2463
+ if(bytes.length === 16) {
2464
+ return util.bytesToIPv6(bytes);
2465
+ }
2466
+ return null;
2467
+ };
2468
+
2469
+ /**
2470
+ * Converts 4-bytes into an IPv4 string representation. The bytes must be
2471
+ * in network order.
2472
+ *
2473
+ * @param bytes the bytes to convert.
2474
+ *
2475
+ * @return the IPv4 string representation or null for an invalid # of bytes.
2476
+ */
2477
+ util.bytesToIPv4 = function(bytes) {
2478
+ if(bytes.length !== 4) {
2479
+ return null;
2480
+ }
2481
+ var ip = [];
2482
+ for(var i = 0; i < bytes.length; ++i) {
2483
+ ip.push(bytes.charCodeAt(i));
2484
+ }
2485
+ return ip.join('.');
2486
+ };
2487
+
2488
+ /**
2489
+ * Converts 16-bytes into an IPv16 string representation. The bytes must be
2490
+ * in network order.
2491
+ *
2492
+ * @param bytes the bytes to convert.
2493
+ *
2494
+ * @return the IPv16 string representation or null for an invalid # of bytes.
2495
+ */
2496
+ util.bytesToIPv6 = function(bytes) {
2497
+ if(bytes.length !== 16) {
2498
+ return null;
2499
+ }
2500
+ var ip = [];
2501
+ var zeroGroups = [];
2502
+ var zeroMaxGroup = 0;
2503
+ for(var i = 0; i < bytes.length; i += 2) {
2504
+ var hex = util.bytesToHex(bytes[i] + bytes[i + 1]);
2505
+ // canonicalize zero representation
2506
+ while(hex[0] === '0' && hex !== '0') {
2507
+ hex = hex.substr(1);
2508
+ }
2509
+ if(hex === '0') {
2510
+ var last = zeroGroups[zeroGroups.length - 1];
2511
+ var idx = ip.length;
2512
+ if(!last || idx !== last.end + 1) {
2513
+ zeroGroups.push({start: idx, end: idx});
2514
+ } else {
2515
+ last.end = idx;
2516
+ if((last.end - last.start) >
2517
+ (zeroGroups[zeroMaxGroup].end - zeroGroups[zeroMaxGroup].start)) {
2518
+ zeroMaxGroup = zeroGroups.length - 1;
2519
+ }
2520
+ }
2521
+ }
2522
+ ip.push(hex);
2523
+ }
2524
+ if(zeroGroups.length > 0) {
2525
+ var group = zeroGroups[zeroMaxGroup];
2526
+ // only shorten group of length > 0
2527
+ if(group.end - group.start > 0) {
2528
+ ip.splice(group.start, group.end - group.start + 1, '');
2529
+ if(group.start === 0) {
2530
+ ip.unshift('');
2531
+ }
2532
+ if(group.end === 7) {
2533
+ ip.push('');
2534
+ }
2535
+ }
2536
+ }
2537
+ return ip.join(':');
2538
+ };
2539
+
2540
+ /**
2541
+ * Estimates the number of processes that can be run concurrently. If
2542
+ * creating Web Workers, keep in mind that the main JavaScript process needs
2543
+ * its own core.
2544
+ *
2545
+ * @param options the options to use:
2546
+ * update true to force an update (not use the cached value).
2547
+ * @param callback(err, max) called once the operation completes.
2548
+ */
2549
+ util.estimateCores = function(options, callback) {
2550
+ if(typeof options === 'function') {
2551
+ callback = options;
2552
+ options = {};
2553
+ }
2554
+ options = options || {};
2555
+ if('cores' in util && !options.update) {
2556
+ return callback(null, util.cores);
2557
+ }
2558
+ if(typeof navigator !== 'undefined' &&
2559
+ 'hardwareConcurrency' in navigator &&
2560
+ navigator.hardwareConcurrency > 0) {
2561
+ util.cores = navigator.hardwareConcurrency;
2562
+ return callback(null, util.cores);
2563
+ }
2564
+ if(typeof Worker === 'undefined') {
2565
+ // workers not available
2566
+ util.cores = 1;
2567
+ return callback(null, util.cores);
2568
+ }
2569
+ if(typeof Blob === 'undefined') {
2570
+ // can't estimate, default to 2
2571
+ util.cores = 2;
2572
+ return callback(null, util.cores);
2573
+ }
2574
+
2575
+ // create worker concurrency estimation code as blob
2576
+ var blobUrl = URL.createObjectURL(new Blob(['(',
2577
+ function() {
2578
+ self.addEventListener('message', function(e) {
2579
+ // run worker for 4 ms
2580
+ var st = Date.now();
2581
+ var et = st + 4;
2582
+ while(Date.now() < et);
2583
+ self.postMessage({st: st, et: et});
2584
+ });
2585
+ }.toString(),
2586
+ ')()'], {type: 'application/javascript'}));
2587
+
2588
+ // take 5 samples using 16 workers
2589
+ sample([], 5, 16);
2590
+
2591
+ function sample(max, samples, numWorkers) {
2592
+ if(samples === 0) {
2593
+ // get overlap average
2594
+ var avg = Math.floor(max.reduce(function(avg, x) {
2595
+ return avg + x;
2596
+ }, 0) / max.length);
2597
+ util.cores = Math.max(1, avg);
2598
+ URL.revokeObjectURL(blobUrl);
2599
+ return callback(null, util.cores);
2600
+ }
2601
+ map(numWorkers, function(err, results) {
2602
+ max.push(reduce(numWorkers, results));
2603
+ sample(max, samples - 1, numWorkers);
2604
+ });
2605
+ }
2606
+
2607
+ function map(numWorkers, callback) {
2608
+ var workers = [];
2609
+ var results = [];
2610
+ for(var i = 0; i < numWorkers; ++i) {
2611
+ var worker = new Worker(blobUrl);
2612
+ worker.addEventListener('message', function(e) {
2613
+ results.push(e.data);
2614
+ if(results.length === numWorkers) {
2615
+ for(var i = 0; i < numWorkers; ++i) {
2616
+ workers[i].terminate();
2617
+ }
2618
+ callback(null, results);
2619
+ }
2620
+ });
2621
+ workers.push(worker);
2622
+ }
2623
+ for(var i = 0; i < numWorkers; ++i) {
2624
+ workers[i].postMessage(i);
2625
+ }
2626
+ }
2627
+
2628
+ function reduce(numWorkers, results) {
2629
+ // find overlapping time windows
2630
+ var overlaps = [];
2631
+ for(var n = 0; n < numWorkers; ++n) {
2632
+ var r1 = results[n];
2633
+ var overlap = overlaps[n] = [];
2634
+ for(var i = 0; i < numWorkers; ++i) {
2635
+ if(n === i) {
2636
+ continue;
2637
+ }
2638
+ var r2 = results[i];
2639
+ if((r1.st > r2.st && r1.st < r2.et) ||
2640
+ (r2.st > r1.st && r2.st < r1.et)) {
2641
+ overlap.push(i);
2642
+ }
2643
+ }
2644
+ }
2645
+ // get maximum overlaps ... don't include overlapping worker itself
2646
+ // as the main JS process was also being scheduled during the work and
2647
+ // would have to be subtracted from the estimate anyway
2648
+ return overlaps.reduce(function(max, overlap) {
2649
+ return Math.max(max, overlap.length);
2650
+ }, 0);
2651
+ }
2652
+ };