nadesiko3 3.3.49 → 3.3.50

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 (342) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +143 -143
  3. package/batch/.DS_Store +0 -0
  4. package/batch/browsers.template.md +3 -3
  5. package/batch/build_browsers.nako3 +72 -72
  6. package/batch/build_command.nako3 +44 -44
  7. package/batch/build_nako_version.nako3 +42 -42
  8. package/batch/calc_hash.nako3 +29 -29
  9. package/batch/cmd_txt2json.nako3 +74 -74
  10. package/batch/command.txt +79 -0
  11. package/batch/command_nakopad.txt +69 -0
  12. package/batch/download-extlib.nako3 +43 -43
  13. package/batch/gen_command_nakopad.nako3 +57 -57
  14. package/batch/jsplugin2text.nako3 +285 -285
  15. package/batch/pickup_command.nako3 +110 -110
  16. package/batch/pickup_reserved_words.nako3 +11 -11
  17. package/batch/publish_version.nako3 +46 -46
  18. package/batch/show_agents.js +14 -14
  19. package/batch/turtle2js.nako3 +21 -21
  20. package/bin/cnako3 +10 -10
  21. package/core/LICENSE +21 -21
  22. package/core/README.md +66 -66
  23. package/core/batch/build_nako_version.nako3 +42 -42
  24. package/core/command/snako.mjs +105 -105
  25. package/core/command/snako.mts +116 -116
  26. package/core/index.mjs +21 -21
  27. package/core/package.json +47 -47
  28. package/core/sample/hello.nako3 +7 -7
  29. package/core/sample/hoge.mjs +4 -4
  30. package/core/sample/hoge.mts +6 -6
  31. package/core/src/nako3.mjs +864 -858
  32. package/core/src/nako3.mts +976 -967
  33. package/core/src/nako_colors.mjs +78 -78
  34. package/core/src/nako_colors.mts +86 -86
  35. package/core/src/nako_core_version.mjs +8 -8
  36. package/core/src/nako_core_version.mts +19 -19
  37. package/core/src/nako_csv.mjs +185 -185
  38. package/core/src/nako_csv.mts +188 -188
  39. package/core/src/nako_errors.mjs +173 -173
  40. package/core/src/nako_errors.mts +197 -197
  41. package/core/src/nako_from_dncl.mjs +255 -255
  42. package/core/src/nako_from_dncl.mts +250 -250
  43. package/core/src/nako_gen.mjs +1647 -1648
  44. package/core/src/nako_gen.mts +1718 -1719
  45. package/core/src/nako_gen_async.mjs +1659 -1659
  46. package/core/src/nako_gen_async.mts +1732 -1732
  47. package/core/src/nako_global.mjs +107 -107
  48. package/core/src/nako_global.mts +138 -138
  49. package/core/src/nako_indent.mjs +445 -445
  50. package/core/src/nako_indent.mts +492 -492
  51. package/core/src/nako_josi_list.mjs +38 -38
  52. package/core/src/nako_josi_list.mts +45 -45
  53. package/core/src/nako_lex_rules.mjs +253 -253
  54. package/core/src/nako_lex_rules.mts +260 -260
  55. package/core/src/nako_lexer.mjs +609 -609
  56. package/core/src/nako_lexer.mts +612 -612
  57. package/core/src/nako_logger.mjs +199 -199
  58. package/core/src/nako_logger.mts +232 -232
  59. package/core/src/nako_parser3.mjs +2439 -2439
  60. package/core/src/nako_parser3.mts +2195 -2195
  61. package/core/src/nako_parser_base.mjs +370 -370
  62. package/core/src/nako_parser_base.mts +370 -370
  63. package/core/src/nako_parser_const.mjs +37 -37
  64. package/core/src/nako_parser_const.mts +37 -37
  65. package/core/src/nako_prepare.mjs +304 -304
  66. package/core/src/nako_prepare.mts +315 -315
  67. package/core/src/nako_reserved_words.mjs +38 -38
  68. package/core/src/nako_reserved_words.mts +38 -38
  69. package/core/src/nako_source_mapping.mjs +207 -207
  70. package/core/src/nako_source_mapping.mts +262 -262
  71. package/core/src/nako_test.mjs +37 -37
  72. package/core/src/nako_types.mjs +25 -25
  73. package/core/src/nako_types.mts +151 -151
  74. package/core/src/plugin_csv.mjs +49 -49
  75. package/core/src/plugin_csv.mts +50 -50
  76. package/core/src/plugin_math.mjs +328 -328
  77. package/core/src/plugin_math.mts +326 -326
  78. package/core/src/plugin_promise.mjs +91 -91
  79. package/core/src/plugin_promise.mts +91 -91
  80. package/core/src/plugin_system.mjs +2832 -2832
  81. package/core/src/plugin_system.mts +2690 -2690
  82. package/core/src/plugin_test.mjs +34 -34
  83. package/core/src/plugin_test.mts +34 -34
  84. package/demo/.DS_Store +0 -0
  85. package/demo/ace_editor.html +89 -89
  86. package/demo/ace_editor_tabs.html +161 -161
  87. package/demo/basic.html +71 -71
  88. package/demo/browsers.html +10 -9
  89. package/demo/css/basic.css +3 -3
  90. package/demo/css/common.css +157 -157
  91. package/demo/css/editor.css +8 -8
  92. package/demo/css/flow.css +3 -3
  93. package/demo/css/index.css +3 -3
  94. package/demo/extlib/.DS_Store +0 -0
  95. package/demo/flow.html +98 -98
  96. package/demo/graph.html +53 -53
  97. package/demo/image/nakopad-icon256.png +0 -0
  98. package/demo/index.html +133 -133
  99. package/demo/js/common.js +17 -17
  100. package/demo/js/turtle3d_test.js +44 -44
  101. package/demo/js/turtle_test.js +45 -45
  102. package/demo/nako3/calc.nako3 +4 -4
  103. package/demo/runscript.html +47 -47
  104. package/demo/runscript2.html +33 -33
  105. package/demo/runscript3.html +35 -35
  106. package/demo/runscript4.html +33 -33
  107. package/demo/turtle.html +58 -58
  108. package/demo/turtle2.html +141 -141
  109. package/demo/turtle3.html +279 -279
  110. package/demo/turtle3d.html +58 -58
  111. package/demo/turtle3d2.html +107 -107
  112. package/demo/version.html +24 -24
  113. package/doc/SETUP.md +157 -157
  114. package/doc/about.md +17 -17
  115. package/doc/browsers.md +26 -26
  116. package/doc/docgen.md +21 -21
  117. package/doc/editor.md +44 -44
  118. package/doc/files.md +39 -39
  119. package/doc/plugins.md +234 -234
  120. package/doc/release.md +79 -79
  121. package/doc/textlint.md +43 -43
  122. package/doc/win32.md +57 -57
  123. package/package.json +195 -195
  124. package/release/_hash.txt +28 -28
  125. package/release/_script-tags.txt +14 -14
  126. package/release/command.json +1 -1
  127. package/release/command.json.js +1 -1
  128. package/release/command_cnako3.json +1 -1
  129. package/release/command_list.json +1 -1
  130. package/release/editor.js +1 -1
  131. package/release/nako_gen_async.js +1 -1
  132. package/release/nako_gen_async.js.LICENSE.txt +35 -0
  133. package/release/plugin_caniuse.js.LICENSE.txt +11 -0
  134. package/release/plugin_csv.js +1 -1
  135. package/release/plugin_csv.js.LICENSE.txt +15 -0
  136. package/release/plugin_datetime.js.LICENSE.txt +15 -0
  137. package/release/plugin_kansuji.js.LICENSE.txt +3 -0
  138. package/release/plugin_markup.js.LICENSE.txt +11 -0
  139. package/release/plugin_turtle.js.LICENSE.txt +15 -0
  140. package/release/plugin_webworker.js.LICENSE.txt +3 -0
  141. package/release/plugin_weykturtle3d.js.LICENSE.txt +3 -0
  142. package/release/stats.json +1 -1
  143. package/release/version.js +1 -1
  144. package/release/wnako3.js +1 -1
  145. package/release/wnako3webworker.js +1 -1
  146. package/release/wnako3webworker.js.LICENSE.txt +131 -0
  147. package/src/.DS_Store +0 -0
  148. package/src/browsers.txt +12 -11
  149. package/src/browsers_agents.json +2 -2
  150. package/src/browsers_agents.mjs +1 -1
  151. package/src/cnako3.mjs +17 -17
  152. package/src/cnako3.mts +18 -18
  153. package/src/cnako3mod.mjs +707 -707
  154. package/src/cnako3mod.mts +712 -712
  155. package/src/commander_ja.mjs +164 -164
  156. package/src/commander_ja.mts +161 -161
  157. package/src/enako3.mjs +68 -68
  158. package/src/era.mjs +22 -22
  159. package/src/image_turtle-elephant.mjs +2 -2
  160. package/src/image_turtle-panda.mjs +2 -2
  161. package/src/image_turtle64.mjs +2 -2
  162. package/src/index.mjs +9 -9
  163. package/src/index.mts +10 -10
  164. package/src/nako3editorfix.sfd +106 -106
  165. package/src/nako_version.mjs +8 -8
  166. package/src/nako_version.mts +2 -2
  167. package/src/plugin_browser.mjs +213 -213
  168. package/src/plugin_browser.mts +206 -206
  169. package/src/plugin_browser_ajax.mjs +399 -399
  170. package/src/plugin_browser_audio.mjs +109 -109
  171. package/src/plugin_browser_canvas.mjs +449 -449
  172. package/src/plugin_browser_chart.mjs +294 -294
  173. package/src/plugin_browser_color.mjs +49 -49
  174. package/src/plugin_browser_crypto.mjs +26 -26
  175. package/src/plugin_browser_dialog.mjs +53 -53
  176. package/src/plugin_browser_dom_basic.mjs +336 -336
  177. package/src/plugin_browser_dom_event.mjs +193 -193
  178. package/src/plugin_browser_dom_parts.mjs +396 -396
  179. package/src/plugin_browser_geolocation.mjs +51 -51
  180. package/src/plugin_browser_hotkey.mjs +25 -25
  181. package/src/plugin_browser_html.mjs +59 -59
  182. package/src/plugin_browser_in_worker.mjs +45 -45
  183. package/src/plugin_browser_location.mjs +21 -21
  184. package/src/plugin_browser_speech.mjs +111 -111
  185. package/src/plugin_browser_storage.mjs +121 -121
  186. package/src/plugin_browser_system.mjs +31 -31
  187. package/src/plugin_browser_websocket.mjs +73 -73
  188. package/src/plugin_caniuse.mjs +29 -29
  189. package/src/plugin_datetime.mjs +394 -394
  190. package/src/plugin_httpserver.mjs +277 -277
  191. package/src/plugin_httpserver.mts +286 -286
  192. package/src/plugin_kansuji.mjs +224 -224
  193. package/src/plugin_keigo.mjs +55 -55
  194. package/src/plugin_markup.mjs +32 -32
  195. package/src/plugin_node.mjs +1047 -1047
  196. package/src/plugin_node.mts +980 -980
  197. package/src/plugin_turtle.mjs +647 -647
  198. package/src/plugin_webworker.mjs +334 -334
  199. package/src/plugin_weykturtle3d.mjs +1214 -1214
  200. package/src/plugin_worker.mjs +95 -95
  201. package/src/repl.nako3 +63 -63
  202. package/src/wnako3.mjs +12 -12
  203. package/src/wnako3.mts +11 -11
  204. package/src/wnako3_editor.css +215 -215
  205. package/src/wnako3_editor.mjs +1542 -1542
  206. package/src/wnako3_editor.mts +1658 -1657
  207. package/src/wnako3mod.mjs +213 -213
  208. package/src/wnako3mod.mts +214 -214
  209. package/src/wnako3webworker.mjs +69 -69
  210. package/test/.DS_Store +0 -0
  211. package/test/ace_editor/karma.config.js +94 -94
  212. package/test/ace_editor/test/.babelrc.json +3 -3
  213. package/test/ace_editor/test/ace_editor_test.js +178 -178
  214. package/test/ace_editor/test/html/custom_context.html +139 -139
  215. package/test/async/async_basic_test.mjs +122 -122
  216. package/test/browser/.DS_Store +0 -0
  217. package/test/browser/karma.config.js +221 -221
  218. package/test/browser/test/.babelrc.json +3 -3
  219. package/test/browser/test/compare_util.js +50 -50
  220. package/test/browser/test/html/div_basic.html +2 -2
  221. package/test/browser/test/html/event_dom_form.html +4 -4
  222. package/test/browser/test/html/event_dom_scrolldiv.html +5 -5
  223. package/test/browser/test/import_plugin_checker.js +24 -24
  224. package/test/browser/test/plugin_browser_test.js +51 -51
  225. package/test/browser/test/plugin_browser_test_ajax.js +123 -123
  226. package/test/browser/test/plugin_browser_test_color.js +18 -18
  227. package/test/browser/test/plugin_browser_test_dialog.js +72 -72
  228. package/test/browser/test/plugin_browser_test_dom_event.js +598 -598
  229. package/test/browser/test/plugin_browser_test_dom_parts.js +125 -125
  230. package/test/browser/test/plugin_browser_test_system.js +9 -9
  231. package/test/browser/test/plugin_turtle_test.js +817 -817
  232. package/test/browser/test/plugin_webworker_test.js +86 -86
  233. package/test/browser/test/require_test.js +68 -68
  234. package/test/bundled/.DS_Store +0 -0
  235. package/test/bundled/karma.config.base.js +117 -117
  236. package/test/bundled/karma.config.js +86 -86
  237. package/test/bundled/test/.babelrc.json +3 -3
  238. package/test/bundled/test/bundled_test.js +69 -69
  239. package/test/bundled/test/html/custom_context.html +65 -65
  240. package/test/bundled/test/html/custom_debug.html +66 -66
  241. package/test/bundled/test4b.cmd +52 -52
  242. package/test/bundled/test_base/.DS_Store +0 -0
  243. package/test/bundled/test_base/.babelrc.json +3 -3
  244. package/test/bundled/test_base/_checktool_test.js +25 -25
  245. package/test/bundled/test_base/basic_ajax_test.js +56 -56
  246. package/test/bundled/test_base/basic_async_test.js +18 -18
  247. package/test/bundled/test_base/basic_test.js +153 -153
  248. package/test/bundled/test_base/calc_test.js +132 -132
  249. package/test/bundled/test_base/css/browsers_box.css +114 -114
  250. package/test/bundled/test_base/html/custom_context.html +69 -69
  251. package/test/bundled/test_base/html/custom_debug.html +71 -71
  252. package/test/bundled/test_base/js/browsers_box.js +72 -72
  253. package/test/bundled/test_base/plugin_csv_test.js +37 -37
  254. package/test/bundled/test_base/plugin_datetime_test.js +115 -115
  255. package/test/bundled/test_base/plugin_kansuji_test.js +49 -49
  256. package/test/bundled/test_base/plugin_system_test.js +410 -410
  257. package/test/bundled/test_base/plugin_webworker_test.js +53 -53
  258. package/test/bundled/test_base/test_utils.js +191 -191
  259. package/test/common/.DS_Store +0 -0
  260. package/test/common/plugin_browser_test.mjs +22 -22
  261. package/test/common/plugin_browser_ut_audio_test.mjs +108 -108
  262. package/test/common/plugin_browser_ut_color_test.mjs +21 -21
  263. package/test/common/plugin_browser_ut_dialog_test.mjs +100 -100
  264. package/test/common/plugin_browser_ut_html_test.mjs +13 -13
  265. package/test/common/plugin_browser_ut_system_test.mjs +10 -10
  266. package/test/common/plugin_markup_test.mjs +23 -23
  267. package/test/jsconfig.json +19 -19
  268. package/test/karma.config.js +91 -91
  269. package/test/node/.DS_Store +0 -0
  270. package/test/node/async_test.mjs +96 -96
  271. package/test/node/commander_ja_test.mjs +89 -89
  272. package/test/node/error_message_test.mjs +243 -243
  273. package/test/node/kai_test.nako3 +6 -6
  274. package/test/node/node_test.mjs +60 -60
  275. package/test/node/plugin_broken.js.txt +3 -3
  276. package/test/node/plugin_browser_ut_ajax_test.mjs.todo +357 -357
  277. package/test/node/plugin_browser_ut_location_test.mjs +42 -42
  278. package/test/node/plugin_markup_test.mjs +47 -47
  279. package/test/node/plugin_math_test.mjs +45 -45
  280. package/test/node/plugin_node_test.mjs +98 -98
  281. package/test/node/plugin_test.mjs +44 -44
  282. package/test/node/relative_import_test_1.nako3 +1 -1
  283. package/test/node/relative_import_test_2.nako3 +2 -2
  284. package/test/node/require_nako3_test.mjs +67 -67
  285. package/test/node/requiretest.nako3 +4 -4
  286. package/test/node/requiretest_indirect.nako3 +1 -1
  287. package/test/node/requiretest_name.nako3 +5 -5
  288. package/test/node/runtime_error.nako3 +2 -2
  289. package/test/node/scope1.nako3 +10 -10
  290. package/test/node/scope2.nako3 +12 -12
  291. package/test/node/side_effects_test.mjs +39 -39
  292. package/test/node/sjis.txt +5 -5
  293. package/test/node/syntax_error.nako3 +1 -1
  294. package/test/node/wnako3_editor_test.mjs +384 -384
  295. package/tools/.DS_Store +0 -0
  296. package/tools/README.md +12 -12
  297. package/tools/check_new_version.nako3 +25 -25
  298. package/tools/nako3edit/.DS_Store +0 -0
  299. package/tools/nako3edit/a.sqlite3 +0 -0
  300. package/tools/nako3edit/html/.DS_Store +0 -0
  301. package/tools/nako3edit/html/daisyui/LICENSE +22 -22
  302. package/tools/nako3edit/html/daisyui/version_2.14.1 +1 -1
  303. package/tools/nako3edit/html/edit.html +170 -170
  304. package/tools/nako3edit/html/edit_plugin.js +6 -6
  305. package/tools/nako3edit/html/files.html +125 -125
  306. package/tools/nako3edit/html/nako3edit.css +65 -65
  307. package/tools/nako3edit/index.mjs +248 -248
  308. package/tools/nako3server/index.html +10 -10
  309. package/tools/nako3server/index.mjs +116 -116
  310. package/tools/nako3server/index.nako3 +34 -34
  311. package/core/.editorconfig +0 -6
  312. package/core/.eslintrc.cjs +0 -33
  313. package/core/.github/dependabot.yml +0 -7
  314. package/core/.github/workflows/nodejs.yml +0 -37
  315. package/core/.github/workflows/super-linter.yml +0 -61
  316. package/core/.github/workflows/textlint.yml +0 -199
  317. package/core/index.mts +0 -21
  318. package/core/test/array_test.mjs +0 -34
  319. package/core/test/basic_test.mjs +0 -344
  320. package/core/test/calc_test.mjs +0 -140
  321. package/core/test/core_module_test.mjs +0 -23
  322. package/core/test/debug_test.mjs +0 -16
  323. package/core/test/dncl_test.mjs +0 -94
  324. package/core/test/error_message_test.mjs +0 -210
  325. package/core/test/error_test.mjs +0 -16
  326. package/core/test/flow_test.mjs +0 -373
  327. package/core/test/func_call.mjs +0 -160
  328. package/core/test/func_test.mjs +0 -149
  329. package/core/test/indent_test.mjs +0 -364
  330. package/core/test/lex_test.mjs +0 -168
  331. package/core/test/literal_test.mjs +0 -73
  332. package/core/test/nako_lexer_test.mjs +0 -35
  333. package/core/test/nako_logger_test.mjs +0 -76
  334. package/core/test/nako_logger_test.mts +0 -78
  335. package/core/test/plugin_csv_test.mjs +0 -38
  336. package/core/test/plugin_promise_test.mjs +0 -18
  337. package/core/test/plugin_system_test.mjs +0 -630
  338. package/core/test/prepare_test.mjs +0 -96
  339. package/core/test/re_test.mjs +0 -22
  340. package/core/test/side_effects_test.mjs +0 -92
  341. package/core/test/variable_scope_test.mjs +0 -149
  342. package/core/tsconfig.json +0 -101
