@port-labs/jq-node-bindings 0.0.4 → 0.0.6

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 (286) hide show
  1. package/binding.gyp +3 -3
  2. package/configure +8 -6
  3. package/deps/jq/.travis.yml +184 -35
  4. package/deps/jq/AUTHORS +31 -30
  5. package/deps/jq/COPYING +2 -2
  6. package/deps/jq/KEYS +8 -0
  7. package/deps/jq/Makefile.am +85 -70
  8. package/deps/jq/NEWS +5 -4
  9. package/deps/jq/README.md +18 -9
  10. package/deps/jq/appveyor.yml +53 -0
  11. package/deps/jq/compile-ios.sh +5 -5
  12. package/deps/jq/config/m4/check-math-func.m4 +7 -2
  13. package/deps/jq/configure.ac +130 -68
  14. package/deps/jq/docs/Rakefile +14 -135
  15. package/deps/jq/docs/Rakefile.manual +49 -0
  16. package/deps/jq/docs/Rakefile.website +76 -0
  17. package/deps/jq/docs/content/2.download/default.yml +115 -39
  18. package/deps/jq/docs/content/3.manual/manual.yml +641 -231
  19. package/deps/jq/docs/content/3.manual/v1.3/manual.yml +130 -130
  20. package/deps/jq/docs/content/3.manual/v1.4/manual.yml +160 -160
  21. package/deps/jq/docs/content/3.manual/v1.5/manual.yml +2878 -0
  22. package/deps/jq/docs/content/3.manual/v1.6/manual.yml +3287 -0
  23. package/deps/jq/docs/content/index/index.yml +28 -6
  24. package/deps/jq/docs/public/.htaccess +2 -2
  25. package/deps/jq/docs/public/css/base.scss +141 -59
  26. package/deps/jq/docs/public/js/manual-search.js +52 -0
  27. package/deps/jq/docs/site.yml +1 -10
  28. package/deps/jq/docs/templates/default.liquid +10 -10
  29. package/deps/jq/docs/templates/index.liquid +45 -32
  30. package/deps/jq/docs/templates/manual.liquid +67 -90
  31. package/deps/jq/docs/templates/shared/_footer.liquid +10 -5
  32. package/deps/jq/docs/templates/shared/_head.liquid +17 -12
  33. package/deps/jq/docs/templates/shared/_navbar.liquid +27 -0
  34. package/deps/jq/jq.1.prebuilt +523 -139
  35. package/deps/jq/modules/oniguruma/AUTHORS +1 -0
  36. package/deps/jq/modules/oniguruma/CMakeLists.txt +86 -0
  37. package/deps/jq/modules/oniguruma/COPYING +28 -0
  38. package/deps/jq/modules/oniguruma/ChangeLog +0 -0
  39. package/deps/jq/modules/oniguruma/HISTORY +2138 -0
  40. package/deps/jq/modules/oniguruma/Makefile.am +33 -0
  41. package/deps/jq/modules/oniguruma/NEWS +0 -0
  42. package/deps/jq/modules/oniguruma/README +189 -0
  43. package/deps/jq/modules/oniguruma/README.ja +195 -0
  44. package/deps/jq/modules/oniguruma/README.md +203 -0
  45. package/deps/jq/modules/oniguruma/cmake/dist.cmake +321 -0
  46. package/deps/jq/modules/oniguruma/compile +348 -0
  47. package/deps/jq/modules/oniguruma/config.guess +1754 -0
  48. package/deps/jq/modules/oniguruma/config.sub +1890 -0
  49. package/deps/jq/modules/oniguruma/configure.ac +87 -0
  50. package/deps/jq/modules/oniguruma/contributed/libfuzzer-onig.cpp +31 -0
  51. package/deps/jq/modules/oniguruma/depcomp +791 -0
  52. package/deps/jq/modules/oniguruma/dist.info +10 -0
  53. package/deps/jq/modules/oniguruma/doc/API +660 -0
  54. package/deps/jq/modules/oniguruma/doc/API.ja +667 -0
  55. package/deps/jq/modules/oniguruma/doc/FAQ +12 -0
  56. package/deps/jq/modules/oniguruma/doc/FAQ.ja +22 -0
  57. package/deps/jq/modules/oniguruma/doc/RE +436 -0
  58. package/deps/jq/modules/oniguruma/doc/RE.ja +448 -0
  59. package/deps/jq/modules/oniguruma/doc/UNICODE_PROPERTIES +698 -0
  60. package/deps/jq/modules/oniguruma/index.html +181 -0
  61. package/deps/jq/modules/oniguruma/index_ja.html +184 -0
  62. package/deps/jq/modules/oniguruma/install-sh +541 -0
  63. package/deps/jq/modules/oniguruma/m4/.whatever +0 -0
  64. package/deps/jq/modules/oniguruma/make_win32.bat +3 -0
  65. package/deps/jq/modules/oniguruma/make_win64.bat +3 -0
  66. package/deps/jq/modules/oniguruma/missing +215 -0
  67. package/deps/jq/modules/oniguruma/onig-config.in +78 -0
  68. package/deps/jq/modules/oniguruma/oniguruma.pc.cmake.in +13 -0
  69. package/deps/jq/modules/oniguruma/oniguruma.pc.in +14 -0
  70. package/deps/jq/modules/oniguruma/sample/CMakeLists.txt +28 -0
  71. package/deps/jq/modules/oniguruma/sample/Makefile.am +34 -0
  72. package/deps/jq/modules/oniguruma/sample/bug_fix.c +131 -0
  73. package/deps/jq/modules/oniguruma/sample/crnl.c +127 -0
  74. package/deps/jq/modules/oniguruma/sample/encode.c +308 -0
  75. package/deps/jq/modules/oniguruma/sample/listcap.c +110 -0
  76. package/deps/jq/modules/oniguruma/sample/names.c +75 -0
  77. package/deps/jq/modules/oniguruma/sample/posix.c +96 -0
  78. package/deps/jq/modules/oniguruma/sample/scan.c +88 -0
  79. package/deps/jq/modules/oniguruma/sample/simple.c +59 -0
  80. package/deps/jq/modules/oniguruma/sample/sql.c +76 -0
  81. package/deps/jq/modules/oniguruma/sample/syntax.c +76 -0
  82. package/deps/jq/modules/oniguruma/sample/user_property.c +87 -0
  83. package/deps/jq/modules/oniguruma/src/Makefile.am +58 -0
  84. package/deps/jq/modules/oniguruma/src/Makefile.windows +183 -0
  85. package/deps/jq/modules/oniguruma/src/ascii.c +61 -0
  86. package/deps/jq/modules/oniguruma/src/big5.c +190 -0
  87. package/deps/jq/modules/oniguruma/src/config.h.cmake.in +71 -0
  88. package/deps/jq/modules/oniguruma/src/config.h.win32 +84 -0
  89. package/deps/jq/modules/oniguruma/src/config.h.win64 +84 -0
  90. package/deps/jq/modules/oniguruma/src/cp1251.c +203 -0
  91. package/deps/jq/modules/oniguruma/src/euc_jp.c +310 -0
  92. package/deps/jq/modules/oniguruma/src/euc_jp_prop.c +158 -0
  93. package/deps/jq/modules/oniguruma/src/euc_jp_prop.gperf +27 -0
  94. package/deps/jq/modules/oniguruma/src/euc_kr.c +188 -0
  95. package/deps/jq/modules/oniguruma/src/euc_tw.c +171 -0
  96. package/deps/jq/modules/oniguruma/src/gb18030.c +538 -0
  97. package/deps/jq/modules/oniguruma/src/gperf_fold_key_conv.py +67 -0
  98. package/deps/jq/modules/oniguruma/src/gperf_unfold_key_conv.py +55 -0
  99. package/deps/jq/modules/oniguruma/src/iso8859_1.c +275 -0
  100. package/deps/jq/modules/oniguruma/src/iso8859_10.c +242 -0
  101. package/deps/jq/modules/oniguruma/src/iso8859_11.c +99 -0
  102. package/deps/jq/modules/oniguruma/src/iso8859_13.c +231 -0
  103. package/deps/jq/modules/oniguruma/src/iso8859_14.c +244 -0
  104. package/deps/jq/modules/oniguruma/src/iso8859_15.c +238 -0
  105. package/deps/jq/modules/oniguruma/src/iso8859_16.c +240 -0
  106. package/deps/jq/modules/oniguruma/src/iso8859_2.c +238 -0
  107. package/deps/jq/modules/oniguruma/src/iso8859_3.c +238 -0
  108. package/deps/jq/modules/oniguruma/src/iso8859_4.c +240 -0
  109. package/deps/jq/modules/oniguruma/src/iso8859_5.c +229 -0
  110. package/deps/jq/modules/oniguruma/src/iso8859_6.c +99 -0
  111. package/deps/jq/modules/oniguruma/src/iso8859_7.c +225 -0
  112. package/deps/jq/modules/oniguruma/src/iso8859_8.c +99 -0
  113. package/deps/jq/modules/oniguruma/src/iso8859_9.c +231 -0
  114. package/deps/jq/modules/oniguruma/src/koi8.c +253 -0
  115. package/deps/jq/modules/oniguruma/src/koi8_r.c +215 -0
  116. package/deps/jq/modules/oniguruma/src/make_unicode_fold.sh +22 -0
  117. package/deps/jq/modules/oniguruma/src/make_unicode_fold_data.py +306 -0
  118. package/deps/jq/modules/oniguruma/src/make_unicode_property.sh +18 -0
  119. package/deps/jq/modules/oniguruma/src/make_unicode_property_data.py +545 -0
  120. package/deps/jq/modules/oniguruma/src/mktable.c +1184 -0
  121. package/deps/jq/modules/oniguruma/src/onig_init.c +45 -0
  122. package/deps/jq/modules/oniguruma/src/oniggnu.h +85 -0
  123. package/deps/jq/modules/oniguruma/src/onigposix.h +169 -0
  124. package/deps/jq/modules/oniguruma/src/oniguruma.h +841 -0
  125. package/deps/jq/modules/oniguruma/src/regcomp.c +6300 -0
  126. package/deps/jq/modules/oniguruma/src/regenc.c +917 -0
  127. package/deps/jq/modules/oniguruma/src/regenc.h +243 -0
  128. package/deps/jq/modules/oniguruma/src/regerror.c +393 -0
  129. package/deps/jq/modules/oniguruma/src/regexec.c +3856 -0
  130. package/deps/jq/modules/oniguruma/src/regext.c +202 -0
  131. package/deps/jq/modules/oniguruma/src/reggnu.c +147 -0
  132. package/deps/jq/modules/oniguruma/src/regint.h +779 -0
  133. package/deps/jq/modules/oniguruma/src/regparse.c +5403 -0
  134. package/deps/jq/modules/oniguruma/src/regparse.h +351 -0
  135. package/deps/jq/modules/oniguruma/src/regposerr.c +105 -0
  136. package/deps/jq/modules/oniguruma/src/regposix.c +306 -0
  137. package/deps/jq/modules/oniguruma/src/regsyntax.c +315 -0
  138. package/deps/jq/modules/oniguruma/src/regtrav.c +76 -0
  139. package/deps/jq/modules/oniguruma/src/regversion.c +57 -0
  140. package/deps/jq/modules/oniguruma/src/sjis.c +341 -0
  141. package/deps/jq/modules/oniguruma/src/sjis_prop.c +158 -0
  142. package/deps/jq/modules/oniguruma/src/sjis_prop.gperf +27 -0
  143. package/deps/jq/modules/oniguruma/src/st.c +589 -0
  144. package/deps/jq/modules/oniguruma/src/st.h +68 -0
  145. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold1_key.c +2250 -0
  146. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold2_key.c +203 -0
  147. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold3_key.c +113 -0
  148. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_fold_data.c +1225 -0
  149. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data.c +24742 -0
  150. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_property_data_posix.c +4846 -0
  151. package/deps/jq/modules/oniguruma/src/unicode-7.0/unicode_unfold_key.c +2571 -0
  152. package/deps/jq/modules/oniguruma/src/unicode.c +664 -0
  153. package/deps/jq/modules/oniguruma/src/unicode_fold1_key.c +2548 -0
  154. package/deps/jq/modules/oniguruma/src/unicode_fold2_key.c +203 -0
  155. package/deps/jq/modules/oniguruma/src/unicode_fold3_key.c +113 -0
  156. package/deps/jq/modules/oniguruma/src/unicode_fold_data.c +1366 -0
  157. package/deps/jq/modules/oniguruma/src/unicode_property_data.c +25306 -0
  158. package/deps/jq/modules/oniguruma/src/unicode_property_data_posix.c +4940 -0
  159. package/deps/jq/modules/oniguruma/src/unicode_unfold_key.c +2854 -0
  160. package/deps/jq/modules/oniguruma/src/utf16_be.c +235 -0
  161. package/deps/jq/modules/oniguruma/src/utf16_le.c +245 -0
  162. package/deps/jq/modules/oniguruma/src/utf32_be.c +194 -0
  163. package/deps/jq/modules/oniguruma/src/utf32_le.c +194 -0
  164. package/deps/jq/modules/oniguruma/src/utf8.c +335 -0
  165. package/deps/jq/modules/oniguruma/test/Makefile.am +28 -0
  166. package/deps/jq/modules/oniguruma/test/testc.c +874 -0
  167. package/deps/jq/modules/oniguruma/test/testu.c +916 -0
  168. package/deps/jq/modules/oniguruma/test-driver +153 -0
  169. package/deps/jq/modules/oniguruma/windows/testc.c +869 -0
  170. package/deps/jq/scripts/crosscompile +2 -1
  171. package/deps/jq/scripts/gen_utf8_tables.py +2 -3
  172. package/deps/jq/scripts/update-website +29 -0
  173. package/deps/jq/scripts/version +7 -2
  174. package/deps/jq/sig/jq-release.key +41 -0
  175. package/deps/jq/sig/v1.3/jq-linux-x86.asc +17 -0
  176. package/deps/jq/sig/v1.3/jq-linux-x86_64.asc +17 -0
  177. package/deps/jq/sig/v1.3/jq-osx-x86.asc +17 -0
  178. package/deps/jq/sig/v1.3/jq-osx-x86_64.asc +17 -0
  179. package/deps/jq/sig/v1.3/jq-win32.exe.asc +17 -0
  180. package/deps/jq/sig/v1.3/jq-win64.exe.asc +17 -0
  181. package/deps/jq/sig/v1.3/sha256sum.txt +6 -0
  182. package/deps/jq/sig/v1.4/jq-linux-x86.asc +17 -0
  183. package/deps/jq/sig/v1.4/jq-linux-x86_64.asc +17 -0
  184. package/deps/jq/sig/v1.4/jq-osx-x86.asc +17 -0
  185. package/deps/jq/sig/v1.4/jq-osx-x86_64.asc +17 -0
  186. package/deps/jq/sig/v1.4/jq-solaris11-32.asc +17 -0
  187. package/deps/jq/sig/v1.4/jq-solaris11-64.asc +17 -0
  188. package/deps/jq/sig/v1.4/jq-win32.exe.asc +17 -0
  189. package/deps/jq/sig/v1.4/jq-win64.exe.asc +17 -0
  190. package/deps/jq/sig/v1.4/sha256sum.txt +8 -0
  191. package/deps/jq/sig/v1.5/jq-linux32-no-oniguruma.asc +17 -0
  192. package/deps/jq/sig/v1.5/jq-linux32.asc +17 -0
  193. package/deps/jq/sig/v1.5/jq-linux64.asc +17 -0
  194. package/deps/jq/sig/v1.5/jq-osx-amd64.asc +17 -0
  195. package/deps/jq/sig/v1.5/jq-win32.exe.asc +17 -0
  196. package/deps/jq/sig/v1.5/jq-win64.exe.asc +17 -0
  197. package/deps/jq/sig/v1.5/sha256sum.txt +5 -0
  198. package/deps/jq/sig/v1.5rc1/jq-linux-x86_64-static.asc +17 -0
  199. package/deps/jq/sig/v1.5rc1/jq-win32.exe.asc +17 -0
  200. package/deps/jq/sig/v1.5rc1/jq-win64.exe.asc +17 -0
  201. package/deps/jq/sig/v1.5rc1/sha256sum.txt +3 -0
  202. package/deps/jq/sig/v1.5rc2/jq-linux-x86.asc +17 -0
  203. package/deps/jq/sig/v1.5rc2/jq-linux-x86_64.asc +17 -0
  204. package/deps/jq/sig/v1.5rc2/jq-osx-x86_64.asc +17 -0
  205. package/deps/jq/sig/v1.5rc2/jq-win32.exe.asc +17 -0
  206. package/deps/jq/sig/v1.5rc2/jq-win64.exe.asc +17 -0
  207. package/deps/jq/sig/v1.5rc2/sha256sum.txt +5 -0
  208. package/deps/jq/sig/v1.6/jq-linux32.asc +16 -0
  209. package/deps/jq/sig/v1.6/jq-linux64.asc +16 -0
  210. package/deps/jq/sig/v1.6/jq-osx-amd64.asc +16 -0
  211. package/deps/jq/sig/v1.6/jq-win32.exe.asc +16 -0
  212. package/deps/jq/sig/v1.6/jq-win64.exe.asc +16 -0
  213. package/deps/jq/sig/v1.6/sha256sum.txt +5 -0
  214. package/deps/jq/{builtin.c → src/builtin.c} +449 -344
  215. package/deps/jq/{builtin.h → src/builtin.h} +0 -0
  216. package/deps/jq/src/builtin.jq +311 -0
  217. package/deps/jq/{bytecode.c → src/bytecode.c} +0 -0
  218. package/deps/jq/{bytecode.h → src/bytecode.h} +0 -0
  219. package/deps/jq/{compile.c → src/compile.c} +213 -37
  220. package/deps/jq/{compile.h → src/compile.h} +7 -2
  221. package/deps/jq/{exec_stack.h → src/exec_stack.h} +0 -0
  222. package/deps/jq/{execute.c → src/execute.c} +127 -24
  223. package/deps/jq/{inject_errors.c → src/inject_errors.c} +0 -0
  224. package/deps/jq/{jq.h → src/jq.h} +13 -2
  225. package/deps/jq/{jq_parser.h → src/jq_parser.h} +0 -0
  226. package/deps/jq/{jq_test.c → src/jq_test.c} +1 -1
  227. package/deps/jq/{jv.c → src/jv.c} +24 -5
  228. package/deps/jq/{jv.h → src/jv.h} +46 -11
  229. package/deps/jq/{jv_alloc.c → src/jv_alloc.c} +0 -0
  230. package/deps/jq/{jv_alloc.h → src/jv_alloc.h} +0 -0
  231. package/deps/jq/{jv_aux.c → src/jv_aux.c} +38 -14
  232. package/deps/jq/{jv_dtoa.c → src/jv_dtoa.c} +4 -5
  233. package/deps/jq/{jv_dtoa.h → src/jv_dtoa.h} +0 -0
  234. package/deps/jq/src/jv_file.c +81 -0
  235. package/deps/jq/{jv_parse.c → src/jv_parse.c} +8 -2
  236. package/deps/jq/{jv_print.c → src/jv_print.c} +80 -27
  237. package/deps/jq/{jv_unicode.c → src/jv_unicode.c} +28 -4
  238. package/deps/jq/{jv_unicode.h → src/jv_unicode.h} +1 -0
  239. package/deps/jq/{jv_utf8_tables.h → src/jv_utf8_tables.h} +0 -0
  240. package/deps/jq/{lexer.c → src/lexer.c} +317 -292
  241. package/deps/jq/{lexer.h → src/lexer.h} +16 -12
  242. package/deps/jq/{lexer.l → src/lexer.l} +5 -4
  243. package/deps/jq/src/libm.h +291 -0
  244. package/deps/jq/{linker.c → src/linker.c} +5 -3
  245. package/deps/jq/{linker.h → src/linker.h} +0 -0
  246. package/deps/jq/{locfile.c → src/locfile.c} +1 -1
  247. package/deps/jq/{locfile.h → src/locfile.h} +0 -0
  248. package/deps/jq/{main.c → src/main.c} +202 -100
  249. package/deps/jq/{opcode_list.h → src/opcode_list.h} +4 -0
  250. package/deps/jq/{parser.c → src/parser.c} +1149 -1069
  251. package/deps/jq/{parser.h → src/parser.h} +28 -24
  252. package/deps/jq/{parser.y → src/parser.y} +108 -52
  253. package/deps/jq/{util.c → src/util.c} +12 -9
  254. package/deps/jq/{util.h → src/util.h} +0 -0
  255. package/deps/jq/tests/base64.test +35 -0
  256. package/deps/jq/tests/base64test +5 -0
  257. package/deps/jq/tests/jq-f-test.sh +4 -0
  258. package/deps/jq/tests/jq.test +305 -21
  259. package/deps/jq/tests/jqtest +1 -1
  260. package/deps/jq/tests/mantest +1 -1
  261. package/deps/jq/tests/onig.test +13 -0
  262. package/deps/jq/tests/onigtest +1 -1
  263. package/deps/jq/tests/optional.test +20 -0
  264. package/deps/jq/tests/optionaltest +5 -0
  265. package/deps/jq/tests/setup +7 -1
  266. package/deps/jq/tests/shtest +133 -29
  267. package/deps/jq/tests/utf8-truncate.jq +3 -0
  268. package/deps/jq/tests/utf8test +10 -0
  269. package/lib/index.js +7 -1
  270. package/package.json +3 -3
  271. package/test/santiy.test.js +24 -0
  272. package/deps/jq/docs/default_manpage.md +0 -22
  273. package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.css +0 -1058
  274. package/deps/jq/docs/public/bootstrap/css/bootstrap-responsive.min.css +0 -9
  275. package/deps/jq/docs/public/bootstrap/css/bootstrap.css +0 -5224
  276. package/deps/jq/docs/public/bootstrap/css/bootstrap.min.css +0 -9
  277. package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings-white.png +0 -0
  278. package/deps/jq/docs/public/bootstrap/img/glyphicons-halflings.png +0 -0
  279. package/deps/jq/docs/public/bootstrap/js/bootstrap.js +0 -2027
  280. package/deps/jq/docs/public/bootstrap/js/bootstrap.min.js +0 -6
  281. package/deps/jq/docs/templates/shared/_header.liquid +0 -26
  282. package/deps/jq/jq.1.default +0 -39
  283. package/deps/jq/jv_file.c +0 -49
  284. package/deps/jq/libm.h +0 -160
  285. package/deps/jq/setup.sh +0 -33
  286. package/reports/jest-port-api.xml +0 -35
