nadesiko3 3.3.45 → 3.3.49

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 (329) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +143 -132
  3. package/batch/browsers.template.md +3 -3
  4. package/batch/build_browsers.nako3 +72 -72
  5. package/batch/build_command.nako3 +44 -44
  6. package/batch/build_nako_version.nako3 +42 -42
  7. package/batch/calc_hash.nako3 +29 -29
  8. package/batch/cmd_txt2json.nako3 +74 -74
  9. package/batch/command.txt +270 -338
  10. package/batch/command_nakopad.txt +9 -69
  11. package/batch/download-extlib.nako3 +43 -43
  12. package/batch/gen_command_nakopad.nako3 +57 -57
  13. package/batch/jsplugin2text.nako3 +285 -285
  14. package/batch/pickup_command.nako3 +110 -110
  15. package/batch/pickup_reserved_words.nako3 +11 -11
  16. package/batch/publish_version.nako3 +46 -46
  17. package/batch/show_agents.js +14 -14
  18. package/batch/turtle2js.nako3 +21 -21
  19. package/bin/cnako3 +10 -10
  20. package/core/.editorconfig +6 -0
  21. package/core/.eslintrc.cjs +33 -0
  22. package/core/.github/dependabot.yml +7 -0
  23. package/core/.github/workflows/nodejs.yml +37 -0
  24. package/core/.github/workflows/super-linter.yml +61 -0
  25. package/core/.github/workflows/textlint.yml +199 -0
  26. package/core/LICENSE +21 -0
  27. package/core/README.md +66 -0
  28. package/core/batch/build_nako_version.nako3 +42 -0
  29. package/core/command/snako.mjs +105 -0
  30. package/core/command/snako.mts +116 -0
  31. package/core/index.mjs +21 -0
  32. package/core/index.mts +21 -0
  33. package/core/package.json +47 -0
  34. package/core/sample/hello.nako3 +7 -0
  35. package/core/sample/hoge.mjs +4 -0
  36. package/core/sample/hoge.mts +6 -0
  37. package/core/src/nako3.mjs +858 -0
  38. package/core/src/nako3.mts +967 -0
  39. package/core/src/nako_colors.mjs +78 -0
  40. package/core/src/nako_colors.mts +86 -0
  41. package/core/src/nako_core_version.mjs +8 -0
  42. package/core/src/nako_core_version.mts +19 -0
  43. package/core/src/nako_csv.mjs +185 -0
  44. package/core/src/nako_csv.mts +188 -0
  45. package/core/src/nako_errors.mjs +173 -0
  46. package/core/src/nako_errors.mts +197 -0
  47. package/core/src/nako_from_dncl.mjs +255 -0
  48. package/core/src/nako_from_dncl.mts +250 -0
  49. package/core/src/nako_gen.mjs +1648 -0
  50. package/core/src/nako_gen.mts +1719 -0
  51. package/core/src/nako_gen_async.mjs +1659 -0
  52. package/core/src/nako_gen_async.mts +1732 -0
  53. package/core/src/nako_global.mjs +107 -0
  54. package/core/src/nako_global.mts +138 -0
  55. package/core/src/nako_indent.mjs +445 -0
  56. package/core/src/nako_indent.mts +492 -0
  57. package/core/src/nako_josi_list.mjs +38 -0
  58. package/core/src/nako_josi_list.mts +45 -0
  59. package/core/src/nako_lex_rules.mjs +253 -0
  60. package/core/src/nako_lex_rules.mts +260 -0
  61. package/core/src/nako_lexer.mjs +609 -0
  62. package/core/src/nako_lexer.mts +612 -0
  63. package/core/src/nako_logger.mjs +199 -0
  64. package/core/src/nako_logger.mts +232 -0
  65. package/core/src/nako_parser3.mjs +2439 -0
  66. package/core/src/nako_parser3.mts +2195 -0
  67. package/core/src/nako_parser_base.mjs +370 -0
  68. package/core/src/nako_parser_base.mts +370 -0
  69. package/core/src/nako_parser_const.mjs +37 -0
  70. package/core/src/nako_parser_const.mts +37 -0
  71. package/core/src/nako_prepare.mjs +304 -0
  72. package/core/src/nako_prepare.mts +315 -0
  73. package/core/src/nako_reserved_words.mjs +38 -0
  74. package/core/src/nako_reserved_words.mts +38 -0
  75. package/core/src/nako_source_mapping.mjs +207 -0
  76. package/core/src/nako_source_mapping.mts +262 -0
  77. package/core/src/nako_test.mjs +37 -0
  78. package/core/src/nako_types.mjs +25 -0
  79. package/core/src/nako_types.mts +151 -0
  80. package/core/src/plugin_csv.mjs +49 -0
  81. package/core/src/plugin_csv.mts +50 -0
  82. package/core/src/plugin_math.mjs +328 -0
  83. package/core/src/plugin_math.mts +326 -0
  84. package/core/src/plugin_promise.mjs +91 -0
  85. package/core/src/plugin_promise.mts +91 -0
  86. package/core/src/plugin_system.mjs +2832 -0
  87. package/core/src/plugin_system.mts +2690 -0
  88. package/core/src/plugin_test.mjs +34 -0
  89. package/core/src/plugin_test.mts +34 -0
  90. package/core/test/array_test.mjs +34 -0
  91. package/core/test/basic_test.mjs +344 -0
  92. package/core/test/calc_test.mjs +140 -0
  93. package/core/test/core_module_test.mjs +23 -0
  94. package/core/test/debug_test.mjs +16 -0
  95. package/core/test/dncl_test.mjs +94 -0
  96. package/core/test/error_message_test.mjs +210 -0
  97. package/core/test/error_test.mjs +16 -0
  98. package/core/test/flow_test.mjs +373 -0
  99. package/core/test/func_call.mjs +160 -0
  100. package/core/test/func_test.mjs +149 -0
  101. package/core/test/indent_test.mjs +364 -0
  102. package/core/test/lex_test.mjs +168 -0
  103. package/core/test/literal_test.mjs +73 -0
  104. package/core/test/nako_lexer_test.mjs +35 -0
  105. package/core/test/nako_logger_test.mjs +76 -0
  106. package/core/test/nako_logger_test.mts +78 -0
  107. package/core/test/plugin_csv_test.mjs +38 -0
  108. package/core/test/plugin_promise_test.mjs +18 -0
  109. package/core/test/plugin_system_test.mjs +630 -0
  110. package/core/test/prepare_test.mjs +96 -0
  111. package/core/test/re_test.mjs +22 -0
  112. package/core/test/side_effects_test.mjs +92 -0
  113. package/core/test/variable_scope_test.mjs +149 -0
  114. package/core/tsconfig.json +101 -0
  115. package/demo/ace_editor.html +89 -89
  116. package/demo/ace_editor_tabs.html +161 -161
  117. package/demo/basic.html +71 -71
  118. package/demo/browsers.html +9 -10
  119. package/demo/css/basic.css +3 -3
  120. package/demo/css/common.css +157 -157
  121. package/demo/css/editor.css +8 -8
  122. package/demo/css/flow.css +3 -3
  123. package/demo/css/index.css +3 -3
  124. package/demo/flow.html +98 -98
  125. package/demo/graph.html +53 -53
  126. package/demo/image/nakopad-icon256.png +0 -0
  127. package/demo/index.html +133 -133
  128. package/demo/js/common.js +17 -17
  129. package/demo/js/turtle3d_test.js +44 -44
  130. package/demo/js/turtle_test.js +45 -45
  131. package/demo/nako3/calc.nako3 +4 -4
  132. package/demo/runscript.html +47 -47
  133. package/demo/runscript2.html +33 -33
  134. package/demo/runscript3.html +35 -35
  135. package/demo/runscript4.html +33 -33
  136. package/demo/turtle.html +58 -58
  137. package/demo/turtle2.html +141 -141
  138. package/demo/turtle3.html +279 -279
  139. package/demo/turtle3d.html +58 -58
  140. package/demo/turtle3d2.html +107 -107
  141. package/demo/version.html +24 -24
  142. package/doc/SETUP.md +157 -157
  143. package/doc/about.md +17 -17
  144. package/doc/browsers.md +26 -26
  145. package/doc/docgen.md +21 -21
  146. package/doc/editor.md +44 -44
  147. package/doc/files.md +39 -39
  148. package/doc/plugins.md +234 -234
  149. package/doc/release.md +79 -79
  150. package/doc/textlint.md +43 -43
  151. package/doc/win32.md +57 -57
  152. package/package.json +195 -192
  153. package/release/_hash.txt +28 -28
  154. package/release/_script-tags.txt +14 -14
  155. package/release/command.json +1 -1
  156. package/release/command.json.js +1 -1
  157. package/release/command_cnako3.json +1 -1
  158. package/release/command_list.json +1 -1
  159. package/release/editor.js +1 -1
  160. package/release/nako_gen_async.js +1 -1
  161. package/release/plugin_csv.js +1 -1
  162. package/release/stats.json +1 -1
  163. package/release/version.js +1 -1
  164. package/release/wnako3.js +1 -1
  165. package/release/wnako3webworker.js +1 -1
  166. package/src/browsers.txt +11 -12
  167. package/src/browsers_agents.json +2 -2
  168. package/src/browsers_agents.mjs +1 -1
  169. package/src/cnako3.mjs +17 -10
  170. package/src/cnako3.mts +18 -12
  171. package/src/cnako3mod.mjs +707 -687
  172. package/src/cnako3mod.mts +712 -696
  173. package/src/commander_ja.mjs +164 -164
  174. package/src/commander_ja.mts +161 -161
  175. package/src/enako3.mjs +68 -69
  176. package/src/era.mjs +22 -22
  177. package/src/image_turtle-elephant.mjs +2 -5
  178. package/src/image_turtle-panda.mjs +2 -5
  179. package/src/image_turtle64.mjs +2 -5
  180. package/src/index.mjs +9 -9
  181. package/src/index.mts +10 -11
  182. package/src/nako3editorfix.sfd +106 -106
  183. package/src/nako_version.mjs +8 -8
  184. package/src/nako_version.mts +2 -2
  185. package/src/plugin_browser.mjs +213 -212
  186. package/src/plugin_browser.mts +206 -205
  187. package/src/plugin_browser_ajax.mjs +399 -399
  188. package/src/plugin_browser_audio.mjs +109 -109
  189. package/src/plugin_browser_canvas.mjs +449 -449
  190. package/src/plugin_browser_chart.mjs +294 -294
  191. package/src/plugin_browser_color.mjs +49 -49
  192. package/src/plugin_browser_crypto.mjs +26 -26
  193. package/src/plugin_browser_dialog.mjs +53 -53
  194. package/src/plugin_browser_dom_basic.mjs +336 -336
  195. package/src/plugin_browser_dom_event.mjs +193 -193
  196. package/src/plugin_browser_dom_parts.mjs +396 -396
  197. package/src/plugin_browser_geolocation.mjs +51 -51
  198. package/src/plugin_browser_hotkey.mjs +25 -25
  199. package/src/plugin_browser_html.mjs +59 -59
  200. package/src/plugin_browser_in_worker.mjs +45 -45
  201. package/src/plugin_browser_location.mjs +21 -21
  202. package/src/plugin_browser_speech.mjs +111 -111
  203. package/src/plugin_browser_storage.mjs +121 -121
  204. package/src/plugin_browser_system.mjs +31 -31
  205. package/src/plugin_browser_websocket.mjs +73 -73
  206. package/src/plugin_caniuse.mjs +29 -29
  207. package/src/plugin_datetime.mjs +394 -394
  208. package/src/plugin_httpserver.mjs +277 -0
  209. package/src/plugin_httpserver.mts +286 -0
  210. package/src/plugin_kansuji.mjs +224 -224
  211. package/src/plugin_keigo.mjs +55 -55
  212. package/src/plugin_markup.mjs +32 -32
  213. package/src/plugin_node.mjs +1047 -1047
  214. package/src/plugin_node.mts +980 -980
  215. package/src/plugin_turtle.mjs +647 -647
  216. package/src/plugin_webworker.mjs +334 -334
  217. package/src/plugin_weykturtle3d.mjs +1214 -1214
  218. package/src/plugin_worker.mjs +95 -95
  219. package/src/repl.nako3 +63 -63
  220. package/src/wnako3.mjs +12 -12
  221. package/src/wnako3.mts +11 -11
  222. package/src/wnako3_editor.css +215 -215
  223. package/src/wnako3_editor.mjs +1542 -1542
  224. package/src/wnako3_editor.mts +1657 -1656
  225. package/src/wnako3mod.mjs +213 -213
  226. package/src/wnako3mod.mts +214 -214
  227. package/src/wnako3webworker.mjs +69 -68
  228. package/test/ace_editor/karma.config.js +94 -94
  229. package/test/ace_editor/test/.babelrc.json +3 -3
  230. package/test/ace_editor/test/ace_editor_test.js +178 -178
  231. package/test/ace_editor/test/html/custom_context.html +139 -139
  232. package/test/async/async_basic_test.mjs +122 -122
  233. package/test/browser/karma.config.js +221 -221
  234. package/test/browser/test/.babelrc.json +3 -3
  235. package/test/browser/test/compare_util.js +50 -50
  236. package/test/browser/test/html/div_basic.html +2 -2
  237. package/test/browser/test/html/event_dom_form.html +4 -4
  238. package/test/browser/test/html/event_dom_scrolldiv.html +5 -5
  239. package/test/browser/test/import_plugin_checker.js +24 -24
  240. package/test/browser/test/plugin_browser_test.js +51 -51
  241. package/test/browser/test/plugin_browser_test_ajax.js +123 -123
  242. package/test/browser/test/plugin_browser_test_color.js +18 -18
  243. package/test/browser/test/plugin_browser_test_dialog.js +72 -72
  244. package/test/browser/test/plugin_browser_test_dom_event.js +598 -598
  245. package/test/browser/test/plugin_browser_test_dom_parts.js +125 -125
  246. package/test/browser/test/plugin_browser_test_system.js +9 -9
  247. package/test/browser/test/plugin_turtle_test.js +817 -817
  248. package/test/browser/test/plugin_webworker_test.js +86 -86
  249. package/test/browser/test/require_test.js +68 -68
  250. package/test/bundled/karma.config.base.js +117 -117
  251. package/test/bundled/karma.config.js +86 -86
  252. package/test/bundled/test/.babelrc.json +3 -3
  253. package/test/bundled/test/bundled_test.js +69 -69
  254. package/test/bundled/test/html/custom_context.html +65 -65
  255. package/test/bundled/test/html/custom_debug.html +66 -66
  256. package/test/bundled/test4b.cmd +52 -52
  257. package/test/bundled/test_base/.babelrc.json +3 -3
  258. package/test/bundled/test_base/_checktool_test.js +25 -25
  259. package/test/bundled/test_base/basic_ajax_test.js +56 -56
  260. package/test/bundled/test_base/basic_async_test.js +18 -18
  261. package/test/bundled/test_base/basic_test.js +153 -153
  262. package/test/bundled/test_base/calc_test.js +132 -132
  263. package/test/bundled/test_base/css/browsers_box.css +114 -114
  264. package/test/bundled/test_base/html/custom_context.html +69 -69
  265. package/test/bundled/test_base/html/custom_debug.html +71 -71
  266. package/test/bundled/test_base/js/browsers_box.js +72 -72
  267. package/test/bundled/test_base/plugin_csv_test.js +37 -37
  268. package/test/bundled/test_base/plugin_datetime_test.js +115 -115
  269. package/test/bundled/test_base/plugin_kansuji_test.js +49 -49
  270. package/test/bundled/test_base/plugin_system_test.js +410 -410
  271. package/test/bundled/test_base/plugin_webworker_test.js +53 -53
  272. package/test/bundled/test_base/test_utils.js +191 -191
  273. package/test/common/plugin_browser_test.mjs +22 -24
  274. package/test/common/plugin_browser_ut_audio_test.mjs +108 -108
  275. package/test/common/plugin_browser_ut_color_test.mjs +21 -21
  276. package/test/common/plugin_browser_ut_dialog_test.mjs +100 -100
  277. package/test/common/plugin_browser_ut_html_test.mjs +13 -13
  278. package/test/common/plugin_browser_ut_system_test.mjs +10 -10
  279. package/test/common/plugin_markup_test.mjs +23 -23
  280. package/test/jsconfig.json +19 -19
  281. package/test/karma.config.js +91 -91
  282. package/test/node/async_test.mjs +96 -82
  283. package/test/node/commander_ja_test.mjs +89 -89
  284. package/test/node/error_message_test.mjs +243 -253
  285. package/test/node/kai_test.nako3 +6 -6
  286. package/test/node/node_test.mjs +60 -60
  287. package/test/node/plugin_broken.js.txt +3 -3
  288. package/test/node/plugin_browser_ut_ajax_test.mjs.todo +357 -357
  289. package/test/node/plugin_browser_ut_location_test.mjs +42 -42
  290. package/test/node/plugin_markup_test.mjs +47 -46
  291. package/test/node/plugin_math_test.mjs +45 -44
  292. package/test/node/plugin_node_test.mjs +98 -97
  293. package/test/node/plugin_test.mjs +44 -43
  294. package/test/node/relative_import_test_1.nako3 +1 -1
  295. package/test/node/relative_import_test_2.nako3 +2 -2
  296. package/test/node/require_nako3_test.mjs +67 -66
  297. package/test/node/requiretest.nako3 +4 -4
  298. package/test/node/requiretest_indirect.nako3 +1 -1
  299. package/test/node/requiretest_name.nako3 +5 -5
  300. package/test/node/runtime_error.nako3 +2 -2
  301. package/test/node/scope1.nako3 +10 -10
  302. package/test/node/scope2.nako3 +12 -12
  303. package/test/node/side_effects_test.mjs +39 -119
  304. package/test/node/sjis.txt +5 -5
  305. package/test/node/syntax_error.nako3 +1 -1
  306. package/test/node/wnako3_editor_test.mjs +384 -384
  307. package/tools/README.md +12 -7
  308. package/tools/check_new_version.nako3 +25 -25
  309. package/tools/nako3edit/html/daisyui/LICENSE +22 -22
  310. package/tools/nako3edit/html/daisyui/version_2.14.1 +1 -1
  311. package/tools/nako3edit/html/edit.html +170 -170
  312. package/tools/nako3edit/html/edit_plugin.js +6 -6
  313. package/tools/nako3edit/html/files.html +125 -125
  314. package/tools/nako3edit/html/nako3edit.css +65 -65
  315. package/tools/nako3edit/index.mjs +248 -244
  316. package/tools/nako3server/index.html +10 -0
  317. package/tools/nako3server/index.mjs +116 -116
  318. package/tools/nako3server/index.nako3 +34 -0
  319. package/release/nako_gen_async.js.LICENSE.txt +0 -35
  320. package/release/plugin_caniuse.js.LICENSE.txt +0 -11
  321. package/release/plugin_csv.js.LICENSE.txt +0 -15
  322. package/release/plugin_datetime.js.LICENSE.txt +0 -15
  323. package/release/plugin_kansuji.js.LICENSE.txt +0 -3
  324. package/release/plugin_markup.js.LICENSE.txt +0 -11
  325. package/release/plugin_turtle.js.LICENSE.txt +0 -15
  326. package/release/plugin_webworker.js.LICENSE.txt +0 -3
  327. package/release/plugin_weykturtle3d.js.LICENSE.txt +0 -3
  328. package/release/wnako3webworker.js.LICENSE.txt +0 -131
  329. package/tools/nako3edit/a.sqlite3 +0 -0
@@ -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
+ }