@@ -1,1047 +1,1047 @@
1
- /**
2
- * file: plugin_node.mjs
3
- * node.js のためのプラグイン
4
- */
5
- import fs from 'fs';
6
- import fse from 'fs-extra';
7
- import fetch from 'node-fetch';
8
- import { exec, execSync } from 'child_process';
9
- import path from 'path';
10
- import iconv from 'iconv-lite';
11
- import opener from 'opener';
12
- import assert from 'assert';
13
- // 「標準入力取得時」「尋」で利用
14
- import readline from 'readline';
15
- // ハッシュ関数で利用
16
- import crypto from 'crypto';
17
- import os from 'os';
18
- export default {
19
- '初期化': {
20
- type: 'func',
21
- josi: [],
22
- pure: true,
23
- fn: function (sys) {
24
- sys.__getBinPath = (tool) => {
25
- let fpath = tool;
26
- if (process.platform === 'win32') {
27
- if (!fileExists(tool)) {
28
- const nodeDir = path.dirname(process.argv[0]);
29
- const root = path.resolve(path.join(nodeDir, '..'));
30
- fpath = path.join(root, 'bin', tool + '.exe');
31
- if (fileExists(fpath)) {
32
- return `"${fpath}"`;
33
- }
34
- return tool;
35
- }
36
- }
37
- return fpath;
38
- };
39
- sys.__getBokanPath = () => {
40
- let nakofile;
41
- const cmd = path.basename(process.argv[1]);
42
- if (cmd.indexOf('cnako3') < 0) {
43
- nakofile = process.argv[1];
44
- }
45
- else {
46
- nakofile = process.argv[2];
47
- }
48
- return path.dirname(path.resolve(nakofile));
49
- };
50
- sys.__v0['コマンドライン'] = process.argv;
51
- sys.__v0['ナデシコランタイムパス'] = process.argv[0];
52
- sys.__v0['ナデシコランタイム'] = path.basename(process.argv[0]);
53
- sys.__v0['母艦パス'] = sys.__getBokanPath();
54
- sys.__v0['AJAX:ONERROR'] = null;
55
- }
56
- },
57
- // @ファイル入出力
58
- '開': {
59
- type: 'func',
60
- josi: [['を', 'から']],
61
- pure: true,
62
- fn: function (s) {
63
- return fs.readFileSync(s, 'utf-8');
64
- }
65
- },
66
- '読': {
67
- type: 'func',
68
- josi: [['を', 'から']],
69
- pure: false,
70
- fn: function (s, sys) {
71
- return sys.__exec('開', [s]);
72
- }
73
- },
74
- 'バイナリ読': {
75
- type: 'func',
76
- josi: [['を', 'から']],
77
- pure: true,
78
- fn: function (s, sys) {
79
- return fs.readFileSync(s);
80
- }
81
- },
82
- '保存': {
83
- type: 'func',
84
- josi: [['を'], ['へ', 'に']],
85
- pure: true,
86
- fn: function (s, f) {
87
- // Buffer?
88
- if (typeof s === 'string') {
89
- fs.writeFileSync(f, s, 'utf-8');
90
- }
91
- else {
92
- fs.writeFileSync(f, s);
93
- }
94
- },
95
- return_none: true
96
- },
97
- 'SJISファイル読': {
98
- type: 'func',
99
- josi: [['を', 'から']],
100
- pure: true,
101
- fn: function (s, sys) {
102
- // iconv.skipDecodeWarning = true
103
- const buf = fs.readFileSync(s);
104
- const text = iconv.decode(Buffer.from(buf), 'sjis');
105
- return text;
106
- }
107
- },
108
- 'SJISファイル保存': {
109
- type: 'func',
110
- josi: [['を'], ['へ', 'に']],
111
- pure: true,
112
- fn: function (s, f, sys) {
113
- // iconv.skipDecodeWarning = true
114
- const buf = iconv.encode(s, 'Shift_JIS');
115
- fs.writeFileSync(f, buf);
116
- },
117
- return_none: true
118
- },
119
- '起動待機': {
120
- type: 'func',
121
- josi: [['を']],
122
- pure: true,
123
- fn: function (s) {
124
- const r = execSync(s);
125
- return r.toString();
126
- }
127
- },
128
- '起動': {
129
- type: 'func',
130
- josi: [['を']],
131
- pure: true,
132
- fn: function (s) {
133
- exec(s, (err, stdout, stderr) => {
134
- if (err) {
135
- console.error(stderr);
136
- }
137
- else if (stdout) {
138
- console.log(stdout);
139
- }
140
- });
141
- }
142
- },
143
- '起動時': {
144
- type: 'func',
145
- josi: [['で'], ['を']],
146
- pure: true,
147
- fn: function (callback, s, sys) {
148
- exec(s, (err, stdout, stderr) => {
149
- if (err) {
150
- throw new Error(stderr);
151
- }
152
- else {
153
- callback(stdout);
154
- }
155
- });
156
- }
157
- },
158
- 'ブラウザ起動': {
159
- type: 'func',
160
- josi: [['を']],
161
- pure: true,
162
- fn: function (url) {
163
- opener(url);
164
- }
165
- },
166
- 'ファイル列挙': {
167
- type: 'func',
168
- josi: [['の', 'を', 'で']],
169
- pure: true,
170
- fn: function (s) {
171
- if (s.indexOf('*') >= 0) { // ワイルドカードがある場合
172
- const searchPath = path.dirname(s);
173
- const mask1 = path.basename(s)
174
- .replace(/\./g, '\\.')
175
- .replace(/\*/g, '.*');
176
- const mask2 = (mask1.indexOf(';') < 0)
177
- ? mask1 + '$'
178
- : '(' + mask1.replace(/;/g, '|') + ')$';
179
- const maskRE = new RegExp(mask2, 'i');
180
- const list = fs.readdirSync(searchPath);
181
- return list.filter((n) => maskRE.test(n));
182
- }
183
- else {
184
- return fs.readdirSync(s);
185
- }
186
- }
187
- },
188
- '全ファイル列挙': {
189
- type: 'func',
190
- josi: [['の', 'を', 'で']],
191
- pure: true,
192
- fn: function (s) {
193
- /** @type {string[]} */
194
- const result = [];
195
- // ワイルドカードの有無を確認
196
- let mask = '.*';
197
- let basepath = s;
198
- if (s.indexOf('*') >= 0) {
199
- basepath = path.dirname(s);
200
- const mask1 = path.basename(s)
201
- .replace(/\./g, '\\.')
202
- .replace(/\*/g, '.*');
203
- mask = (mask1.indexOf(';') < 0)
204
- ? mask1 + '$'
205
- : '(' + mask1.replace(/;/g, '|') + ')$';
206
- }
207
- basepath = path.resolve(basepath);
208
- const maskRE = new RegExp(mask, 'i');
209
- // 再帰関数を定義
210
- const enumR = (base) => {
211
- const list = fs.readdirSync(base);
212
- for (const f of list) {
213
- if (f === '.' || f === '..') {
214
- continue;
215
- }
216
- const fullpath = path.join(base, f);
217
- let st = null;
218
- try {
219
- st = fs.statSync(fullpath);
220
- }
221
- catch (e) {
222
- st = null;
223
- }
224
- if (st == null) {
225
- continue;
226
- }
227
- if (st.isDirectory()) {
228
- enumR(fullpath);
229
- continue;
230
- }
231
- if (maskRE.test(f)) {
232
- result.push(fullpath);
233
- }
234
- }
235
- };
236
- // 検索実行
237
- enumR(basepath);
238
- return result;
239
- }
240
- },
241
- '存在': {
242
- type: 'func',
243
- josi: [['が', 'の']],
244
- pure: true,
245
- fn: function (path) {
246
- return fileExists(path);
247
- }
248
- },
249
- 'フォルダ存在': {
250
- type: 'func',
251
- josi: [['が', 'の']],
252
- pure: true,
253
- fn: function (path) {
254
- return isDir(path);
255
- }
256
- },
257
- 'フォルダ作成': {
258
- type: 'func',
259
- josi: [['の', 'を', 'に', 'へ']],
260
- pure: true,
261
- fn: function (path) {
262
- return fse.mkdirpSync(path);
263
- }
264
- },
265
- 'ファイルコピー': {
266
- type: 'func',
267
- josi: [['から', 'を'], ['に', 'へ']],
268
- pure: true,
269
- fn: function (a, b, sys) {
270
- return fse.copySync(a, b);
271
- }
272
- },
273
- 'ファイルコピー時': {
274
- type: 'func',
275
- josi: [['で'], ['から', 'を'], ['に', 'へ']],
276
- pure: true,
277
- fn: function (callback, a, b, sys) {
278
- return fse.copy(a, b, (err) => {
279
- if (err) {
280
- throw new Error('ファイルコピー時:' + err);
281
- }
282
- callback();
283
- });
284
- },
285
- return_none: false
286
- },
287
- 'ファイル移動': {
288
- type: 'func',
289
- josi: [['から', 'を'], ['に', 'へ']],
290
- pure: true,
291
- fn: function (a, b, sys) {
292
- return fse.moveSync(a, b);
293
- }
294
- },
295
- 'ファイル移動時': {
296
- type: 'func',
297
- josi: [['で'], ['から', 'を'], ['に', 'へ']],
298
- pure: true,
299
- fn: function (callback, a, b, sys) {
300
- fse.move(a, b, (err) => {
301
- if (err) {
302
- throw new Error('ファイル移動時:' + err);
303
- }
304
- callback();
305
- });
306
- },
307
- return_none: false
308
- },
309
- 'ファイル削除': {
310
- type: 'func',
311
- josi: [['の', 'を']],
312
- pure: true,
313
- fn: function (path, sys) {
314
- return fse.removeSync(path);
315
- }
316
- },
317
- 'ファイル削除時': {
318
- type: 'func',
319
- josi: [['で'], ['の', 'を']],
320
- pure: true,
321
- fn: function (callback, path, sys) {
322
- return fse.remove(path, (err) => {
323
- if (err) {
324
- throw new Error('ファイル削除時:' + err);
325
- }
326
- callback();
327
- });
328
- },
329
- return_none: false
330
- },
331
- 'ファイル情報取得': {
332
- type: 'func',
333
- josi: [['の', 'から']],
334
- pure: true,
335
- fn: function (path, sys) {
336
- return fs.statSync(path);
337
- }
338
- },
339
- 'ファイルサイズ取得': {
340
- type: 'func',
341
- josi: [['の', 'から']],
342
- pure: true,
343
- fn: function (path, sys) {
344
- const st = fs.statSync(path);
345
- if (!st) {
346
- return -1;
347
- }
348
- return st.size;
349
- }
350
- },
351
- // @パス操作
352
- 'ファイル名抽出': {
353
- type: 'func',
354
- josi: [['から', 'の']],
355
- pure: true,
356
- fn: function (s) {
357
- return path.basename(s);
358
- }
359
- },
360
- 'パス抽出': {
361
- type: 'func',
362
- josi: [['から', 'の']],
363
- pure: true,
364
- fn: function (s) {
365
- return path.dirname(s);
366
- }
367
- },
368
- '絶対パス変換': {
369
- type: 'func',
370
- josi: [['を', 'の']],
371
- pure: true,
372
- fn: function (a) {
373
- return path.resolve(a);
374
- }
375
- },
376
- '相対パス展開': {
377
- type: 'func',
378
- josi: [['を'], ['で']],
379
- pure: true,
380
- fn: function (a, b) {
381
- return path.resolve(path.join(a, b));
382
- }
383
- },
384
- // @フォルダ取得
385
- 'カレントディレクトリ取得': {
386
- type: 'func',
387
- josi: [],
388
- pure: true,
389
- fn: function () {
390
- const cwd = process.cwd();
391
- return path.resolve(cwd);
392
- }
393
- },
394
- 'カレントディレクトリ変更': {
395
- type: 'func',
396
- josi: [['に', 'へ']],
397
- pure: true,
398
- fn: function (dir) {
399
- process.chdir(dir);
400
- },
401
- return_none: true
402
- },
403
- '作業フォルダ取得': {
404
- type: 'func',
405
- josi: [],
406
- pure: true,
407
- fn: function () {
408
- const cwd = process.cwd();
409
- return path.resolve(cwd);
410
- }
411
- },
412
- '作業フォルダ変更': {
413
- type: 'func',
414
- josi: [['に', 'へ']],
415
- pure: true,
416
- fn: function (dir) {
417
- process.chdir(dir);
418
- },
419
- return_none: true
420
- },
421
- 'ホームディレクトリ取得': {
422
- type: 'func',
423
- josi: [],
424
- pure: true,
425
- fn: function () {
426
- return process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME'];
427
- }
428
- },
429
- 'デスクトップ': {
430
- type: 'func',
431
- josi: [],
432
- pure: false,
433
- fn: function (sys) {
434
- const home = sys.__exec('ホームディレクトリ取得', [sys]);
435
- return path.join(home, 'Desktop');
436
- }
437
- },
438
- 'マイドキュメント': {
439
- type: 'func',
440
- josi: [],
441
- pure: false,
442
- fn: function (sys) {
443
- const home = sys.__exec('ホームディレクトリ取得', [sys]);
444
- return path.join(home, 'Documents');
445
- }
446
- },
447
- '母艦パス': { type: 'const', value: '' },
448
- '母艦パス取得': {
449
- type: 'func',
450
- josi: [],
451
- pure: true,
452
- fn: function (sys) {
453
- return sys.__getBokanPath();
454
- }
455
- },
456
- // @環境変数
457
- '環境変数取得': {
458
- type: 'func',
459
- josi: [['の']],
460
- pure: true,
461
- fn: function (s) {
462
- return process.env[s];
463
- }
464
- },
465
- '環境変数一覧取得': {
466
- type: 'func',
467
- josi: [],
468
- pure: true,
469
- fn: function () {
470
- return process.env;
471
- }
472
- },
473
- // @圧縮・解凍
474
- '圧縮解凍ツールパス': { type: 'const', value: '7z' },
475
- '圧縮解凍ツールパス変更': {
476
- type: 'func',
477
- josi: [['に', 'へ']],
478
- pure: true,
479
- fn: function (v, sys) {
480
- sys.__v0['圧縮解凍ツールパス'] = v;
481
- },
482
- return_none: true
483
- },
484
- '解凍': {
485
- type: 'func',
486
- josi: [['を', 'から'], ['に', 'へ']],
487
- pure: true,
488
- fn: function (a, b, sys) {
489
- const tpath = sys.__getBinPath(sys.__v0['圧縮解凍ツールパス']);
490
- const cmd = `${tpath} x "${a}" -o"${b}" -y`;
491
- execSync(cmd);
492
- return true;
493
- }
494
- },
495
- '解凍時': {
496
- type: 'func',
497
- josi: [['で'], ['を', 'から'], ['に', 'へ']],
498
- pure: true,
499
- fn: function (callback, a, b, sys) {
500
- const tpath = sys.__getBinPath(sys.__v0['圧縮解凍ツールパス']);
501
- const cmd = `${tpath} x "${a}" -o"${b}" -y`;
502
- exec(cmd, (err, stdout, stderr) => {
503
- if (err) {
504
- throw new Error('[エラー]『解凍時』' + err);
505
- }
506
- callback(stdout);
507
- });
508
- },
509
- return_none: false
510
- },
511
- '圧縮': {
512
- type: 'func',
513
- josi: [['を', 'から'], ['に', 'へ']],
514
- pure: true,
515
- fn: function (a, b, sys) {
516
- const tpath = sys.__getBinPath(sys.__v0['圧縮解凍ツールパス']);
517
- const cmd = `${tpath} a -r "${b}" "${a}" -y`;
518
- execSync(cmd);
519
- return true;
520
- }
521
- },
522
- '圧縮時': {
523
- type: 'func',
524
- josi: [['で'], ['を', 'から'], ['に', 'へ']],
525
- pure: true,
526
- fn: function (callback, a, b, sys) {
527
- const tpath = sys.__getBinPath(sys.__v0['圧縮解凍ツールパス']);
528
- const cmd = `${tpath} a -r "${b}" "${a}" -y`;
529
- exec(cmd, (err, stdout, stderr) => {
530
- if (err) {
531
- throw new Error('[エラー]『圧縮時』' + err);
532
- }
533
- callback(stdout);
534
- });
535
- },
536
- return_none: true
537
- },
538
- // @Nodeプロセス
539
- '終': {
540
- type: 'func',
541
- josi: [],
542
- pure: true,
543
- fn: function () {
544
- process.exit();
545
- },
546
- return_none: true
547
- },
548
- '強制終了時': {
549
- type: 'func',
550
- josi: [['を']],
551
- pure: true,
552
- fn: function (func, sys) {
553
- if (typeof (func) === 'string') {
554
- func = sys.__findFunc(func, '強制終了時');
555
- }
556
- process.on('SIGINT', (signal) => {
557
- const flag = func(sys);
558
- if (flag) {
559
- process.exit();
560
- }
561
- });
562
- },
563
- return_none: true
564
- },
565
- '終了': {
566
- type: 'func',
567
- josi: [],
568
- pure: false,
569
- fn: function (sys) {
570
- sys.__exec('終', []);
571
- },
572
- return_none: true
573
- },
574
- 'OS取得': {
575
- type: 'func',
576
- josi: [],
577
- pure: true,
578
- fn: function (sys) {
579
- return process.platform;
580
- }
581
- },
582
- 'OSアーキテクチャ取得': {
583
- type: 'func',
584
- josi: [],
585
- pure: true,
586
- fn: function (sys) {
587
- return process.arch;
588
- }
589
- },
590
- // @コマンドラインと標準入出力
591
- 'コマンドライン': { type: 'const', value: '' },
592
- 'ナデシコランタイム': { type: 'const', value: '' },
593
- 'ナデシコランタイムパス': { type: 'const', value: '' },
594
- '標準入力取得時': {
595
- type: 'func',
596
- josi: [['を']],
597
- pure: true,
598
- fn: function (callback) {
599
- const reader = readline.createInterface({
600
- input: process.stdin,
601
- output: process.stdout
602
- });
603
- reader.on('line', function (line) {
604
- callback(line);
605
- });
606
- }
607
- },
608
- '尋': {
609
- type: 'func',
610
- josi: [['と', 'を']],
611
- pure: true,
612
- asyncFn: true,
613
- fn: function (msg) {
614
- return new Promise((resolve, reject) => {
615
- const rl = readline.createInterface(process.stdin, process.stdout);
616
- if (!rl) {
617
- reject(new Error('『尋』命令で標準入力が取得できません'));
618
- return;
619
- }
620
- rl.question(msg, (buf) => {
621
- rl.close();
622
- if (buf && buf.match(/^[0-9.]+$/)) {
623
- buf = parseFloat(buf);
624
- }
625
- resolve(buf);
626
- });
627
- });
628
- }
629
- },
630
- // @テスト
631
- 'ASSERT等': {
632
- type: 'func',
633
- josi: [['と'], ['が']],
634
- pure: true,
635
- fn: function (a, b, sys) {
636
- assert.strictEqual(a, b);
637
- }
638
- },
639
- // @ネットワーク
640
- '自分IPアドレス取得': {
641
- type: 'func',
642
- josi: [],
643
- pure: true,
644
- fn: function (sys) {
645
- const nif = os.networkInterfaces();
646
- if (!nif) {
647
- throw new Error('『自分IPアドレス取得』でネットワークのインターフェイスが種畜できません。');
648
- }
649
- /**
650
- * @type {string[]}
651
- */
652
- const result = [];
653
- for (const dev in nif) {
654
- const n = nif[dev];
655
- if (!n) {
656
- continue;
657
- }
658
- n.forEach((detail) => {
659
- if (detail.family === 'IPv4') {
660
- result.push(detail.address);
661
- }
662
- });
663
- }
664
- return result;
665
- }
666
- },
667
- '自分IPV6アドレス取得': {
668
- type: 'func',
669
- josi: [],
670
- pure: true,
671
- fn: function (sys) {
672
- const nif = os.networkInterfaces();
673
- if (!nif) {
674
- throw new Error('『自分IPアドレス取得』でネットワークのインターフェイスが種畜できません。');
675
- }
676
- const result = [];
677
- for (const dev in nif) {
678
- const n = nif[dev];
679
- if (!n) {
680
- continue;
681
- }
682
- n.forEach((detail) => {
683
- if (detail.family === 'IPv6') {
684
- result.push(detail.address);
685
- }
686
- });
687
- }
688
- return result;
689
- }
690
- },
691
- // @Ajax
692
- 'AJAX送信時': {
693
- type: 'func',
694
- josi: [['の'], ['まで', 'へ', 'に']],
695
- pure: true,
696
- fn: function (callback, url, sys) {
697
- let options = sys.__v0['AJAXオプション'];
698
- if (options === '') {
699
- options = { method: 'GET' };
700
- }
701
- fetch(url, options).then((res) => {
702
- return res.text();
703
- }).then((text) => {
704
- sys.__v0['対象'] = text;
705
- callback(text);
706
- }).catch((err) => {
707
- console.log('[fetch.error]', err);
708
- throw err;
709
- });
710
- },
711
- return_none: true
712
- },
713
- 'AJAX受信時': {
714
- type: 'func',
715
- josi: [['で'], ['から', 'を']],
716
- pure: true,
717
- fn: function (callback, url, sys) {
718
- sys.__exec('AJAX送信時', [callback, url, sys]);
719
- },
720
- return_none: true
721
- },
722
- 'GET送信時': {
723
- type: 'func',
724
- josi: [['の'], ['まで', 'へ', 'に']],
725
- pure: false,
726
- fn: function (callback, url, sys) {
727
- sys.__exec('AJAX送信時', [callback, url, sys]);
728
- },
729
- return_none: true
730
- },
731
- 'POST送信時': {
732
- type: 'func',
733
- josi: [['の'], ['まで', 'へ', 'に'], ['を']],
734
- pure: true,
735
- fn: function (callback, url, params, sys) {
736
- const flist = [];
737
- for (const key in params) {
738
- const v = params[key];
739
- const kv = encodeURIComponent(key) + '=' + encodeURIComponent(v);
740
- flist.push(kv);
741
- }
742
- const bodyData = flist.join('&');
743
- const options = {
744
- method: 'POST',
745
- headers: {
746
- 'Content-Type': 'application/x-www-form-urlencoded'
747
- },
748
- body: bodyData
749
- };
750
- fetch(url, options).then((res) => {
751
- return res.text();
752
- }).then((text) => {
753
- sys.__v0['対象'] = text;
754
- callback(text);
755
- }).catch((err) => {
756
- sys.__v0['AJAX:ONERROR'](err);
757
- });
758
- }
759
- },
760
- 'POSTフォーム送信時': {
761
- type: 'func',
762
- josi: [['の'], ['まで', 'へ', 'に'], ['を']],
763
- pure: true,
764
- fn: function (callback, url, params, sys) {
765
- const fd = new FormData();
766
- for (const key in params) {
767
- fd.set(key, params[key]);
768
- }
769
- const options = {
770
- method: 'POST',
771
- headers: {
772
- 'Content-Type': 'multipart/form-data'
773
- },
774
- body: fd
775
- };
776
- fetch(url, options).then((res) => {
777
- return res.text();
778
- }).then((text) => {
779
- sys.__v0['対象'] = text;
780
- callback(text);
781
- }).catch((err) => {
782
- sys.__v0['AJAX:ONERROR'](err);
783
- });
784
- }
785
- },
786
- 'AJAX失敗時': {
787
- type: 'func',
788
- josi: [['の']],
789
- pure: true,
790
- fn: function (callback, sys) {
791
- sys.__v0['AJAX:ONERROR'] = callback;
792
- }
793
- },
794
- 'AJAXオプション': { type: 'const', value: '' },
795
- 'AJAXオプション設定': {
796
- type: 'func',
797
- josi: [['に', 'へ', 'と']],
798
- pure: true,
799
- fn: function (option, sys) {
800
- sys.__v0['AJAXオプション'] = option;
801
- },
802
- return_none: true
803
- },
804
- 'AJAX保障送信': {
805
- type: 'func',
806
- josi: [['まで', 'へ', 'に']],
807
- pure: true,
808
- fn: function (url, sys) {
809
- let options = sys.__v0['AJAXオプション'];
810
- if (options === '') {
811
- options = { method: 'GET' };
812
- }
813
- return fetch(url, options);
814
- },
815
- return_none: false
816
- },
817
- 'HTTP保障取得': {
818
- type: 'func',
819
- josi: [['の', 'から', 'を']],
820
- pure: true,
821
- fn: function (url, sys) {
822
- return sys.__exec('AJAX保障送信', [url, sys]);
823
- },
824
- return_none: false
825
- },
826
- 'GET保障送信': {
827
- type: 'func',
828
- josi: [['まで', 'へ', 'に']],
829
- pure: true,
830
- fn: function (url, sys) {
831
- return sys.__exec('AJAX保障送信', [url, sys]);
832
- },
833
- return_none: false
834
- },
835
- 'POST保障送信': {
836
- type: 'func',
837
- josi: [['まで', 'へ', 'に'], ['を']],
838
- pure: true,
839
- fn: function (url, params, sys) {
840
- const flist = [];
841
- for (const key in params) {
842
- const v = params[key];
843
- const kv = encodeURIComponent(key) + '=' + encodeURIComponent(v);
844
- flist.push(kv);
845
- }
846
- const bodyData = flist.join('&');
847
- const options = {
848
- method: 'POST',
849
- headers: {
850
- 'Content-Type': 'application/x-www-form-urlencoded'
851
- },
852
- body: bodyData
853
- };
854
- return fetch(url, options);
855
- },
856
- return_none: false
857
- },
858
- 'POSTフォーム保障送信': {
859
- type: 'func',
860
- josi: [['まで', 'へ', 'に'], ['を']],
861
- pure: true,
862
- fn: function (url, params, sys) {
863
- const fd = new FormData();
864
- for (const key in params) {
865
- fd.set(key, params[key]);
866
- }
867
- const options = {
868
- method: 'POST',
869
- body: fd
870
- };
871
- return fetch(url, options);
872
- },
873
- return_none: false
874
- },
875
- 'AJAX内容取得': {
876
- type: 'func',
877
- josi: [['から'], ['で']],
878
- pure: true,
879
- fn: function (res, type, sys) {
880
- type = type.toString().toUpperCase();
881
- if (type === 'TEXT' || type === 'テキスト') {
882
- return res.text();
883
- }
884
- else if (type === 'JSON') {
885
- return res.json();
886
- }
887
- else if (type === 'BLOB') {
888
- return res.blob();
889
- }
890
- else if (type === 'ARRAY' || type === '配列') {
891
- return res.arrayBuffer();
892
- }
893
- else if (type === 'BODY' || type === '本体') {
894
- return res.body;
895
- }
896
- return res.body();
897
- },
898
- return_none: false
899
- },
900
- 'AJAX受信': {
901
- type: 'func',
902
- josi: [['から', 'を']],
903
- pure: true,
904
- fn: function (url, sys) {
905
- if (sys.__genMode !== '非同期モード') {
906
- throw new Error('『AJAX受信』を使うには、プログラムの冒頭で「!非同期モード」と宣言してください。');
907
- }
908
- const sysenv = sys.setAsync(sys);
909
- let options = sys.__v0['AJAXオプション'];
910
- if (options === '') {
911
- options = { method: 'GET' };
912
- }
913
- // fetch 実行
914
- fetch(url, options).then((res) => {
915
- if (res.ok) { // 成功したとき
916
- return res.text();
917
- }
918
- else { // 失敗したとき
919
- throw new Error('status=' + res.status);
920
- }
921
- }).then((text) => {
922
- sys.__v0['対象'] = text;
923
- sys.compAsync(sys, sysenv);
924
- }).catch((err) => {
925
- console.error('[AJAX受信のエラー]', err);
926
- sys.__errorAsync(err, sys);
927
- });
928
- },
929
- return_none: true
930
- },
931
- // @新AJAX
932
- 'AJAXテキスト取得': {
933
- type: 'func',
934
- josi: [['から']],
935
- pure: true,
936
- asyncFn: true,
937
- fn: async function (url, sys) {
938
- let options = sys.__v0['AJAXオプション'];
939
- if (options === '') {
940
- options = { method: 'GET' };
941
- }
942
- const res = await fetch(url, options);
943
- const txt = await res.text();
944
- return txt;
945
- },
946
- return_none: false
947
- },
948
- 'AJAX_JSON取得': {
949
- type: 'func',
950
- josi: [['から']],
951
- pure: true,
952
- asyncFn: true,
953
- fn: async function (url, sys) {
954
- let options = sys.__v0['AJAXオプション'];
955
- if (options === '') {
956
- options = { method: 'GET' };
957
- }
958
- const res = await fetch(url, options);
959
- const txt = await res.json();
960
- return txt;
961
- },
962
- return_none: false
963
- },
964
- // @文字コード
965
- '文字コード変換サポート判定': {
966
- type: 'func',
967
- josi: [['の', 'を']],
968
- pure: true,
969
- fn: function (code, sys) {
970
- return iconv.encodingExists(code);
971
- }
972
- },
973
- 'SJIS変換': {
974
- type: 'func',
975
- josi: [['に', 'へ', 'を']],
976
- pure: true,
977
- fn: function (str, sys) {
978
- // iconv.skipDecodeWarning = true
979
- return iconv.encode(str, 'Shift_JIS');
980
- }
981
- },
982
- 'SJIS取得': {
983
- type: 'func',
984
- josi: [['から', 'を', 'で']],
985
- pure: true,
986
- fn: function (buf, sys) {
987
- // iconv.skipDecodeWarning = true
988
- return iconv.decode(Buffer.from(buf), 'sjis');
989
- }
990
- },
991
- 'エンコーディング変換': {
992
- type: 'func',
993
- josi: [['を'], ['へ', 'で']],
994
- pure: true,
995
- fn: function (s, code, sys) {
996
- // iconv.skipDecodeWarning = true
997
- return iconv.encode(s, code);
998
- }
999
- },
1000
- 'エンコーディング取得': {
1001
- type: 'func',
1002
- josi: [['を'], ['から', 'で']],
1003
- pure: true,
1004
- fn: function (buf, code, sys) {
1005
- // iconv.skipDecodeWarning = true
1006
- return iconv.decode(Buffer.from(buf), code);
1007
- }
1008
- },
1009
- // @ハッシュ関数
1010
- 'ハッシュ関数一覧取得': {
1011
- type: 'func',
1012
- josi: [],
1013
- pure: true,
1014
- fn: function (sys) {
1015
- return crypto.getHashes();
1016
- }
1017
- },
1018
- 'ハッシュ値計算': {
1019
- type: 'func',
1020
- josi: [['を'], ['の'], ['で']],
1021
- pure: true,
1022
- fn: function (s, alg, enc, sys) {
1023
- const hashsum = crypto.createHash(alg);
1024
- hashsum.update(s);
1025
- return hashsum.digest(enc);
1026
- }
1027
- }
1028
- };
1029
- // ローカル関数
1030
- function fileExists(f) {
1031
- try {
1032
- fs.statSync(f);
1033
- return true;
1034
- }
1035
- catch (err) {
1036
- return false;
1037
- }
1038
- }
1039
- function isDir(f) {
1040
- try {
1041
- const st = fs.statSync(f);
1042
- return st.isDirectory();
1043
- }
1044
- catch (err) {
1045
- return false;
1046
- }
1047
- }
1
+ /**
2
+ * file: plugin_node.mjs
3
+ * node.js のためのプラグイン
4
+ */
5
+ import fs from 'fs';
6
+ import fse from 'fs-extra';
7
+ import fetch from 'node-fetch';
8
+ import { exec, execSync } from 'child_process';
9
+ import path from 'path';
10
+ import iconv from 'iconv-lite';
11
+ import opener from 'opener';
12
+ import assert from 'assert';
13
+ // 「標準入力取得時」「尋」で利用
14
+ import readline from 'readline';
15
+ // ハッシュ関数で利用
16
+ import crypto from 'crypto';
17
+ import os from 'os';
18
+ export default {
19
+ '初期化': {
20
+ type: 'func',
21
+ josi: [],
22
+ pure: true,
23
+ fn: function (sys) {
24
+ sys.__getBinPath = (tool) => {
25
+ let fpath = tool;
26
+ if (process.platform === 'win32') {
27
+ if (!fileExists(tool)) {
28
+ const nodeDir = path.dirname(process.argv[0]);
29
+ const root = path.resolve(path.join(nodeDir, '..'));
30
+ fpath = path.join(root, 'bin', tool + '.exe');
31
+ if (fileExists(fpath)) {
32
+ return `"${fpath}"`;
33
+ }
34
+ return tool;
35
+ }
36
+ }
37
+ return fpath;
38
+ };
39
+ sys.__getBokanPath = () => {
40
+ let nakofile;
41
+ const cmd = path.basename(process.argv[1]);
42
+ if (cmd.indexOf('cnako3') < 0) {
43
+ nakofile = process.argv[1];
44
+ }
45
+ else {
46
+ nakofile = process.argv[2];
47
+ }
48
+ return path.dirname(path.resolve(nakofile));
49
+ };
50
+ sys.__v0['コマンドライン'] = process.argv;
51
+ sys.__v0['ナデシコランタイムパス'] = process.argv[0];
52
+ sys.__v0['ナデシコランタイム'] = path.basename(process.argv[0]);
53
+ sys.__v0['母艦パス'] = sys.__getBokanPath();
54
+ sys.__v0['AJAX:ONERROR'] = null;
55
+ }
56
+ },
57
+ // @ファイル入出力
58
+ '開': {
59
+ type: 'func',
60
+ josi: [['を', 'から']],
61
+ pure: true,
62
+ fn: function (s) {
63
+ return fs.readFileSync(s, 'utf-8');
64
+ }
65
+ },
66
+ '読': {
67
+ type: 'func',
68
+ josi: [['を', 'から']],
69
+ pure: false,
70
+ fn: function (s, sys) {
71
+ return sys.__exec('開', [s]);
72
+ }
73
+ },
74
+ 'バイナリ読': {
75
+ type: 'func',
76
+ josi: [['を', 'から']],
77
+ pure: true,
78
+ fn: function (s, sys) {
79
+ return fs.readFileSync(s);
80
+ }
81
+ },
82
+ '保存': {
83
+ type: 'func',
84
+ josi: [['を'], ['へ', 'に']],
85
+ pure: true,
86
+ fn: function (s, f) {
87
+ // Buffer?
88
+ if (typeof s === 'string') {
89
+ fs.writeFileSync(f, s, 'utf-8');
90
+ }
91
+ else {
92
+ fs.writeFileSync(f, s);
93
+ }
94
+ },
95
+ return_none: true
96
+ },
97
+ 'SJISファイル読': {
98
+ type: 'func',
99
+ josi: [['を', 'から']],
100
+ pure: true,
101
+ fn: function (s, sys) {
102
+ // iconv.skipDecodeWarning = true
103
+ const buf = fs.readFileSync(s);
104
+ const text = iconv.decode(Buffer.from(buf), 'sjis');
105
+ return text;
106
+ }
107
+ },
108
+ 'SJISファイル保存': {
109
+ type: 'func',
110
+ josi: [['を'], ['へ', 'に']],
111
+ pure: true,
112
+ fn: function (s, f, sys) {
113
+ // iconv.skipDecodeWarning = true
114
+ const buf = iconv.encode(s, 'Shift_JIS');
115
+ fs.writeFileSync(f, buf);
116
+ },
117
+ return_none: true
118
+ },
119
+ '起動待機': {
120
+ type: 'func',
121
+ josi: [['を']],
122
+ pure: true,
123
+ fn: function (s) {
124
+ const r = execSync(s);
125
+ return r.toString();
126
+ }
127
+ },
128
+ '起動': {
129
+ type: 'func',
130
+ josi: [['を']],
131
+ pure: true,
132
+ fn: function (s) {
133
+ exec(s, (err, stdout, stderr) => {
134
+ if (err) {
135
+ console.error(stderr);
136
+ }
137
+ else if (stdout) {
138
+ console.log(stdout);
139
+ }
140
+ });
141
+ }
142
+ },
143
+ '起動時': {
144
+ type: 'func',
145
+ josi: [['で'], ['を']],
146
+ pure: true,
147
+ fn: function (callback, s, sys) {
148
+ exec(s, (err, stdout, stderr) => {
149
+ if (err) {
150
+ throw new Error(stderr);
151
+ }
152
+ else {
153
+ callback(stdout);
154
+ }
155
+ });
156
+ }
157
+ },
158
+ 'ブラウザ起動': {
159
+ type: 'func',
160
+ josi: [['を']],
161
+ pure: true,
162
+ fn: function (url) {
163
+ opener(url);
164
+ }
165
+ },
166
+ 'ファイル列挙': {
167
+ type: 'func',
168
+ josi: [['の', 'を', 'で']],
169
+ pure: true,
170
+ fn: function (s) {
171
+ if (s.indexOf('*') >= 0) { // ワイルドカードがある場合
172
+ const searchPath = path.dirname(s);
173
+ const mask1 = path.basename(s)
174
+ .replace(/\./g, '\\.')
175
+ .replace(/\*/g, '.*');
176
+ const mask2 = (mask1.indexOf(';') < 0)
177
+ ? mask1 + '$'
178
+ : '(' + mask1.replace(/;/g, '|') + ')$';
179
+ const maskRE = new RegExp(mask2, 'i');
180
+ const list = fs.readdirSync(searchPath);
181
+ return list.filter((n) => maskRE.test(n));
182
+ }
183
+ else {
184
+ return fs.readdirSync(s);
185
+ }
186
+ }
187
+ },
188
+ '全ファイル列挙': {
189
+ type: 'func',
190
+ josi: [['の', 'を', 'で']],
191
+ pure: true,
192
+ fn: function (s) {
193
+ /** @type {string[]} */
194
+ const result = [];
195
+ // ワイルドカードの有無を確認
196
+ let mask = '.*';
197
+ let basepath = s;
198
+ if (s.indexOf('*') >= 0) {
199
+ basepath = path.dirname(s);
200
+ const mask1 = path.basename(s)
201
+ .replace(/\./g, '\\.')
202
+ .replace(/\*/g, '.*');
203
+ mask = (mask1.indexOf(';') < 0)
204
+ ? mask1 + '$'
205
+ : '(' + mask1.replace(/;/g, '|') + ')$';
206
+ }
207
+ basepath = path.resolve(basepath);
208
+ const maskRE = new RegExp(mask, 'i');
209
+ // 再帰関数を定義
210
+ const enumR = (base) => {
211
+ const list = fs.readdirSync(base);
212
+ for (const f of list) {
213
+ if (f === '.' || f === '..') {
214
+ continue;
215
+ }
216
+ const fullpath = path.join(base, f);
217
+ let st = null;
218
+ try {
219
+ st = fs.statSync(fullpath);
220
+ }
221
+ catch (e) {
222
+ st = null;
223
+ }
224
+ if (st == null) {
225
+ continue;
226
+ }
227
+ if (st.isDirectory()) {
228
+ enumR(fullpath);
229
+ continue;
230
+ }
231
+ if (maskRE.test(f)) {
232
+ result.push(fullpath);
233
+ }
234
+ }
235
+ };
236
+ // 検索実行
237
+ enumR(basepath);
238
+ return result;
239
+ }
240
+ },
241
+ '存在': {
242
+ type: 'func',
243
+ josi: [['が', 'の']],
244
+ pure: true,
245
+ fn: function (path) {
246
+ return fileExists(path);
247
+ }
248
+ },
249
+ 'フォルダ存在': {
250
+ type: 'func',
251
+ josi: [['が', 'の']],
252
+ pure: true,
253
+ fn: function (path) {
254
+ return isDir(path);
255
+ }
256
+ },
257
+ 'フォルダ作成': {
258
+ type: 'func',
259
+ josi: [['の', 'を', 'に', 'へ']],
260
+ pure: true,
261
+ fn: function (path) {
262
+ return fse.mkdirpSync(path);
263
+ }
264
+ },
265
+ 'ファイルコピー': {
266
+ type: 'func',
267
+ josi: [['から', 'を'], ['に', 'へ']],
268
+ pure: true,
269
+ fn: function (a, b, sys) {
270
+ return fse.copySync(a, b);
271
+ }
272
+ },
273
+ 'ファイルコピー時': {
274
+ type: 'func',
275
+ josi: [['で'], ['から', 'を'], ['に', 'へ']],
276
+ pure: true,
277
+ fn: function (callback, a, b, sys) {
278
+ return fse.copy(a, b, (err) => {
279
+ if (err) {
280
+ throw new Error('ファイルコピー時:' + err);
281
+ }
282
+ callback();
283
+ });
284
+ },
285
+ return_none: false
286
+ },
287
+ 'ファイル移動': {
288
+ type: 'func',
289
+ josi: [['から', 'を'], ['に', 'へ']],
290
+ pure: true,
291
+ fn: function (a, b, sys) {
292
+ return fse.moveSync(a, b);
293
+ }
294
+ },
295
+ 'ファイル移動時': {
296
+ type: 'func',
297
+ josi: [['で'], ['から', 'を'], ['に', 'へ']],
298
+ pure: true,
299
+ fn: function (callback, a, b, sys) {
300
+ fse.move(a, b, (err) => {
301
+ if (err) {
302
+ throw new Error('ファイル移動時:' + err);
303
+ }
304
+ callback();
305
+ });
306
+ },
307
+ return_none: false
308
+ },
309
+ 'ファイル削除': {
310
+ type: 'func',
311
+ josi: [['の', 'を']],
312
+ pure: true,
313
+ fn: function (path, sys) {
314
+ return fse.removeSync(path);
315
+ }
316
+ },
317
+ 'ファイル削除時': {
318
+ type: 'func',
319
+ josi: [['で'], ['の', 'を']],
320
+ pure: true,
321
+ fn: function (callback, path, sys) {
322
+ return fse.remove(path, (err) => {
323
+ if (err) {
324
+ throw new Error('ファイル削除時:' + err);
325
+ }
326
+ callback();
327
+ });
328
+ },
329
+ return_none: false
330
+ },
331
+ 'ファイル情報取得': {
332
+ type: 'func',
333
+ josi: [['の', 'から']],
334
+ pure: true,
335
+ fn: function (path, sys) {
336
+ return fs.statSync(path);
337
+ }
338
+ },
339
+ 'ファイルサイズ取得': {
340
+ type: 'func',
341
+ josi: [['の', 'から']],
342
+ pure: true,
343
+ fn: function (path, sys) {
344
+ const st = fs.statSync(path);
345
+ if (!st) {
346
+ return -1;
347
+ }
348
+ return st.size;
349
+ }
350
+ },
351
+ // @パス操作
352
+ 'ファイル名抽出': {
353
+ type: 'func',
354
+ josi: [['から', 'の']],
355
+ pure: true,
356
+ fn: function (s) {
357
+ return path.basename(s);
358
+ }
359
+ },
360
+ 'パス抽出': {
361
+ type: 'func',
362
+ josi: [['から', 'の']],
363
+ pure: true,
364
+ fn: function (s) {
365
+ return path.dirname(s);
366
+ }
367
+ },
368
+ '絶対パス変換': {
369
+ type: 'func',
370
+ josi: [['を', 'の']],
371
+ pure: true,
372
+ fn: function (a) {
373
+ return path.resolve(a);
374
+ }
375
+ },
376
+ '相対パス展開': {
377
+ type: 'func',
378
+ josi: [['を'], ['で']],
379
+ pure: true,
380
+ fn: function (a, b) {
381
+ return path.resolve(path.join(a, b));
382
+ }
383
+ },
384
+ // @フォルダ取得
385
+ 'カレントディレクトリ取得': {
386
+ type: 'func',
387
+ josi: [],
388
+ pure: true,
389
+ fn: function () {
390
+ const cwd = process.cwd();
391
+ return path.resolve(cwd);
392
+ }
393
+ },
394
+ 'カレントディレクトリ変更': {
395
+ type: 'func',
396
+ josi: [['に', 'へ']],
397
+ pure: true,
398
+ fn: function (dir) {
399
+ process.chdir(dir);
400
+ },
401
+ return_none: true
402
+ },
403
+ '作業フォルダ取得': {
404
+ type: 'func',
405
+ josi: [],
406
+ pure: true,
407
+ fn: function () {
408
+ const cwd = process.cwd();
409
+ return path.resolve(cwd);
410
+ }
411
+ },
412
+ '作業フォルダ変更': {
413
+ type: 'func',
414
+ josi: [['に', 'へ']],
415
+ pure: true,
416
+ fn: function (dir) {
417
+ process.chdir(dir);
418
+ },
419
+ return_none: true
420
+ },
421
+ 'ホームディレクトリ取得': {
422
+ type: 'func',
423
+ josi: [],
424
+ pure: true,
425
+ fn: function () {
426
+ return process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME'];
427
+ }
428
+ },
429
+ 'デスクトップ': {
430
+ type: 'func',
431
+ josi: [],
432
+ pure: false,
433
+ fn: function (sys) {
434
+ const home = sys.__exec('ホームディレクトリ取得', [sys]);
435
+ return path.join(home, 'Desktop');
436
+ }
437
+ },
438
+ 'マイドキュメント': {
439
+ type: 'func',
440
+ josi: [],
441
+ pure: false,
442
+ fn: function (sys) {
443
+ const home = sys.__exec('ホームディレクトリ取得', [sys]);
444
+ return path.join(home, 'Documents');
445
+ }
446
+ },
447
+ '母艦パス': { type: 'const', value: '' },
448
+ '母艦パス取得': {
449
+ type: 'func',
450
+ josi: [],
451
+ pure: true,
452
+ fn: function (sys) {
453
+ return sys.__getBokanPath();
454
+ }
455
+ },
456
+ // @環境変数
457
+ '環境変数取得': {
458
+ type: 'func',
459
+ josi: [['の']],
460
+ pure: true,
461
+ fn: function (s) {
462
+ return process.env[s];
463
+ }
464
+ },
465
+ '環境変数一覧取得': {
466
+ type: 'func',
467
+ josi: [],
468
+ pure: true,
469
+ fn: function () {
470
+ return process.env;
471
+ }
472
+ },
473
+ // @圧縮・解凍
474
+ '圧縮解凍ツールパス': { type: 'const', value: '7z' },
475
+ '圧縮解凍ツールパス変更': {
476
+ type: 'func',
477
+ josi: [['に', 'へ']],
478
+ pure: true,
479
+ fn: function (v, sys) {
480
+ sys.__v0['圧縮解凍ツールパス'] = v;
481
+ },
482
+ return_none: true
483
+ },
484
+ '解凍': {
485
+ type: 'func',
486
+ josi: [['を', 'から'], ['に', 'へ']],
487
+ pure: true,
488
+ fn: function (a, b, sys) {
489
+ const tpath = sys.__getBinPath(sys.__v0['圧縮解凍ツールパス']);
490
+ const cmd = `${tpath} x "${a}" -o"${b}" -y`;
491
+ execSync(cmd);
492
+ return true;
493
+ }
494
+ },
495
+ '解凍時': {
496
+ type: 'func',
497
+ josi: [['で'], ['を', 'から'], ['に', 'へ']],
498
+ pure: true,
499
+ fn: function (callback, a, b, sys) {
500
+ const tpath = sys.__getBinPath(sys.__v0['圧縮解凍ツールパス']);
501
+ const cmd = `${tpath} x "${a}" -o"${b}" -y`;
502
+ exec(cmd, (err, stdout, stderr) => {
503
+ if (err) {
504
+ throw new Error('[エラー]『解凍時』' + err);
505
+ }
506
+ callback(stdout);
507
+ });
508
+ },
509
+ return_none: false
510
+ },
511
+ '圧縮': {
512
+ type: 'func',
513
+ josi: [['を', 'から'], ['に', 'へ']],
514
+ pure: true,
515
+ fn: function (a, b, sys) {
516
+ const tpath = sys.__getBinPath(sys.__v0['圧縮解凍ツールパス']);
517
+ const cmd = `${tpath} a -r "${b}" "${a}" -y`;
518
+ execSync(cmd);
519
+ return true;
520
+ }
521
+ },
522
+ '圧縮時': {
523
+ type: 'func',
524
+ josi: [['で'], ['を', 'から'], ['に', 'へ']],
525
+ pure: true,
526
+ fn: function (callback, a, b, sys) {
527
+ const tpath = sys.__getBinPath(sys.__v0['圧縮解凍ツールパス']);
528
+ const cmd = `${tpath} a -r "${b}" "${a}" -y`;
529
+ exec(cmd, (err, stdout, stderr) => {
530
+ if (err) {
531
+ throw new Error('[エラー]『圧縮時』' + err);
532
+ }
533
+ callback(stdout);
534
+ });
535
+ },
536
+ return_none: true
537
+ },
538
+ // @Nodeプロセス
539
+ '終': {
540
+ type: 'func',
541
+ josi: [],
542
+ pure: true,
543
+ fn: function () {
544
+ process.exit();
545
+ },
546
+ return_none: true
547
+ },
548
+ '強制終了時': {
549
+ type: 'func',
550
+ josi: [['を']],
551
+ pure: true,
552
+ fn: function (func, sys) {
553
+ if (typeof (func) === 'string') {
554
+ func = sys.__findFunc(func, '強制終了時');
555
+ }
556
+ process.on('SIGINT', (signal) => {
557
+ const flag = func(sys);
558
+ if (flag) {
559
+ process.exit();
560
+ }
561
+ });
562
+ },
563
+ return_none: true
564
+ },
565
+ '終了': {
566
+ type: 'func',
567
+ josi: [],
568
+ pure: false,
569
+ fn: function (sys) {
570
+ sys.__exec('終', []);
571
+ },
572
+ return_none: true
573
+ },
574
+ 'OS取得': {
575
+ type: 'func',
576
+ josi: [],
577
+ pure: true,
578
+ fn: function (sys) {
579
+ return process.platform;
580
+ }
581
+ },
582
+ 'OSアーキテクチャ取得': {
583
+ type: 'func',
584
+ josi: [],
585
+ pure: true,
586
+ fn: function (sys) {
587
+ return process.arch;
588
+ }
589
+ },
590
+ // @コマンドラインと標準入出力
591
+ 'コマンドライン': { type: 'const', value: '' },
592
+ 'ナデシコランタイム': { type: 'const', value: '' },
593
+ 'ナデシコランタイムパス': { type: 'const', value: '' },
594
+ '標準入力取得時': {
595
+ type: 'func',
596
+ josi: [['を']],
597
+ pure: true,
598
+ fn: function (callback) {
599
+ const reader = readline.createInterface({
600
+ input: process.stdin,
601
+ output: process.stdout
602
+ });
603
+ reader.on('line', function (line) {
604
+ callback(line);
605
+ });
606
+ }
607
+ },
608
+ '尋': {
609
+ type: 'func',
610
+ josi: [['と', 'を']],
611
+ pure: true,
612
+ asyncFn: true,
613
+ fn: function (msg) {
614
+ return new Promise((resolve, reject) => {
615
+ const rl = readline.createInterface(process.stdin, process.stdout);
616
+ if (!rl) {
617
+ reject(new Error('『尋』命令で標準入力が取得できません'));
618
+ return;
619
+ }
620
+ rl.question(msg, (buf) => {
621
+ rl.close();
622
+ if (buf && buf.match(/^[0-9.]+$/)) {
623
+ buf = parseFloat(buf);
624
+ }
625
+ resolve(buf);
626
+ });
627
+ });
628
+ }
629
+ },
630
+ // @テスト
631
+ 'ASSERT等': {
632
+ type: 'func',
633
+ josi: [['と'], ['が']],
634
+ pure: true,
635
+ fn: function (a, b, sys) {
636
+ assert.strictEqual(a, b);
637
+ }
638
+ },
639
+ // @ネットワーク
640
+ '自分IPアドレス取得': {
641
+ type: 'func',
642
+ josi: [],
643
+ pure: true,
644
+ fn: function (sys) {
645
+ const nif = os.networkInterfaces();
646
+ if (!nif) {
647
+ throw new Error('『自分IPアドレス取得』でネットワークのインターフェイスが種畜できません。');
648
+ }
649
+ /**
650
+ * @type {string[]}
651
+ */
652
+ const result = [];
653
+ for (const dev in nif) {
654
+ const n = nif[dev];
655
+ if (!n) {
656
+ continue;
657
+ }
658
+ n.forEach((detail) => {
659
+ if (detail.family === 'IPv4') {
660
+ result.push(detail.address);
661
+ }
662
+ });
663
+ }
664
+ return result;
665
+ }
666
+ },
667
+ '自分IPV6アドレス取得': {
668
+ type: 'func',
669
+ josi: [],
670
+ pure: true,
671
+ fn: function (sys) {
672
+ const nif = os.networkInterfaces();
673
+ if (!nif) {
674
+ throw new Error('『自分IPアドレス取得』でネットワークのインターフェイスが種畜できません。');
675
+ }
676
+ const result = [];
677
+ for (const dev in nif) {
678
+ const n = nif[dev];
679
+ if (!n) {
680
+ continue;
681
+ }
682
+ n.forEach((detail) => {
683
+ if (detail.family === 'IPv6') {
684
+ result.push(detail.address);
685
+ }
686
+ });
687
+ }
688
+ return result;
689
+ }
690
+ },
691
+ // @Ajax
692
+ 'AJAX送信時': {
693
+ type: 'func',
694
+ josi: [['の'], ['まで', 'へ', 'に']],
695
+ pure: true,
696
+ fn: function (callback, url, sys) {
697
+ let options = sys.__v0['AJAXオプション'];
698
+ if (options === '') {
699
+ options = { method: 'GET' };
700
+ }
701
+ fetch(url, options).then((res) => {
702
+ return res.text();
703
+ }).then((text) => {
704
+ sys.__v0['対象'] = text;
705
+ callback(text);
706
+ }).catch((err) => {
707
+ console.log('[fetch.error]', err);
708
+ throw err;
709
+ });
710
+ },
711
+ return_none: true
712
+ },
713
+ 'AJAX受信時': {
714
+ type: 'func',
715
+ josi: [['で'], ['から', 'を']],
716
+ pure: true,
717
+ fn: function (callback, url, sys) {
718
+ sys.__exec('AJAX送信時', [callback, url, sys]);
719
+ },
720
+ return_none: true
721
+ },
722
+ 'GET送信時': {
723
+ type: 'func',
724
+ josi: [['の'], ['まで', 'へ', 'に']],
725
+ pure: false,
726
+ fn: function (callback, url, sys) {
727
+ sys.__exec('AJAX送信時', [callback, url, sys]);
728
+ },
729
+ return_none: true
730
+ },
731
+ 'POST送信時': {
732
+ type: 'func',
733
+ josi: [['の'], ['まで', 'へ', 'に'], ['を']],
734
+ pure: true,
735
+ fn: function (callback, url, params, sys) {
736
+ const flist = [];
737
+ for (const key in params) {
738
+ const v = params[key];
739
+ const kv = encodeURIComponent(key) + '=' + encodeURIComponent(v);
740
+ flist.push(kv);
741
+ }
742
+ const bodyData = flist.join('&');
743
+ const options = {
744
+ method: 'POST',
745
+ headers: {
746
+ 'Content-Type': 'application/x-www-form-urlencoded'
747
+ },
748
+ body: bodyData
749
+ };
750
+ fetch(url, options).then((res) => {
751
+ return res.text();
752
+ }).then((text) => {
753
+ sys.__v0['対象'] = text;
754
+ callback(text);
755
+ }).catch((err) => {
756
+ sys.__v0['AJAX:ONERROR'](err);
757
+ });
758
+ }
759
+ },
760
+ 'POSTフォーム送信時': {
761
+ type: 'func',
762
+ josi: [['の'], ['まで', 'へ', 'に'], ['を']],
763
+ pure: true,
764
+ fn: function (callback, url, params, sys) {
765
+ const fd = new FormData();
766
+ for (const key in params) {
767
+ fd.set(key, params[key]);
768
+ }
769
+ const options = {
770
+ method: 'POST',
771
+ headers: {
772
+ 'Content-Type': 'multipart/form-data'
773
+ },
774
+ body: fd
775
+ };
776
+ fetch(url, options).then((res) => {
777
+ return res.text();
778
+ }).then((text) => {
779
+ sys.__v0['対象'] = text;
780
+ callback(text);
781
+ }).catch((err) => {
782
+ sys.__v0['AJAX:ONERROR'](err);
783
+ });
784
+ }
785
+ },
786
+ 'AJAX失敗時': {
787
+ type: 'func',
788
+ josi: [['の']],
789
+ pure: true,
790
+ fn: function (callback, sys) {
791
+ sys.__v0['AJAX:ONERROR'] = callback;
792
+ }
793
+ },
794
+ 'AJAXオプション': { type: 'const', value: '' },
795
+ 'AJAXオプション設定': {
796
+ type: 'func',
797
+ josi: [['に', 'へ', 'と']],
798
+ pure: true,
799
+ fn: function (option, sys) {
800
+ sys.__v0['AJAXオプション'] = option;
801
+ },
802
+ return_none: true
803
+ },
804
+ 'AJAX保障送信': {
805
+ type: 'func',
806
+ josi: [['まで', 'へ', 'に']],
807
+ pure: true,
808
+ fn: function (url, sys) {
809
+ let options = sys.__v0['AJAXオプション'];
810
+ if (options === '') {
811
+ options = { method: 'GET' };
812
+ }
813
+ return fetch(url, options);
814
+ },
815
+ return_none: false
816
+ },
817
+ 'HTTP保障取得': {
818
+ type: 'func',
819
+ josi: [['の', 'から', 'を']],
820
+ pure: true,
821
+ fn: function (url, sys) {
822
+ return sys.__exec('AJAX保障送信', [url, sys]);
823
+ },
824
+ return_none: false
825
+ },
826
+ 'GET保障送信': {
827
+ type: 'func',
828
+ josi: [['まで', 'へ', 'に']],
829
+ pure: true,
830
+ fn: function (url, sys) {
831
+ return sys.__exec('AJAX保障送信', [url, sys]);
832
+ },
833
+ return_none: false
834
+ },
835
+ 'POST保障送信': {
836
+ type: 'func',
837
+ josi: [['まで', 'へ', 'に'], ['を']],
838
+ pure: true,
839
+ fn: function (url, params, sys) {
840
+ const flist = [];
841
+ for (const key in params) {
842
+ const v = params[key];
843
+ const kv = encodeURIComponent(key) + '=' + encodeURIComponent(v);
844
+ flist.push(kv);
845
+ }
846
+ const bodyData = flist.join('&');
847
+ const options = {
848
+ method: 'POST',
849
+ headers: {
850
+ 'Content-Type': 'application/x-www-form-urlencoded'
851
+ },
852
+ body: bodyData
853
+ };
854
+ return fetch(url, options);
855
+ },
856
+ return_none: false
857
+ },
858
+ 'POSTフォーム保障送信': {
859
+ type: 'func',
860
+ josi: [['まで', 'へ', 'に'], ['を']],
861
+ pure: true,
862
+ fn: function (url, params, sys) {
863
+ const fd = new FormData();
864
+ for (const key in params) {
865
+ fd.set(key, params[key]);
866
+ }
867
+ const options = {
868
+ method: 'POST',
869
+ body: fd
870
+ };
871
+ return fetch(url, options);
872
+ },
873
+ return_none: false
874
+ },
875
+ 'AJAX内容取得': {
876
+ type: 'func',
877
+ josi: [['から'], ['で']],
878
+ pure: true,
879
+ fn: function (res, type, sys) {
880
+ type = type.toString().toUpperCase();
881
+ if (type === 'TEXT' || type === 'テキスト') {
882
+ return res.text();
883
+ }
884
+ else if (type === 'JSON') {
885
+ return res.json();
886
+ }
887
+ else if (type === 'BLOB') {
888
+ return res.blob();
889
+ }
890
+ else if (type === 'ARRAY' || type === '配列') {
891
+ return res.arrayBuffer();
892
+ }
893
+ else if (type === 'BODY' || type === '本体') {
894
+ return res.body;
895
+ }
896
+ return res.body();
897
+ },
898
+ return_none: false
899
+ },
900
+ 'AJAX受信': {
901
+ type: 'func',
902
+ josi: [['から', 'を']],
903
+ pure: true,
904
+ fn: function (url, sys) {
905
+ if (sys.__genMode !== '非同期モード') {
906
+ throw new Error('『AJAX受信』を使うには、プログラムの冒頭で「!非同期モード」と宣言してください。');
907
+ }
908
+ const sysenv = sys.setAsync(sys);
909
+ let options = sys.__v0['AJAXオプション'];
910
+ if (options === '') {
911
+ options = { method: 'GET' };
912
+ }
913
+ // fetch 実行
914
+ fetch(url, options).then((res) => {
915
+ if (res.ok) { // 成功したとき
916
+ return res.text();
917
+ }
918
+ else { // 失敗したとき
919
+ throw new Error('status=' + res.status);
920
+ }
921
+ }).then((text) => {
922
+ sys.__v0['対象'] = text;
923
+ sys.compAsync(sys, sysenv);
924
+ }).catch((err) => {
925
+ console.error('[AJAX受信のエラー]', err);
926
+ sys.__errorAsync(err, sys);
927
+ });
928
+ },
929
+ return_none: true
930
+ },
931
+ // @新AJAX
932
+ 'AJAXテキスト取得': {
933
+ type: 'func',
934
+ josi: [['から']],
935
+ pure: true,
936
+ asyncFn: true,
937
+ fn: async function (url, sys) {
938
+ let options = sys.__v0['AJAXオプション'];
939
+ if (options === '') {
940
+ options = { method: 'GET' };
941
+ }
942
+ const res = await fetch(url, options);
943
+ const txt = await res.text();
944
+ return txt;
945
+ },
946
+ return_none: false
947
+ },
948
+ 'AJAX_JSON取得': {
949
+ type: 'func',
950
+ josi: [['から']],
951
+ pure: true,
952
+ asyncFn: true,
953
+ fn: async function (url, sys) {
954
+ let options = sys.__v0['AJAXオプション'];
955
+ if (options === '') {
956
+ options = { method: 'GET' };
957
+ }
958
+ const res = await fetch(url, options);
959
+ const txt = await res.json();
960
+ return txt;
961
+ },
962
+ return_none: false
963
+ },
964
+ // @文字コード
965
+ '文字コード変換サポート判定': {
966
+ type: 'func',
967
+ josi: [['の', 'を']],
968
+ pure: true,
969
+ fn: function (code, sys) {
970
+ return iconv.encodingExists(code);
971
+ }
972
+ },
973
+ 'SJIS変換': {
974
+ type: 'func',
975
+ josi: [['に', 'へ', 'を']],
976
+ pure: true,
977
+ fn: function (str, sys) {
978
+ // iconv.skipDecodeWarning = true
979
+ return iconv.encode(str, 'Shift_JIS');
980
+ }
981
+ },
982
+ 'SJIS取得': {
983
+ type: 'func',
984
+ josi: [['から', 'を', 'で']],
985
+ pure: true,
986
+ fn: function (buf, sys) {
987
+ // iconv.skipDecodeWarning = true
988
+ return iconv.decode(Buffer.from(buf), 'sjis');
989
+ }
990
+ },
991
+ 'エンコーディング変換': {
992
+ type: 'func',
993
+ josi: [['を'], ['へ', 'で']],
994
+ pure: true,
995
+ fn: function (s, code, sys) {
996
+ // iconv.skipDecodeWarning = true
997
+ return iconv.encode(s, code);
998
+ }
999
+ },
1000
+ 'エンコーディング取得': {
1001
+ type: 'func',
1002
+ josi: [['を'], ['から', 'で']],
1003
+ pure: true,
1004
+ fn: function (buf, code, sys) {
1005
+ // iconv.skipDecodeWarning = true
1006
+ return iconv.decode(Buffer.from(buf), code);
1007
+ }
1008
+ },
1009
+ // @ハッシュ関数
1010
+ 'ハッシュ関数一覧取得': {
1011
+ type: 'func',
1012
+ josi: [],
1013
+ pure: true,
1014
+ fn: function (sys) {
1015
+ return crypto.getHashes();
1016
+ }
1017
+ },
1018
+ 'ハッシュ値計算': {
1019
+ type: 'func',
1020
+ josi: [['を'], ['の'], ['で']],
1021
+ pure: true,
1022
+ fn: function (s, alg, enc, sys) {
1023
+ const hashsum = crypto.createHash(alg);
1024
+ hashsum.update(s);
1025
+ return hashsum.digest(enc);
1026
+ }
1027
+ }
1028
+ };
1029
+ // ローカル関数
1030
+ function fileExists(f) {
1031
+ try {
1032
+ fs.statSync(f);
1033
+ return true;
1034
+ }
1035
+ catch (err) {
1036
+ return false;
1037
+ }
1038
+ }
1039
+ function isDir(f) {
1040
+ try {
1041
+ const st = fs.statSync(f);
1042
+ return st.isDirectory();
1043
+ }
1044
+ catch (err) {
1045
+ return false;
1046
+ }
1047
+ }