File without changes
@@ -0,0 +1,311 @@
1
+ def halt_error: halt_error(5);
2
+ def error: error(.);
3
+ def map(f): [.[] | f];
4
+ def select(f): if f then . else empty end;
5
+ def sort_by(f): _sort_by_impl(map([f]));
6
+ def group_by(f): _group_by_impl(map([f]));
7
+ def unique: group_by(.) | map(.[0]);
8
+ def unique_by(f): group_by(f) | map(.[0]);
9
+ def max_by(f): _max_by_impl(map([f]));
10
+ def min_by(f): _min_by_impl(map([f]));
11
+ def add: reduce .[] as $x (null; . + $x);
12
+ def del(f): delpaths([path(f)]);
13
+ def _assign(paths; value): value as $v | reduce path(paths) as $p (.; setpath($p; $v));
14
+ def _modify(paths; update): reduce path(paths) as $p (.; label $out | (setpath($p; getpath($p) | update) | ., break $out), delpaths([$p]));
15
+ def map_values(f): .[] |= f;
16
+
17
+ # recurse
18
+ def recurse(f): def r: ., (f | r); r;
19
+ def recurse(f; cond): def r: ., (f | select(cond) | r); r;
20
+ def recurse: recurse(.[]?);
21
+ def recurse_down: recurse;
22
+
23
+ def to_entries: [keys_unsorted[] as $k | {key: $k, value: .[$k]}];
24
+ def from_entries: map({(.key // .Key // .name // .Name): (if has("value") then .value else .Value end)}) | add | .//={};
25
+ def with_entries(f): to_entries | map(f) | from_entries;
26
+ def reverse: [.[length - 1 - range(0;length)]];
27
+ def indices($i): if type == "array" and ($i|type) == "array" then .[$i]
28
+ elif type == "array" then .[[$i]]
29
+ elif type == "string" and ($i|type) == "string" then _strindices($i)
30
+ else .[$i] end;
31
+ def index($i): indices($i) | .[0]; # TODO: optimize
32
+ def rindex($i): indices($i) | .[-1:][0]; # TODO: optimize
33
+ def paths: path(recurse(if (type|. == "array" or . == "object") then .[] else empty end))|select(length > 0);
34
+ def paths(node_filter): . as $dot|paths|select(. as $p|$dot|getpath($p)|node_filter);
35
+ def any(generator; condition):
36
+ [label $out | foreach generator as $i
37
+ (false;
38
+ if . then break $out elif $i | condition then true else . end;
39
+ if . then . else empty end)] | length == 1;
40
+ def any(condition): any(.[]; condition);
41
+ def any: any(.);
42
+ def all(generator; condition):
43
+ [label $out | foreach generator as $i
44
+ (true;
45
+ if .|not then break $out elif $i | condition then . else false end;
46
+ if .|not then . else empty end)] | length == 0;
47
+ def all(condition): all(.[]; condition);
48
+ def all: all(.);
49
+ def isfinite: type == "number" and (isinfinite | not);
50
+ def arrays: select(type == "array");
51
+ def objects: select(type == "object");
52
+ def iterables: arrays, objects;
53
+ def booleans: select(type == "boolean");
54
+ def numbers: select(type == "number");
55
+ def normals: select(isnormal);
56
+ def finites: select(isfinite);
57
+ def strings: select(type == "string");
58
+ def nulls: select(type == "null");
59
+ def values: select(. != null);
60
+ def scalars: select(. == null or . == true or . == false or type == "number" or type == "string");
61
+ def scalars_or_empty: select(. == null or . == true or . == false or type == "number" or type == "string" or ((type=="array" or type=="object") and length==0));
62
+ def leaf_paths: paths(scalars);
63
+ def join($x): reduce .[] as $i (null;
64
+ (if .==null then "" else .+$x end) +
65
+ ($i | if type=="boolean" or type=="number" then tostring else .//"" end)
66
+ ) // "";
67
+ def _flatten($x): reduce .[] as $i ([]; if $i | type == "array" and $x != 0 then . + ($i | _flatten($x-1)) else . + [$i] end);
68
+ def flatten($x): if $x < 0 then error("flatten depth must not be negative") else _flatten($x) end;
69
+ def flatten: _flatten(-1);
70
+ def range($x): range(0;$x);
71
+ def fromdateiso8601: strptime("%Y-%m-%dT%H:%M:%SZ")|mktime;
72
+ def todateiso8601: strftime("%Y-%m-%dT%H:%M:%SZ");
73
+ def fromdate: fromdateiso8601;
74
+ def todate: todateiso8601;
75
+ def match(re; mode): _match_impl(re; mode; false)|.[];
76
+ def match($val): ($val|type) as $vt | if $vt == "string" then match($val; null)
77
+ elif $vt == "array" and ($val | length) > 1 then match($val[0]; $val[1])
78
+ elif $vt == "array" and ($val | length) > 0 then match($val[0]; null)
79
+ else error( $vt + " not a string or array") end;
80
+ def test(re; mode): _match_impl(re; mode; true);
81
+ def test($val): ($val|type) as $vt | if $vt == "string" then test($val; null)
82
+ elif $vt == "array" and ($val | length) > 1 then test($val[0]; $val[1])
83
+ elif $vt == "array" and ($val | length) > 0 then test($val[0]; null)
84
+ else error( $vt + " not a string or array") end;
85
+ def capture(re; mods): match(re; mods) | reduce ( .captures | .[] | select(.name != null) | { (.name) : .string } ) as $pair ({}; . + $pair);
86
+ def capture($val): ($val|type) as $vt | if $vt == "string" then capture($val; null)
87
+ elif $vt == "array" and ($val | length) > 1 then capture($val[0]; $val[1])
88
+ elif $vt == "array" and ($val | length) > 0 then capture($val[0]; null)
89
+ else error( $vt + " not a string or array") end;
90
+ def scan(re):
91
+ match(re; "g")
92
+ | if (.captures|length > 0)
93
+ then [ .captures | .[] | .string ]
94
+ else .string
95
+ end ;
96
+ #
97
+ # If input is an array, then emit a stream of successive subarrays of length n (or less),
98
+ # and similarly for strings.
99
+ def _nwise(a; $n): if a|length <= $n then a else a[0:$n] , _nwise(a[$n:]; $n) end;
100
+ def _nwise($n): _nwise(.; $n);
101
+ #
102
+ # splits/1 produces a stream; split/1 is retained for backward compatibility.
103
+ def splits($re; flags): . as $s
104
+ # # multiple occurrences of "g" are acceptable
105
+ | [ match($re; "g" + flags) | (.offset, .offset + .length) ]
106
+ | [0] + . +[$s|length]
107
+ | _nwise(2)
108
+ | $s[.[0]:.[1] ] ;
109
+ def splits($re): splits($re; null);
110
+ #
111
+ # split emits an array for backward compatibility
112
+ def split($re; flags): [ splits($re; flags) ];
113
+ #
114
+ # If s contains capture variables, then create a capture object and pipe it to s
115
+ def sub($re; s):
116
+ . as $in
117
+ | [match($re)]
118
+ | if length == 0 then $in
119
+ else .[0]
120
+ | . as $r
121
+ # # create the "capture" object:
122
+ | reduce ( $r | .captures | .[] | select(.name != null) | { (.name) : .string } ) as $pair
123
+ ({}; . + $pair)
124
+ | $in[0:$r.offset] + s + $in[$r.offset+$r.length:]
125
+ end ;
126
+ #
127
+ # If s contains capture variables, then create a capture object and pipe it to s
128
+ def sub($re; s; flags):
129
+ def subg: [explode[] | select(. != 103)] | implode;
130
+ # "fla" should be flags with all occurrences of g removed; gs should be non-nil if flags has a g
131
+ def sub1(fla; gs):
132
+ def mysub:
133
+ . as $in
134
+ | [match($re; fla)]
135
+ | if length == 0 then $in
136
+ else .[0] as $edit
137
+ | ($edit | .offset + .length) as $len
138
+ # create the "capture" object:
139
+ | reduce ( $edit | .captures | .[] | select(.name != null) | { (.name) : .string } ) as $pair
140
+ ({}; . + $pair)
141
+ | $in[0:$edit.offset]
142
+ + s
143
+ + ($in[$len:] | if length > 0 and gs then mysub else . end)
144
+ end ;
145
+ mysub ;
146
+ (flags | index("g")) as $gs
147
+ | (flags | if $gs then subg else . end) as $fla
148
+ | sub1($fla; $gs);
149
+ #
150
+ def sub($re; s): sub($re; s; "");
151
+ # repeated substitution of re (which may contain named captures)
152
+ def gsub($re; s; flags): sub($re; s; flags + "g");
153
+ def gsub($re; s): sub($re; s; "g");
154
+
155
+ ########################################################################
156
+ # range/3, with a `by` expression argument
157
+ def range($init; $upto; $by):
158
+ def _range:
159
+ if ($by > 0 and . < $upto) or ($by < 0 and . > $upto) then ., ((.+$by)|_range) else . end;
160
+ if $by == 0 then $init else $init|_range end | select(($by > 0 and . < $upto) or ($by < 0 and . > $upto));
161
+ # generic iterator/generator
162
+ def while(cond; update):
163
+ def _while:
164
+ if cond then ., (update | _while) else empty end;
165
+ _while;
166
+ def until(cond; next):
167
+ def _until:
168
+ if cond then . else (next|_until) end;
169
+ _until;
170
+ def limit($n; exp):
171
+ if $n < 0 then exp
172
+ else label $out | foreach exp as $item ($n; .-1; $item, if . <= 0 then break $out else empty end)
173
+ end;
174
+ def isempty(g): 0 == ((label $go | g | (1, break $go)) // 0);
175
+ def first(g): label $out | g | ., break $out;
176
+ def last(g): reduce g as $item (null; $item);
177
+ def nth($n; g): if $n < 0 then error("nth doesn't support negative indices") else last(limit($n + 1; g)) end;
178
+ def first: .[0];
179
+ def last: .[-1];
180
+ def nth($n): .[$n];
181
+ def combinations:
182
+ if length == 0 then [] else
183
+ .[0][] as $x
184
+ | (.[1:] | combinations) as $y
185
+ | [$x] + $y
186
+ end;
187
+ def combinations(n):
188
+ . as $dot
189
+ | [range(n) | $dot]
190
+ | combinations;
191
+ # transpose a possibly jagged matrix, quickly;
192
+ # rows are padded with nulls so the result is always rectangular.
193
+ def transpose:
194
+ if . == [] then []
195
+ else . as $in
196
+ | (map(length) | max) as $max
197
+ | length as $length
198
+ | reduce range(0; $max) as $j
199
+ ([]; . + [reduce range(0;$length) as $i ([]; . + [ $in[$i][$j] ] )] )
200
+ end;
201
+ def in(xs): . as $x | xs | has($x);
202
+ def inside(xs): . as $x | xs | contains($x);
203
+ def input: _input;
204
+ def repeat(exp):
205
+ def _repeat:
206
+ exp, _repeat;
207
+ _repeat;
208
+ def inputs: try repeat(_input) catch if .=="break" then empty else .|error end;
209
+ # like ruby's downcase - only characters A to Z are affected
210
+ def ascii_downcase:
211
+ explode | map( if 65 <= . and . <= 90 then . + 32 else . end) | implode;
212
+ # like ruby's upcase - only characters a to z are affected
213
+ def ascii_upcase:
214
+ explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode;
215
+
216
+ # Streaming utilities
217
+ def truncate_stream(stream):
218
+ . as $n | null | stream | . as $input | if (.[0]|length) > $n then setpath([0];$input[0][$n:]) else empty end;
219
+ def fromstream(i):
220
+ foreach i as $item (
221
+ [null,false,null,false];
222
+ if ($item[0]|length) == 0 then [null,false,.[2],.[3]]
223
+ elif ($item|length) == 1 and ($item[0]|length) < 2 then [null,false,.[0],.[1]]
224
+ else . end |
225
+ . as $state |
226
+ if ($item|length) > 1 and ($item[0]|length) > 0 then
227
+ [.[0]|setpath(($item|.[0]); ($item|.[1])),
228
+ true,
229
+ $state[2],
230
+ $state[3]]
231
+ else .
232
+ end;
233
+ if ($item[0]|length) == 1 and ($item|length == 1) and .[3] then .[2] else empty end,
234
+ if ($item[0]|length) == 0 then $item[1] else empty end
235
+ );
236
+ def tostream:
237
+ {string:true,number:true,boolean:true,null:true} as $leaf_types |
238
+ . as $dot |
239
+ if $leaf_types[$dot|type] or length==0 then [[],$dot]
240
+ else
241
+ # We really need a _streaming_ form of `keys`.
242
+ # We can use `range` for arrays, but not for objects.
243
+ keys_unsorted as $keys |
244
+ $keys[-1] as $last|
245
+ ((# for each key
246
+ $keys[] | . as $key |
247
+ $dot[$key] | . as $dot |
248
+ # recurse on each key/value
249
+ tostream|.[0]|=[$key]+.),
250
+ # then add the closing marker
251
+ [[$last]])
252
+ end;
253
+
254
+
255
+ # Assuming the input array is sorted, bsearch/1 returns
256
+ # the index of the target if the target is in the input array; and otherwise
257
+ # (-1 - ix), where ix is the insertion point that would leave the array sorted.
258
+ # If the input is not sorted, bsearch will terminate but with irrelevant results.
259
+ def bsearch(target):
260
+ if length == 0 then -1
261
+ elif length == 1 then
262
+ if target == .[0] then 0 elif target < .[0] then -1 else -2 end
263
+ else . as $in
264
+ # state variable: [start, end, answer]
265
+ # where start and end are the upper and lower offsets to use.
266
+ | [0, length-1, null]
267
+ | until( .[0] > .[1] ;
268
+ if .[2] != null then (.[1] = -1) # i.e. break
269
+ else
270
+ ( ( (.[1] + .[0]) / 2 ) | floor ) as $mid
271
+ | $in[$mid] as $monkey
272
+ | if $monkey == target then (.[2] = $mid) # success
273
+ elif .[0] == .[1] then (.[1] = -1) # failure
274
+ elif $monkey < target then (.[0] = ($mid + 1))
275
+ else (.[1] = ($mid - 1))
276
+ end
277
+ end )
278
+ | if .[2] == null then # compute the insertion point
279
+ if $in[ .[0] ] < target then (-2 -.[0])
280
+ else (-1 -.[0])
281
+ end
282
+ else .[2]
283
+ end
284
+ end;
285
+
286
+ # Apply f to composite entities recursively, and to atoms
287
+ def walk(f):
288
+ . as $in
289
+ | if type == "object" then
290
+ reduce keys_unsorted[] as $key
291
+ ( {}; . + { ($key): ($in[$key] | walk(f)) } ) | f
292
+ elif type == "array" then map( walk(f) ) | f
293
+ else f
294
+ end;
295
+
296
+ # SQL-ish operators here:
297
+ def INDEX(stream; idx_expr):
298
+ reduce stream as $row ({};
299
+ .[$row|idx_expr|
300
+ if type != "string" then tojson
301
+ else .
302
+ end] |= $row);
303
+ def INDEX(idx_expr): INDEX(.[]; idx_expr);
304
+ def JOIN($idx; idx_expr):
305
+ [.[] | [., $idx[idx_expr]]];
306
+ def JOIN($idx; stream; idx_expr):
307
+ stream | [., $idx[idx_expr]];
308
+ def JOIN($idx; stream; idx_expr; join_expr):
309
+ stream | [., $idx[idx_expr]] | join_expr;
310
+ def IN(s): reduce (first(select(. == s)) | true) as $v (false; if . or $v then true else false end);
311
+ def IN(src; s): reduce (src|IN(s)) as $v (false; if . or $v then true else false end);
File without changes
File without changes