nadesiko3 3.2.27

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 (283) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +107 -0
  3. package/bin/cnako3 +10 -0
  4. package/bin/cnako3.bat +11 -0
  5. package/bin/nako3server.bat +6 -0
  6. package/demo/ace_editor.html +90 -0
  7. package/demo/ace_editor_tabs.html +162 -0
  8. package/demo/basic.html +71 -0
  9. package/demo/browsers.html +128 -0
  10. package/demo/css/basic.css +3 -0
  11. package/demo/css/common.css +157 -0
  12. package/demo/css/editor.css +8 -0
  13. package/demo/css/flow.css +3 -0
  14. package/demo/css/index.css +3 -0
  15. package/demo/extlib/ace@1.4.12/ace.js +17 -0
  16. package/demo/extlib/ace@1.4.12/ext-code_lens.min.js +1 -0
  17. package/demo/extlib/ace@1.4.12/ext-language_tools.min.js +1 -0
  18. package/demo/extlib/ace@1.4.12/ext-options.min.js +1 -0
  19. package/demo/extlib/ace@1.4.12/ext-settings_menu.js +8 -0
  20. package/demo/extlib/ace@1.4.12/keybinding-vscode.js +8 -0
  21. package/demo/extlib/ace@1.4.12/theme-monokai.js +8 -0
  22. package/demo/extlib/ace@1.4.12/theme-xcode.js +8 -0
  23. package/demo/extlib/chart.js@3.2.1/chart.min.js +13 -0
  24. package/demo/extlib/pure-min.css +11 -0
  25. package/demo/flow.html +97 -0
  26. package/demo/graph.html +53 -0
  27. package/demo/image/nako.png +0 -0
  28. package/demo/image/nakopad-icon256.png +0 -0
  29. package/demo/image/turtle.fla +0 -0
  30. package/demo/image/turtle.png +0 -0
  31. package/demo/index.html +134 -0
  32. package/demo/js/common.js +17 -0
  33. package/demo/js/turtle3d_test.js +44 -0
  34. package/demo/js/turtle_test.js +44 -0
  35. package/demo/runscript.html +47 -0
  36. package/demo/runscript2.html +33 -0
  37. package/demo/turtle.html +58 -0
  38. package/demo/turtle2.html +141 -0
  39. package/demo/turtle3.html +278 -0
  40. package/demo/turtle3d.html +58 -0
  41. package/demo/turtle3d2.html +107 -0
  42. package/demo/version.html +24 -0
  43. package/doc/SETUP.md +172 -0
  44. package/doc/about.md +34 -0
  45. package/doc/browsers.md +60 -0
  46. package/doc/docgen.md +21 -0
  47. package/doc/editor.md +44 -0
  48. package/doc/files.md +37 -0
  49. package/doc/plugins.md +195 -0
  50. package/doc/release.md +78 -0
  51. package/doc/win32.md +57 -0
  52. package/package.json +196 -0
  53. package/release/_hash.txt +65 -0
  54. package/release/_script-tags.txt +13 -0
  55. package/release/command.json +1 -0
  56. package/release/command.json.js +1 -0
  57. package/release/command_cnako3.json +1 -0
  58. package/release/command_list.json +1 -0
  59. package/release/editor.js +2 -0
  60. package/release/editor.js.LICENSE.txt +32 -0
  61. package/release/josi.json +48 -0
  62. package/release/nako_gen_async.js +1 -0
  63. package/release/nako_gen_async.js.LICENSE.txt +595 -0
  64. package/release/plugin_caniuse.js +1 -0
  65. package/release/plugin_caniuse.js.LICENSE.txt +411 -0
  66. package/release/plugin_csv.js +1 -0
  67. package/release/plugin_csv.js.LICENSE.txt +367 -0
  68. package/release/plugin_datetime.js +1 -0
  69. package/release/plugin_datetime.js.LICENSE.txt +471 -0
  70. package/release/plugin_kansuji.js +1 -0
  71. package/release/plugin_kansuji.js.LICENSE.txt +491 -0
  72. package/release/plugin_markup.js +1 -0
  73. package/release/plugin_markup.js.LICENSE.txt +363 -0
  74. package/release/plugin_turtle.js +1 -0
  75. package/release/plugin_turtle.js.LICENSE.txt +435 -0
  76. package/release/plugin_webworker.js +1 -0
  77. package/release/plugin_webworker.js.LICENSE.txt +491 -0
  78. package/release/version.js +2 -0
  79. package/release/version.js.LICENSE.txt +32 -0
  80. package/release/wnako3.js +2 -0
  81. package/release/wnako3.js.LICENSE.txt +1 -0
  82. package/release/wnako3webworker.js +1 -0
  83. package/release/wnako3webworker.js.LICENSE.txt +847 -0
  84. package/release/yoyakugo.json +30 -0
  85. package/src/browsers.md +60 -0
  86. package/src/cnako3.js +466 -0
  87. package/src/commander_ja.js +154 -0
  88. package/src/enako3.js +69 -0
  89. package/src/era.json +22 -0
  90. package/src/index.js +5 -0
  91. package/src/nako3.js +836 -0
  92. package/src/nako3_assert.js +37 -0
  93. package/src/nako3editorfix.sfd +106 -0
  94. package/src/nako3editorfix.woff +0 -0
  95. package/src/nako3server.js +51 -0
  96. package/src/nako_colors.js +86 -0
  97. package/src/nako_errors.js +176 -0
  98. package/src/nako_gen.js +1459 -0
  99. package/src/nako_gen_async.js +1622 -0
  100. package/src/nako_global.js +113 -0
  101. package/src/nako_indent.js +480 -0
  102. package/src/nako_josi_list.js +46 -0
  103. package/src/nako_lex_rules.js +259 -0
  104. package/src/nako_lexer.js +576 -0
  105. package/src/nako_logger.js +138 -0
  106. package/src/nako_parser3.js +1768 -0
  107. package/src/nako_parser_base.js +265 -0
  108. package/src/nako_parser_const.js +37 -0
  109. package/src/nako_prepare.js +293 -0
  110. package/src/nako_reserved_words.js +35 -0
  111. package/src/nako_source_mapping.js +251 -0
  112. package/src/nako_test.js +37 -0
  113. package/src/nako_version.js +8 -0
  114. package/src/plugin_browser.js +191 -0
  115. package/src/plugin_browser_ajax.js +352 -0
  116. package/src/plugin_browser_audio.js +109 -0
  117. package/src/plugin_browser_canvas.js +462 -0
  118. package/src/plugin_browser_chart.js +296 -0
  119. package/src/plugin_browser_color.js +49 -0
  120. package/src/plugin_browser_crypto.js +26 -0
  121. package/src/plugin_browser_dialog.js +53 -0
  122. package/src/plugin_browser_dom_basic.js +322 -0
  123. package/src/plugin_browser_dom_event.js +193 -0
  124. package/src/plugin_browser_dom_parts.js +163 -0
  125. package/src/plugin_browser_geolocation.js +51 -0
  126. package/src/plugin_browser_hotkey.js +25 -0
  127. package/src/plugin_browser_html.js +59 -0
  128. package/src/plugin_browser_in_worker.js +44 -0
  129. package/src/plugin_browser_location.js +21 -0
  130. package/src/plugin_browser_speech.js +111 -0
  131. package/src/plugin_browser_storage.js +121 -0
  132. package/src/plugin_browser_system.js +12 -0
  133. package/src/plugin_browser_websocket.js +73 -0
  134. package/src/plugin_caniuse.js +24 -0
  135. package/src/plugin_csv.js +57 -0
  136. package/src/plugin_datetime.js +414 -0
  137. package/src/plugin_express.js +212 -0
  138. package/src/plugin_kansuji.js +224 -0
  139. package/src/plugin_keigo.js +55 -0
  140. package/src/plugin_markup.js +32 -0
  141. package/src/plugin_math.js +319 -0
  142. package/src/plugin_node.js +1018 -0
  143. package/src/plugin_promise.js +94 -0
  144. package/src/plugin_system.js +2109 -0
  145. package/src/plugin_test.js +38 -0
  146. package/src/plugin_turtle.js +646 -0
  147. package/src/plugin_webworker.js +334 -0
  148. package/src/plugin_weykturtle3d.js +1216 -0
  149. package/src/plugin_worker.js +92 -0
  150. package/src/repl.nako3 +63 -0
  151. package/src/turtle-elephant.png +0 -0
  152. package/src/turtle-panda.png +0 -0
  153. package/src/turtle64.png +0 -0
  154. package/src/wnako3.js +162 -0
  155. package/src/wnako3_editor.css +215 -0
  156. package/src/wnako3_editor.js +1645 -0
  157. package/src/wnako3_editor_marker_red.png +0 -0
  158. package/src/wnako3_editor_marker_red.xcf +0 -0
  159. package/src/wnako3_editor_marker_yellow.png +0 -0
  160. package/src/wnako3_editor_marker_yellow.xcf +0 -0
  161. package/src/wnako3webworker.js +70 -0
  162. package/test/ace_editor/karma.config.js +94 -0
  163. package/test/ace_editor/test/.babelrc.json +3 -0
  164. package/test/ace_editor/test/ace_editor_test.js +178 -0
  165. package/test/ace_editor/test/html/custom_context.html +140 -0
  166. package/test/async/async_basic_test.js +124 -0
  167. package/test/browser/karma.config.js +212 -0
  168. package/test/browser/test/.babelrc.json +3 -0
  169. package/test/browser/test/compare_util.js +50 -0
  170. package/test/browser/test/html/canvas_basic.html +1 -0
  171. package/test/browser/test/html/div_basic.html +2 -0
  172. package/test/browser/test/html/event_dom_form.html +4 -0
  173. package/test/browser/test/html/event_dom_scrolldiv.html +5 -0
  174. package/test/browser/test/image/canvas_test1.png +0 -0
  175. package/test/browser/test/image/canvas_test2.png +0 -0
  176. package/test/browser/test/image/canvas_test3.png +0 -0
  177. package/test/browser/test/image/canvas_test4.png +0 -0
  178. package/test/browser/test/image/canvas_test7.png +0 -0
  179. package/test/browser/test/image/canvas_test8.png +0 -0
  180. package/test/browser/test/image/canvas_test_blank.png +0 -0
  181. package/test/browser/test/image/elephant_kana.png +0 -0
  182. package/test/browser/test/image/panda_kana.png +0 -0
  183. package/test/browser/test/image/turtle_kana.png +0 -0
  184. package/test/browser/test/import_plugin_checker.js +24 -0
  185. package/test/browser/test/plugin_browser_test.js +52 -0
  186. package/test/browser/test/plugin_browser_test_ajax.js +123 -0
  187. package/test/browser/test/plugin_browser_test_color.js +18 -0
  188. package/test/browser/test/plugin_browser_test_dialog.js +72 -0
  189. package/test/browser/test/plugin_browser_test_dom_event.js +598 -0
  190. package/test/browser/test/plugin_browser_test_dom_parts.js +125 -0
  191. package/test/browser/test/plugin_browser_test_system.js +9 -0
  192. package/test/browser/test/plugin_turtle_test.js +817 -0
  193. package/test/browser/test/plugin_webworker_test.js +87 -0
  194. package/test/browser/test/require_test.js +71 -0
  195. package/test/bundled/karma.config.base.js +117 -0
  196. package/test/bundled/karma.config.js +86 -0
  197. package/test/bundled/test/.babelrc.json +3 -0
  198. package/test/bundled/test/bundled_test.js +69 -0
  199. package/test/bundled/test/html/custom_context.html +65 -0
  200. package/test/bundled/test/html/custom_debug.html +66 -0
  201. package/test/bundled/test4b.cmd +52 -0
  202. package/test/bundled/test_base/.babelrc.json +3 -0
  203. package/test/bundled/test_base/_checktool_test.js +25 -0
  204. package/test/bundled/test_base/basic_ajax_test.js +56 -0
  205. package/test/bundled/test_base/basic_async_test.js +18 -0
  206. package/test/bundled/test_base/basic_test.js +153 -0
  207. package/test/bundled/test_base/calc_test.js +132 -0
  208. package/test/bundled/test_base/css/browsers_box.css +114 -0
  209. package/test/bundled/test_base/html/custom_context.html +69 -0
  210. package/test/bundled/test_base/html/custom_debug.html +71 -0
  211. package/test/bundled/test_base/js/browsers_box.js +72 -0
  212. package/test/bundled/test_base/plugin_csv_test.js +37 -0
  213. package/test/bundled/test_base/plugin_datetime_test.js +115 -0
  214. package/test/bundled/test_base/plugin_kansuji_test.js +49 -0
  215. package/test/bundled/test_base/plugin_system_test.js +410 -0
  216. package/test/bundled/test_base/plugin_webworker_test.js +53 -0
  217. package/test/bundled/test_base/resources/ok.txt +1 -0
  218. package/test/bundled/test_base/test_utils.js +191 -0
  219. package/test/common/array_test.js +40 -0
  220. package/test/common/basic_test.js +317 -0
  221. package/test/common/calc_test.js +139 -0
  222. package/test/common/debug_test.js +16 -0
  223. package/test/common/error_test.js +16 -0
  224. package/test/common/flow_test.js +360 -0
  225. package/test/common/func_call.js +136 -0
  226. package/test/common/func_test.js +149 -0
  227. package/test/common/indent_test.js +362 -0
  228. package/test/common/lex_test.js +146 -0
  229. package/test/common/literal_test.js +72 -0
  230. package/test/common/nako_logger_test.js +26 -0
  231. package/test/common/plugin_browser_test.js +24 -0
  232. package/test/common/plugin_browser_ut_audio_test.js +88 -0
  233. package/test/common/plugin_browser_ut_color_test.js +21 -0
  234. package/test/common/plugin_browser_ut_dialog_test.js +100 -0
  235. package/test/common/plugin_browser_ut_html_test.js +13 -0
  236. package/test/common/plugin_browser_ut_system_test.js +10 -0
  237. package/test/common/plugin_csv_test.js +39 -0
  238. package/test/common/plugin_datetime_test.js +120 -0
  239. package/test/common/plugin_kansuji_test.js +59 -0
  240. package/test/common/plugin_promise_test.js +18 -0
  241. package/test/common/plugin_system_test.js +451 -0
  242. package/test/common/prepare_test.js +93 -0
  243. package/test/common/re_test.js +20 -0
  244. package/test/common/variable_scope_test.js +105 -0
  245. package/test/jsconfig.json +19 -0
  246. package/test/karma.config.js +91 -0
  247. package/test/node/add_test.nako3 +1 -0
  248. package/test/node/async_test.js +80 -0
  249. package/test/node/commander_ja_test.js +82 -0
  250. package/test/node/error_message_test.js +244 -0
  251. package/test/node/kai_test.nako3 +6 -0
  252. package/test/node/node_test.js +43 -0
  253. package/test/node/plugin_broken.js.txt +3 -0
  254. package/test/node/plugin_browser_ut_ajax_test.js +355 -0
  255. package/test/node/plugin_browser_ut_location_test.js +32 -0
  256. package/test/node/plugin_markup_test.js +44 -0
  257. package/test/node/plugin_math_test.js +42 -0
  258. package/test/node/plugin_node_test.js +93 -0
  259. package/test/node/plugin_test.js +16 -0
  260. package/test/node/relative_import_test_1.nako3 +1 -0
  261. package/test/node/relative_import_test_2.nako3 +2 -0
  262. package/test/node/require_nako3_test.js +59 -0
  263. package/test/node/requiretest.nako3 +4 -0
  264. package/test/node/requiretest_indirect.nako3 +1 -0
  265. package/test/node/requiretest_name.nako3 +5 -0
  266. package/test/node/runtime_error.nako3 +2 -0
  267. package/test/node/side_effects_test.js +106 -0
  268. package/test/node/sjis.txt +5 -0
  269. package/test/node/syntax_error.nako3 +2 -0
  270. package/test/node/wnako3_editor_test.js +360 -0
  271. package/tools/README.md +7 -0
  272. package/tools/nako3edit/html/edit.html +83 -0
  273. package/tools/nako3edit/html/edit_plugin.js +6 -0
  274. package/tools/nako3edit/html/files.html +49 -0
  275. package/tools/nako3edit/html/nako3edit.css +66 -0
  276. package/tools/nako3edit/index.nako3 +145 -0
  277. package/tools/nako3edit/run.js +12 -0
  278. package/tools/nako3server/html/edit.html +104 -0
  279. package/tools/nako3server/html/edit_plugin.js +6 -0
  280. package/tools/nako3server/html/files.html +53 -0
  281. package/tools/nako3server/html/nako3edit.css +66 -0
  282. package/tools/nako3server/index.nako3 +129 -0
  283. package/tools/nako3server/run.js +12 -0
