nadesiko3 3.3.49 → 3.3.52

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