@@ -0,0 +1,414 @@
1
+ // @ts-nocheck
2
+ // file: plugin_datetime.js
3
+ const PluginDateTime = {
4
+ '初期化': {
5
+ type: 'func',
6
+ josi: [],
7
+ pure: true,
8
+ fn: function (sys) {
9
+ }
10
+ },
11
+ // @日時処理
12
+ '元号データ': { type: 'const', value: require('./era.json') }, // @げんごうでーた
13
+ '今': { // @現在時刻を「HH:mm:ss」の形式で返す // @いま
14
+ type: 'func',
15
+ josi: [],
16
+ pure: true,
17
+ fn: function () {
18
+ const dayjs = require('dayjs')
19
+ return dayjs().format('HH:mm:ss')
20
+ }
21
+ },
22
+ 'システム時間': { // @現在のUNIX時間 (UTC(1970/1/1)からの経過秒数) を返す // @しすてむじかん
23
+ type: 'func',
24
+ josi: [],
25
+ pure: true,
26
+ fn: function () {
27
+ const dayjs = require('dayjs')
28
+ return dayjs().unix()
29
+ }
30
+ },
31
+ '今日': { // @今日の日付を「YYYY/MM/DD」の形式で返す // @きょう
32
+ type: 'func',
33
+ josi: [],
34
+ pure: true,
35
+ fn: function () {
36
+ const dayjs = require('dayjs')
37
+ return dayjs().format('YYYY/MM/DD')
38
+ }
39
+ },
40
+ '明日': { // @明日の日付を「YYYY/MM/DD」の形式で返す (v1非互換) // @あす
41
+ type: 'func',
42
+ josi: [],
43
+ pure: true,
44
+ fn: function () {
45
+ const dayjs = require('dayjs')
46
+ return dayjs().add(1, 'days').format('YYYY/MM/DD')
47
+ }
48
+ },
49
+ '昨日': { // @昨日の日付を「YYYY/MM/DD」の形式で返す (v1非互換) // @きのう
50
+ type: 'func',
51
+ josi: [],
52
+ pure: true,
53
+ fn: function () {
54
+ const dayjs = require('dayjs')
55
+ return dayjs().subtract(1, 'days').format('YYYY/MM/DD')
56
+ }
57
+ },
58
+ '今年': { // @今年が何年かを西暦で返す // @ことし
59
+ type: 'func',
60
+ josi: [],
61
+ pure: true,
62
+ fn: function () {
63
+ const dayjs = require('dayjs')
64
+ return dayjs().year()
65
+ }
66
+ },
67
+ '来年': { // @来年が何年かを西暦で返す // @らいねん
68
+ type: 'func',
69
+ josi: [],
70
+ pure: true,
71
+ fn: function () {
72
+ const dayjs = require('dayjs')
73
+ return dayjs().add(1, 'years').year()
74
+ }
75
+ },
76
+ '去年': { // @去年が何年かを西暦で返す // @きょねん
77
+ type: 'func',
78
+ josi: [],
79
+ pure: true,
80
+ fn: function () {
81
+ const dayjs = require('dayjs')
82
+ return dayjs().subtract(1, 'years').year()
83
+ }
84
+ },
85
+ '今月': { // @今月が何月かを返す // @こんげつ
86
+ type: 'func',
87
+ josi: [],
88
+ pure: true,
89
+ fn: function () {
90
+ const dayjs = require('dayjs')
91
+ return dayjs().month() + 1
92
+ }
93
+ },
94
+ '来月': { // @来月が何月かを返す // @らいげつ
95
+ type: 'func',
96
+ josi: [],
97
+ pure: true,
98
+ fn: function () {
99
+ const dayjs = require('dayjs')
100
+ return dayjs().add(1, 'months').month() + 1
101
+ }
102
+ },
103
+ '先月': { // @先月が何月かを返す // @せんげつ
104
+ type: 'func',
105
+ josi: [],
106
+ pure: true,
107
+ fn: function () {
108
+ const dayjs = require('dayjs')
109
+ return dayjs().subtract(1, 'months').month() + 1
110
+ }
111
+ },
112
+ '曜日': { // @日付Sの曜日を返す // @ようび
113
+ type: 'func',
114
+ josi: [['の']],
115
+ pure: true,
116
+ fn: function (s) {
117
+ const dayjs = require('dayjs')
118
+ require('dayjs/locale/ja')
119
+ return dayjs(s, 'YYYY/MM/DD').locale('ja').format('ddd')
120
+ }
121
+ },
122
+ '曜日番号取得': { // @Sに指定した日付の曜日番号をで返す。不正な日付の場合は今日の曜日番号を返す。(0=日/1=月/2=火/3=水/4=木/5=金/6=土) // @ようびばんごうしゅとく
123
+ type: 'func',
124
+ josi: [['の']],
125
+ pure: true,
126
+ fn: function (s) {
127
+ const dayjs = require('dayjs')
128
+ require('dayjs/locale/ja')
129
+
130
+ let t = dayjs(s, 'YYYY/MM/DD')
131
+
132
+ if (!t.isValid()) {
133
+ t = dayjs()
134
+ }
135
+
136
+ return t.locale('ja').format('d')
137
+ }
138
+ },
139
+ 'UNIX時間変換': { // @日時SをUNIX時間 (UTC(1970/1/1)からの経過秒数) に変換して返す(v1非互換) // @UNIXじかんへんかん
140
+ type: 'func',
141
+ josi: [['の', 'を', 'から']],
142
+ pure: false,
143
+ fn: function (s, sys) {
144
+ return sys.__exec('UNIXTIME変換', [s])
145
+ }
146
+ },
147
+ 'UNIXTIME変換': { // @日時SをUNIX時間 (UTC(1970/1/1)からの経過秒数) に変換して返す // @UNIXTIMEへんかん
148
+ type: 'func',
149
+ josi: [['の', 'を', 'から']],
150
+ pure: true,
151
+ fn: function (s) {
152
+ const dayjs = require('dayjs')
153
+ return dayjs(s, 'YYYY/MM/DD HH:mm:ss').unix()
154
+ }
155
+ },
156
+ '日時変換': { // @UNIX時間 (UTC(1970/1/1)からの経過秒数) を「YYYY/MM/DD HH:mm:ss」の形式に変換 // @にちじへんかん
157
+ type: 'func',
158
+ josi: [['を', 'から']],
159
+ pure: true,
160
+ fn: function (tm) {
161
+ const dayjs = require('dayjs')
162
+ return dayjs.unix(tm).format('YYYY/MM/DD HH:mm:ss')
163
+ }
164
+ },
165
+ '和暦変換': { // @Sを和暦に変換する。Sは明治以降の日付が有効。 // @われきへんかん
166
+ type: 'func',
167
+ josi: [['を']],
168
+ pure: true,
169
+ fn: function (s, sys) {
170
+ const dayjs = require('dayjs')
171
+ const date = dayjs(s, 'YYYY/MM/DD')
172
+
173
+ for (const era of sys.__v0['元号データ']) {
174
+ const eraBeginDate = dayjs(era['改元日'], 'YYYY/MM/DD')
175
+ if (eraBeginDate <= date) {
176
+ let eraYear = date.format('YYYY') - eraBeginDate.format('YYYY') + 1
177
+
178
+ if (eraYear === 1) {
179
+ eraYear = '元'
180
+ }
181
+
182
+ return era['元号'] + eraYear + '/' + date.format('MM/DD')
183
+ }
184
+ }
185
+
186
+ throw new Error('『和暦変換』は明治以前の日付には対応していません。')
187
+ }
188
+ },
189
+ '年数差': { // @日付AとBの差を年数で求めて返す。A<Bなら正の数、そうでないなら負の数を返す (v1非互換)。 // @ねんすうさ
190
+ type: 'func',
191
+ josi: [['と', 'から'], ['の', 'までの']],
192
+ pure: false,
193
+ fn: function (a, b, sys) {
194
+ return sys.__exec('日時差', [a, b, '年'])
195
+ }
196
+ },
197
+ '月数差': { // @日付AとBの差を月数で求めて返す。A<Bなら正の数、そうでないなら負の数を返す (v1非互換)。 // @げっすうさ
198
+ type: 'func',
199
+ josi: [['と', 'から'], ['の', 'までの']],
200
+ pure: false,
201
+ fn: function (a, b, sys) {
202
+ return sys.__exec('日時差', [a, b, '月'])
203
+ }
204
+ },
205
+ '日数差': { // @日付AとBの差を日数で求めて返す。A<Bなら正の数、そうでないなら負の数を返す。 // @にっすうさ
206
+ type: 'func',
207
+ josi: [['と', 'から'], ['の', 'までの']],
208
+ pure: false,
209
+ fn: function (a, b, sys) {
210
+ return sys.__exec('日時差', [a, b, '日'])
211
+ }
212
+ },
213
+ '日時差': { // @日時AとBの差を種類unitで返す。A<Bなら正の数、そうでないなら負の数を返す (v1非互換)。 // @にちじさ
214
+ type: 'func',
215
+ josi: [['と', 'から'], ['の', 'までの'], ['による']],
216
+ pure: true,
217
+ fn: function (a, b, unit) {
218
+ const dayjs = require('dayjs')
219
+
220
+ switch (unit) {
221
+ case '年':
222
+ unit = 'years'
223
+ break
224
+ case '月':
225
+ unit = 'months'
226
+ break
227
+ case '日':
228
+ unit = 'days'
229
+ break
230
+ case '時間':
231
+ unit = 'hours'
232
+ break
233
+ case '分':
234
+ unit = 'minutes'
235
+ break
236
+ case '秒':
237
+ unit = 'seconds'
238
+ break
239
+ default:
240
+ break
241
+ }
242
+
243
+ const maxCount = 2
244
+
245
+ for (let i = 0; i < maxCount; i++) {
246
+ const dts = []
247
+
248
+ for (const s of [b, a]) {
249
+ let s_ = s
250
+
251
+ if (i === maxCount - 1) {
252
+ s_ = '1980/01/01 ' + s_
253
+ }
254
+
255
+ const t = dayjs(s_, 'YYYY/MM/DD HH:mm:ss')
256
+
257
+ if (t.isValid()) {
258
+ dts.push(t)
259
+ }
260
+ }
261
+
262
+ if (dts.length === 2) {
263
+ return dts[0].diff(dts[1], unit)
264
+ }
265
+ }
266
+
267
+ throw new Error('時間差が正常に算出できませんでした。')
268
+ }
269
+ },
270
+ '時間差': { // @時間AとBの時間の差を求めて返す。A<Bなら正の数、そうでないなら負の数を返す。 // @じかんさ
271
+ type: 'func',
272
+ josi: [['と', 'から'], ['の', 'までの']],
273
+ pure: false,
274
+ fn: function (a, b, sys) {
275
+ return sys.__exec('日時差', [a, b, '時間'])
276
+ }
277
+ },
278
+ '分差': { // @時間AとBの分数の差を求めて返す。A<Bなら正の数、そうでないなら負の数を返す。 // @ふんさ
279
+ type: 'func',
280
+ josi: [['と', 'から'], ['の', 'までの']],
281
+ pure: false,
282
+ fn: function (a, b, sys) {
283
+ return sys.__exec('日時差', [a, b, '分'])
284
+ }
285
+ },
286
+ '秒差': { // @時間AとBの差を秒差で求めて返す。A<Bなら正の数、そうでないなら負の数を返す。 // @びょうさ
287
+ type: 'func',
288
+ josi: [['と', 'から'], ['の', 'までの']],
289
+ pure: false,
290
+ fn: function (a, b, sys) {
291
+ return sys.__exec('日時差', [a, b, '秒'])
292
+ }
293
+ },
294
+ '時間加算': { // @時間SにAを加えて返す。Aには「(+|-)hh:nn:dd」で指定する。 // @じかんかさん
295
+ type: 'func',
296
+ josi: [['に'], ['を']],
297
+ pure: false,
298
+ fn: function (s, a, sys) {
299
+ const pm = a.slice(0, 1)
300
+
301
+ if (pm !== '+' && pm !== '-') {
302
+ throw new Error('『時間加算』命令の引数Aは「(+|-)hh:nn:dd」で指定します。')
303
+ }
304
+
305
+ const n = a.slice(1).split(':')
306
+ const units = ['時間', '分', '秒']
307
+
308
+ for (let i = 0; i < n.length; i++) {
309
+ s = sys.__exec('日時加算', [s, pm + n[i] + units[i]])
310
+ }
311
+
312
+ return s
313
+ }
314
+ },
315
+ '日付加算': { // @日付SにAを加えて返す。Aには「(+|-)yyyy/mm/dd」で指定する。 // @ひづけかさん
316
+ type: 'func',
317
+ josi: [['に'], ['を']],
318
+ pure: false,
319
+ fn: function (s, a, sys) {
320
+ const pm = a.slice(0, 1)
321
+
322
+ if (pm !== '+' && pm !== '-') {
323
+ throw new Error('『日付加算』命令の引数Aは「(+|-)yyyy/mm/dd」で指定します。')
324
+ }
325
+
326
+ const n = a.slice(1).split('/')
327
+ const units = ['年', 'ヶ月', '日']
328
+
329
+ for (let i = 0; i < n.length; i++) {
330
+ s = sys.__exec('日時加算', [s, pm + n[i] + units[i]])
331
+ }
332
+
333
+ return s
334
+ }
335
+ },
336
+
337
+ '日時加算': { // @日時SにAを加えて返す。Aは「(+|-)1(年|ヶ月|日|時間|分|秒)」のように指定する (v1非互換)。 // @にちじかさん
338
+ type: 'func',
339
+ josi: [['に'], ['を']],
340
+ pure: true,
341
+ fn: function (s, a) {
342
+ const dayjs = require('dayjs')
343
+
344
+ let unit
345
+
346
+ switch (a.match(/(年|ヶ月|日|時間|分|秒)$/)[0]) {
347
+ case '年':
348
+ unit = 'years'
349
+ break
350
+ case 'ヶ月':
351
+ unit = 'months'
352
+ break
353
+ case '日':
354
+ unit = 'days'
355
+ break
356
+ case '時間':
357
+ unit = 'hours'
358
+ break
359
+ case '分':
360
+ unit = 'minutes'
361
+ break
362
+ case '秒':
363
+ unit = 'seconds'
364
+ break
365
+ default:
366
+ break
367
+ }
368
+
369
+ const dateFormat = 'YYYY/MM/DD'
370
+ const timeFormat = 'HH:mm:ss'
371
+ const datetimeFormat = [dateFormat, timeFormat].join(' ')
372
+ const maxCount = 2
373
+
374
+ for (let i = 0; i < maxCount; i++) {
375
+ let s_ = s
376
+ let outputFormat
377
+
378
+ if (i === maxCount - 1) {
379
+ s_ = '1980/01/01 ' + s_
380
+ outputFormat = timeFormat
381
+ } else if (s_.indexOf(':') === -1) {
382
+ outputFormat = dateFormat
383
+ } else {
384
+ outputFormat = datetimeFormat
385
+ }
386
+
387
+ let t = dayjs(s_, datetimeFormat)
388
+
389
+ if (t.isValid()) {
390
+ const n = a.match(/[0-9]+/)[0]
391
+
392
+ switch (a.slice(0, 1)) {
393
+ case '+':
394
+ t = t.add(n, unit)
395
+ break
396
+ case '-':
397
+ t = t.subtract(n, unit)
398
+ break
399
+ default:
400
+ throw new Error('『日時加算』命令の引数Aは「(+|-)1(年|ヶ月|日|時間|分|秒)」のように指定します。')
401
+ }
402
+
403
+ return t.format(outputFormat)
404
+ }
405
+ }
406
+ throw new Error('日時を正常に加算できませんでした。')
407
+ }
408
+ }
409
+ }
410
+
411
+ module.exports = PluginDateTime
412
+ // scriptタグで取り込んだ時、自動で登録する
413
+ /* istanbul ignore else */
414
+ if (typeof (navigator) === 'object' && typeof (navigator.nako3) === 'object') { navigator.nako3.addPluginObject('PluginDateTime', PluginDateTime) }
@@ -0,0 +1,212 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * file: plugin_express.js
4
+ * Webサーバのためのプラグイン (expressをラップしたもの)
5
+ */
6
+ const express = require('express')
7
+ const bodyParser = require('body-parser')
8
+
9
+ // 定数・変数
10
+ let WEBSERVER_NAME = 'WEBサーバ(なでしこ+Express)'
11
+ const ERROR_NO_INIT = '先に『WEBサーバ起動』命令を実行してください。'
12
+ let debug = true
13
+
14
+ const PluginExpress = {
15
+ '初期化': {
16
+ type: 'func',
17
+ josi: [],
18
+ pure: true,
19
+ fn: function (sys) {
20
+ sys.__v0['WEBサーバ:ONSUCCESS'] = null
21
+ sys.__v0['WEBサーバ:ONERROR'] = null
22
+ sys.__v0['WEBサーバ:要求'] = null
23
+ sys.__v0['WEBサーバ:応答'] = null
24
+ sys.__v0['WEBサーバクエリ'] = {}
25
+ sys.__server = null
26
+ sys.__webapp = null
27
+ }
28
+ },
29
+ // @Webサーバ(Express)
30
+ 'GETデータ': { type: 'const', value: '' }, // @GETでーた
31
+ 'POSTデータ': { type: 'const', value: '' }, // @POSTでーた
32
+ 'WEBサーバ名前設定': { // @Webサーバの名前を変更する // @WEBさーばなまえへんこう
33
+ type: 'func',
34
+ josi: [['に', 'へ']],
35
+ pure: true,
36
+ fn: function (name, sys) {
37
+ WEBSERVER_NAME = name
38
+ debug = false
39
+ },
40
+ return_none: true
41
+ },
42
+ 'WEBサーバ起動': { // @ポートPORTNOでWebサーバを起動して成功したら『WEBサーバ起動成功した時』を実行する // @WEBさーばきどう
43
+ type: 'func',
44
+ josi: [['の', 'で']],
45
+ pure: true,
46
+ fn: function (portno, sys) {
47
+ const app = express()
48
+ const server = app.listen(portno, () => {
49
+ const pno = server.address().port
50
+ if (debug) {
51
+ console.log('* [' + WEBSERVER_NAME + '] (debug)')
52
+ console.log('| 以下のURLで起動しました。')
53
+ console.log('+- [URL] http://localhost:' + pno)
54
+ }
55
+ const callback = sys.__v0['WEBサーバ:ONSUCCESS']
56
+ if (callback) { callback(pno, sys) }
57
+ })
58
+ server.on('error', (e) => {
59
+ const callback = sys.__v0['WEBサーバ:ONERROR']
60
+ if (callback) { callback(e, sys) }
61
+ })
62
+ // POSTを自動的に処理
63
+ app.use(bodyParser.text({
64
+ type: 'text/plain'
65
+ }))
66
+ app.use(bodyParser.json({
67
+ type: 'application/json'
68
+ }))
69
+ app.use(bodyParser.urlencoded({
70
+ type: 'application/x-www-form-urlencoded',
71
+ extended: true
72
+ }))
73
+ // memo
74
+ sys.__webapp = app
75
+ sys.__server = server
76
+ return server
77
+ }
78
+ },
79
+ 'WEBサーバ起動時': { // @ポートPORTNOでWebサーバを起動して成功したらCALLBACKを実行する // @WEBさーばきどうしたとき
80
+ type: 'func',
81
+ josi: [['を'], ['の', 'で']],
82
+ pure: false,
83
+ fn: function (callback, portno, sys) {
84
+ sys.__v0['WEBサーバ:ONSUCCESS'] = callback
85
+ return sys.__exec('WEBサーバ起動', [portno, sys])
86
+ }
87
+ },
88
+ 'WEBサーバ起動成功時': { // @WEBサーバ起動が成功した時にcallbackを実行 // @WEBさーばきどうせいこうしたとき
89
+ type: 'func',
90
+ josi: [['を']],
91
+ pure: true,
92
+ fn: function (callback, sys) {
93
+ sys.__v0['WEBサーバ:ONSUCCESS'] = callback
94
+ },
95
+ return_none: true
96
+ },
97
+ 'WEBサーバ起動失敗時': { // @WEBサーバ起動が失敗した時にcallbackを実行 // @WEBさーばきどうしっぱいしたとき
98
+ type: 'func',
99
+ josi: [['を']],
100
+ pure: true,
101
+ fn: function (callback, sys) {
102
+ sys.__v0['WEBサーバ:ONERROR'] = callback
103
+ },
104
+ return_none: true
105
+ },
106
+ 'WEBサーバ静的パス指定': { // @サーバのHTMLや画像などを配置する静的パスを指定する // @WEBさーばせいてきぱすしてい
107
+ type: 'func',
108
+ josi: [['を'], ['に', 'へ']],
109
+ pure: true,
110
+ fn: function (url, path, sys) {
111
+ if (sys.__webapp == null) { throw new Error(ERROR_NO_INIT) }
112
+ if (debug) { console.log('[static]', url, path) }
113
+ sys.__webapp.use(url, express.static(path))
114
+ },
115
+ return_none: true
116
+ },
117
+ 'WEBサーバGET時': { // @URIにGETメソッドがあった時の処理を指定 // @WEBさーばGETしたとき
118
+ type: 'func',
119
+ josi: [['を'], ['に', 'へ']],
120
+ pure: true,
121
+ fn: function (callback, uri, sys) {
122
+ if (debug) {
123
+ console.log('[GET] ' + uri)
124
+ }
125
+ sys.__webapp.get(uri, (req, res) => {
126
+ callbackServerFunc(callback, req, res, sys)
127
+ })
128
+ },
129
+ return_none: true
130
+ },
131
+ 'WEBサーバPOST時': { // @URIにPOSTメソッドがあった時の処理を指定 // @WEBさーばPOSTしたとき
132
+ type: 'func',
133
+ josi: [['を'], ['に', 'へ']],
134
+ pure: true,
135
+ fn: function (callback, uri, sys) {
136
+ sys.__webapp.post(uri, (req, res) => { callbackServerFunc(callback, req, res, sys) })
137
+ },
138
+ return_none: true
139
+ },
140
+ 'WEBサーバPUT時': { // @URIにPOSTメソッドがあった時の処理を指定 // @WEBさーばPUTしたとき
141
+ type: 'func',
142
+ josi: [['を'], ['に', 'へ']],
143
+ pure: true,
144
+ fn: function (callback, uri, sys) {
145
+ sys.__webapp.put(uri, (req, res) => { callbackServerFunc(callback, req, res, sys) })
146
+ },
147
+ return_none: true
148
+ },
149
+ 'WEBサーバDELETE時': { // @URIにPOSTメソッドがあった時の処理を指定 // @WEBさーばDELETEしたとき
150
+ type: 'func',
151
+ josi: [['を'], ['に', 'へ']],
152
+ pure: true,
153
+ fn: function (callback, uri, sys) {
154
+ sys.__webapp.delete(uri, (req, res) => { callbackServerFunc(callback, req, res, sys) })
155
+ },
156
+ return_none: true
157
+ },
158
+ 'WEBサーバヘッダ出力': { // @クライアントにヘッダOBJを出力 // @WEBさーばへっだしゅつりょく
159
+ type: 'func',
160
+ josi: [['を', 'の']],
161
+ pure: true,
162
+ fn: function (obj, sys) {
163
+ const res = sys.__v0['WEBサーバ:応答']
164
+ for (const key in obj) {
165
+ res.set(key, obj[key])
166
+ }
167
+ },
168
+ return_none: true
169
+ },
170
+ 'WEBサーバステータス出力': { // @クライアントにステータスNOを出力 // @WEBさーばすてーたすしゅつりょく
171
+ type: 'func',
172
+ josi: [['を', 'の']],
173
+ pure: true,
174
+ fn: function (no, sys) {
175
+ const res = sys.__v0['WEBサーバ:応答']
176
+ res.sendStatus(no)
177
+ },
178
+ return_none: true
179
+ },
180
+ 'WEBサーバ出力': { // @クライアントにSを出力 // @WEBさーばしゅつりょく
181
+ type: 'func',
182
+ josi: [['を', 'と']],
183
+ pure: true,
184
+ fn: function (s, sys) {
185
+ const res = sys.__v0['WEBサーバ:応答']
186
+ res.send('' + s)
187
+ },
188
+ return_none: true
189
+ },
190
+ 'WEBサーバリダイレクト': { // @URLにリダイレクトする // @WEBさーばりだいれくと
191
+ type: 'func',
192
+ josi: [['へ', 'に']],
193
+ pure: true,
194
+ fn: function (url, sys) {
195
+ const res = sys.__v0['WEBサーバ:応答']
196
+ res.redirect(302, url)
197
+ },
198
+ return_none: true
199
+ }
200
+ }
201
+
202
+ // GET/POST/PUT/DELETEのコールバック
203
+ function callbackServerFunc (callback, req, res, sys) {
204
+ // if (debug) { console.log(req) }
205
+ sys.__v0['WEBサーバ:要求'] = req
206
+ sys.__v0['WEBサーバ:応答'] = res
207
+ sys.__v0['GETデータ'] = req.query
208
+ sys.__v0['POSTデータ'] = req.body
209
+ callback(req, res)
210
+ }
211
+
212
+ module.exports = PluginExpress