bare-script 3.7.1 → 3.7.3

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.
package/lib/bare.js CHANGED
@@ -91,13 +91,13 @@ export async function main(options) {
91
91
  if (args.static || args.debug) {
92
92
  const warnings = lintScript(script);
93
93
  if (warnings.length === 0) {
94
- options.logFn(`BareScript: Static analysis "${scriptName}" ... OK`);
94
+ options.logFn(`BareScript static analysis "${scriptName}" ... OK`);
95
95
  } else {
96
96
  options.logFn(
97
- `BareScript: Static analysis "${scriptName}" ... ${warnings.length} warning${warnings.length > 1 ? 's' : ''}:`
97
+ `BareScript static analysis "${scriptName}" ... ${warnings.length} warning${warnings.length > 1 ? 's' : ''}:`
98
98
  );
99
99
  for (const warning of warnings) {
100
- options.logFn(`BareScript: ${warning}`);
100
+ options.logFn(warning);
101
101
  }
102
102
  if (args.static) {
103
103
  statusCode = 1;
@@ -131,7 +131,7 @@ export async function main(options) {
131
131
  // Log script execution end with timing
132
132
  if (args.debug) {
133
133
  const timeEnd = performance.now();
134
- options.logFn(`BareScript: Script executed in ${(timeEnd - timeBegin).toFixed(1)} milliseconds`);
134
+ options.logFn(`BareScript executed in ${(timeEnd - timeBegin).toFixed(1)} milliseconds`);
135
135
  }
136
136
 
137
137
  // Stop on error status code
@@ -62,7 +62,7 @@ function argsValidate(arguments):
62
62
 
63
63
  # Check for duplicate arguments
64
64
  if validatedArguments != null:
65
- argNames = objectNew()
65
+ argNames = {}
66
66
  for argument in arguments:
67
67
  name = objectGet(argument, 'name')
68
68
  if objectHas(argNames, name):
@@ -86,7 +86,7 @@ endfunction
86
86
  # $return: The arguments object
87
87
  function argsParse(arguments):
88
88
  # Create the arguments object
89
- args = objectNew()
89
+ args = {}
90
90
  for argument in arguments:
91
91
  # Get the argument value
92
92
  global = argsGlobalName(argument)
@@ -119,8 +119,8 @@ endfunction
119
119
  # $return: The MarkdownUp application URL
120
120
  function argsURL(arguments, args, explicit, headerText, url):
121
121
  # Get the URL variables
122
- urlVars = arrayNew()
123
- argNames = objectNew()
122
+ urlVars = []
123
+ argNames = {}
124
124
  for argument in arguments:
125
125
  name = objectGet(argument, 'name')
126
126
  type = objectGet(argument, 'type')
@@ -189,7 +189,7 @@ endfunction
189
189
  # $arg arguments: The [arguments model](includeModel.html#var.vName='ArgsArguments')
190
190
  function argsHelp(arguments):
191
191
  # Create the help data
192
- helpData = arrayNew()
192
+ helpData = []
193
193
  anyDefault = false
194
194
  anyExplicit = false
195
195
  anyDescription = false
@@ -200,13 +200,13 @@ function argsHelp(arguments):
200
200
  description = objectGet(argument, 'description')
201
201
 
202
202
  # Add the help data row
203
- arrayPush(helpData, objectNew( \
204
- 'Variable', argsGlobalName(argument), \
205
- 'Type', type, \
206
- 'Default', argsFormatValue(default, type), \
207
- 'Explicit', if(explicit, 'Yes', ''), \
208
- 'Description', if(description != null, description, '') \
209
- ))
203
+ arrayPush(helpData, { \
204
+ 'Variable': argsGlobalName(argument), \
205
+ 'Type': type, \
206
+ 'Default': argsFormatValue(default, type), \
207
+ 'Explicit': if(explicit, 'Yes', ''), \
208
+ 'Description': if(description != null, description, '') \
209
+ })
210
210
 
211
211
  # Update the "any" field bools
212
212
  anyDefault = anyDefault || (default != null)
@@ -215,7 +215,7 @@ function argsHelp(arguments):
215
215
  endfor
216
216
 
217
217
  # Render the help table
218
- helpFields = arrayNew('Variable', 'Type')
218
+ helpFields = ['Variable', 'Type']
219
219
  if anyDefault:
220
220
  arrayPush(helpFields, 'Default')
221
221
  endif
@@ -225,7 +225,7 @@ function argsHelp(arguments):
225
225
  if anyDescription:
226
226
  arrayPush(helpFields, 'Description')
227
227
  endif
228
- dataTable(helpData, objectNew('fields', helpFields))
228
+ dataTable(helpData, {'fields': helpFields})
229
229
  endfunction
230
230
 
231
231
 
@@ -92,7 +92,7 @@ function dataTableMarkdown(data, model):
92
92
  endif
93
93
 
94
94
  # Determine the table fields
95
- fields = arrayNew()
95
+ fields = []
96
96
  modelFields = if(model != null, objectGet(model, 'fields'))
97
97
  modelCategories = if(model != null, objectGet(model, 'categories'))
98
98
  if modelFields != null || modelCategories != null:
@@ -116,7 +116,7 @@ function dataTableMarkdown(data, model):
116
116
  formats = if(model != null, objectGet(model, 'formats'))
117
117
 
118
118
  # Compute the field header widths
119
- widths = objectNew()
119
+ widths = {}
120
120
  for field in fields:
121
121
  fieldWidth = stringLength(field)
122
122
  if !objectHas(widths, field) || fieldWidth > objectGet(widths, field):
@@ -125,9 +125,9 @@ function dataTableMarkdown(data, model):
125
125
  endfor
126
126
 
127
127
  # Compute the formatted field value strings and widths
128
- dataFormat = arrayNew()
128
+ dataFormat = []
129
129
  for row in data:
130
- rowFormat = objectNew()
130
+ rowFormat = {}
131
131
  arrayPush(dataFormat, rowFormat)
132
132
  for field in fields:
133
133
  # Format the value
@@ -176,7 +176,7 @@ function dataTableMarkdown(data, model):
176
176
  headerFields = headerFields + '|'
177
177
 
178
178
  # Output the table header
179
- lines = arrayNew()
179
+ lines = []
180
180
  arrayPush(lines, headerFields)
181
181
  arrayPush(lines, headerSeparator)
182
182
 
@@ -49,11 +49,11 @@ diffTypes = schemaParse( \
49
49
  # $arg right: The "right" string or array of strings
50
50
  # $return: The array of [difference models](includeModel.html#var.vName='Differences')
51
51
  function diffLines(left, right):
52
- diffs = arrayNew()
52
+ diffs = []
53
53
 
54
54
  # Split the left into an array of lines
55
55
  if systemType(left) == 'array':
56
- leftLines = arrayNew()
56
+ leftLines = []
57
57
  for leftPart in left:
58
58
  arrayExtend(leftLines, regexSplit(diffRegexLineSplit, leftPart))
59
59
  endfor
@@ -63,7 +63,7 @@ function diffLines(left, right):
63
63
 
64
64
  # Split the right into an array of lines
65
65
  if systemType(right) == 'array':
66
- rightLines = arrayNew()
66
+ rightLines = []
67
67
  for rightPart in right:
68
68
  arrayExtend(rightLines, regexSplit(diffRegexLineSplit, rightPart))
69
69
  endfor
@@ -80,26 +80,26 @@ function diffLines(left, right):
80
80
  # If we've run out of lines on either side
81
81
  if ixLeft >= leftLength:
82
82
  if ixRight < rightLength:
83
- arrayPush(diffs, objectNew('type', 'Add', 'lines', arraySlice(rightLines, ixRight)))
83
+ arrayPush(diffs, {'type': 'Add', 'lines': arraySlice(rightLines, ixRight)})
84
84
  endif
85
85
  break
86
86
  endif
87
87
  if ixRight >= rightLength:
88
88
  if ixLeft < leftLength:
89
- arrayPush(diffs, objectNew('type', 'Remove', 'lines', arraySlice(leftLines, ixLeft)))
89
+ arrayPush(diffs, {'type': 'Remove', 'lines': arraySlice(leftLines, ixLeft)})
90
90
  endif
91
91
  break
92
92
  endif
93
93
 
94
94
  # Find consecutive identical lines
95
- identicalLines = arrayNew()
95
+ identicalLines = []
96
96
  while ixLeft < leftLength && ixRight < rightLength && arrayGet(leftLines, ixLeft) == arrayGet(rightLines, ixRight):
97
97
  arrayPush(identicalLines, arrayGet(leftLines, ixLeft))
98
98
  ixLeft = ixLeft + 1
99
99
  ixRight = ixRight + 1
100
100
  endwhile
101
101
  if identicalLines:
102
- arrayPush(diffs, objectNew('type', 'Identical', 'lines', identicalLines))
102
+ arrayPush(diffs, {'type': 'Identical', 'lines': identicalLines})
103
103
  continue
104
104
  endif
105
105
 
@@ -124,11 +124,11 @@ function diffLines(left, right):
124
124
  # If no match found, use remaining lines
125
125
  if !foundMatch:
126
126
  if ixLeft < leftLength:
127
- arrayPush(diffs, objectNew('type', 'Remove', 'lines', arraySlice(leftLines, ixLeft)))
127
+ arrayPush(diffs, {'type': 'Remove', 'lines': arraySlice(leftLines, ixLeft)})
128
128
  ixLeft = leftLength
129
129
  endif
130
130
  if ixRight < rightLength:
131
- arrayPush(diffs, objectNew('type', 'Add', 'lines', arraySlice(rightLines, ixRight)))
131
+ arrayPush(diffs, {'type': 'Add', 'lines': arraySlice(rightLines, ixRight)})
132
132
  ixRight = rightLength
133
133
  endif
134
134
  continue
@@ -136,13 +136,13 @@ function diffLines(left, right):
136
136
 
137
137
  # Add removed lines if any
138
138
  if ixLeftTmp > ixLeft:
139
- arrayPush(diffs, objectNew('type', 'Remove', 'lines', arraySlice(leftLines, ixLeft, ixLeftTmp)))
139
+ arrayPush(diffs, {'type': 'Remove', 'lines': arraySlice(leftLines, ixLeft, ixLeftTmp)})
140
140
  ixLeft = ixLeftTmp
141
141
  endif
142
142
 
143
143
  # Add added lines if any
144
144
  if ixRightTmp > ixRight:
145
- arrayPush(diffs, objectNew('type', 'Add', 'lines', arraySlice(rightLines, ixRight, ixRightTmp)))
145
+ arrayPush(diffs, {'type': 'Add', 'lines': arraySlice(rightLines, ixRight, ixRightTmp)})
146
146
  ixRight = ixRightTmp
147
147
  endif
148
148
  endwhile
@@ -18,18 +18,18 @@ formsSentinel = true
18
18
  # $arg onEnter: Optional (default is null). The text input element on-enter event handler
19
19
  # $return: The text input [element model](https://github.com/craigahobbs/element-model#readme)
20
20
  function formsTextElements(id, text, size, onEnter):
21
- return objectNew( \
22
- 'html', 'input', \
23
- 'attr', objectNew( \
24
- 'autocomplete', 'off', \
25
- 'id', id, \
26
- 'style', 'font-size: inherit; border: thin solid black; padding: 0.4em;', \
27
- 'type', 'text', \
28
- 'value', text, \
29
- 'size', size \
30
- ), \
31
- 'callback', if(onEnter != null, objectNew('keyup', systemPartial(formsTextOnKeyup, onEnter))) \
32
- )
21
+ return { \
22
+ 'html': 'input', \
23
+ 'attr': { \
24
+ 'autocomplete': 'off', \
25
+ 'id': id, \
26
+ 'style': 'font-size: inherit; border: thin solid black; padding: 0.4em;', \
27
+ 'type': 'text', \
28
+ 'value': text, \
29
+ 'size': size \
30
+ }, \
31
+ 'callback': if(onEnter != null, {'keyup': systemPartial(formsTextOnKeyup, onEnter)}) \
32
+ }
33
33
  endfunction
34
34
 
35
35
 
@@ -47,12 +47,12 @@ endfunction
47
47
  # $arg onClick: The link button's click event handler
48
48
  # $return: The link button [element model](https://github.com/craigahobbs/element-model#readme)
49
49
  function formsLinkButtonElements(text, onClick):
50
- return objectNew( \
51
- 'html', 'a', \
52
- 'attr', objectNew('style', 'cursor: pointer; user-select: none;'), \
53
- 'elem', objectNew('text', text), \
54
- 'callback', objectNew('click', onClick) \
55
- )
50
+ return { \
51
+ 'html': 'a', \
52
+ 'attr': {'style': 'cursor: pointer; user-select: none;'}, \
53
+ 'elem': {'text': text}, \
54
+ 'callback': {'click': onClick} \
55
+ }
56
56
  endfunction
57
57
 
58
58
 
@@ -64,16 +64,16 @@ endfunction
64
64
  # $return: The link [element model](https://github.com/craigahobbs/element-model#readme)
65
65
  function formsLinkElements(text, url):
66
66
  if url == null:
67
- return objectNew( \
68
- 'html', 'span', \
69
- 'attr', objectNew('style', 'user-select: none;'), \
70
- 'elem', objectNew('text', text) \
71
- )
67
+ return { \
68
+ 'html': 'span', \
69
+ 'attr': {'style': 'user-select: none;'}, \
70
+ 'elem': {'text': text} \
71
+ }
72
72
  endif
73
73
 
74
- return objectNew( \
75
- 'html', 'a', \
76
- 'attr', objectNew('href', documentURL(url)), \
77
- 'elem', objectNew('text', text) \
78
- )
74
+ return { \
75
+ 'html': 'a', \
76
+ 'attr': {'href': documentURL(url)}, \
77
+ 'elem': {'text': text} \
78
+ }
79
79
  endfunction
@@ -21,14 +21,14 @@ markdownUpWindowWidth = 1024
21
21
 
22
22
 
23
23
  # The simulated MarkdownUp state
24
- markdownUpState = objectNew( \
25
- 'drawingFontSizePx', markdownUpDefaultFontSizePx, \
26
- 'drawingHeight', 480, \
27
- 'drawingWidth', 640, \
28
- 'localStorage', objectNew(), \
29
- 'sessionStorage', objectNew(), \
30
- 'windowClipboard', '' \
31
- )
24
+ markdownUpState = { \
25
+ 'drawingFontSizePx': markdownUpDefaultFontSizePx, \
26
+ 'drawingHeight': 480, \
27
+ 'drawingWidth': 640, \
28
+ 'localStorage': {}, \
29
+ 'sessionStorage': {}, \
30
+ 'windowClipboard': '' \
31
+ }
32
32
 
33
33
 
34
34
  #
@@ -202,7 +202,7 @@ endfunction
202
202
 
203
203
 
204
204
  function localStorageClear():
205
- objectSet(markdownUpState, 'localStorage', objectNew())
205
+ objectSet(markdownUpState, 'localStorage', {})
206
206
  endfunction
207
207
 
208
208
 
@@ -281,11 +281,11 @@ function schemaElements(types, typeName):
281
281
  if userTypeKey == 'struct' && objectGet(objectGet(userType, 'struct'), 'union'):
282
282
  userTypeKey = 'union'
283
283
  endif
284
- return arrayNew( \
285
- arrayNew( \
286
- objectNew('html', 'h1', 'elem', objectNew('text', userTypeKey + ' ' + typeName)) \
287
- ) \
288
- )
284
+ return [ \
285
+ [ \
286
+ {'html': 'h1', 'elem': {'text': userTypeKey + ' ' + typeName}} \
287
+ ] \
288
+ ]
289
289
  endfunction
290
290
 
291
291
 
@@ -295,7 +295,7 @@ endfunction
295
295
 
296
296
 
297
297
  function sessionStorageClear():
298
- objectSet(markdownUpState, 'sessionStorage', objectNew())
298
+ objectSet(markdownUpState, 'sessionStorage', {})
299
299
  endfunction
300
300
 
301
301
 
@@ -97,7 +97,7 @@ endfunction
97
97
  # $arg options: - **start** - The start page name
98
98
  # $arg options: - **keyboard** - Enable keyboard commands ('n' for next, 'p' for previous, 's' for start, 'e' for end)
99
99
  async function pagerMain(pagerModel, options):
100
- options = if(options != null, options, objectNew())
100
+ options = if(options != null, options, {})
101
101
  optionArguments = objectGet(options, 'arguments')
102
102
  optionHideMenu = objectGet(options, 'hideMenu')
103
103
  optionHideNav = objectGet(options, 'hideNav')
@@ -154,7 +154,7 @@ async function pagerMain(pagerModel, options):
154
154
  return
155
155
  endif
156
156
  else:
157
- arguments = arrayNew(objectNew('name', 'page', 'default', startPageName))
157
+ arguments = [{'name': 'page', 'default': startPageName}]
158
158
  endif
159
159
  args = argsParse(arguments)
160
160
  argPage = objectGet(args, 'page')
@@ -211,7 +211,7 @@ async function pagerMain(pagerModel, options):
211
211
 
212
212
  # Render the menu
213
213
  if !optionHideMenu:
214
- menuItems = arrayNew()
214
+ menuItems = []
215
215
  for page in pages:
216
216
  pageName = objectGet(page, 'name')
217
217
  pageHidden = objectGet(page, 'hidden')
@@ -231,7 +231,7 @@ async function pagerMain(pagerModel, options):
231
231
  elif pageName == objectGet(curPage, 'name'):
232
232
  arrayPush(menuItems, markdownEscape(pageName))
233
233
  else:
234
- arrayPush(menuItems, argsLink(arguments, pageName, objectNew('page', pageName)))
234
+ arrayPush(menuItems, argsLink(arguments, pageName, {'page': pageName}))
235
235
  endif
236
236
  endfor
237
237
  markdownPrint(arrayJoin(menuItems, '&nbsp;|&nbsp;'), '')
@@ -239,13 +239,13 @@ async function pagerMain(pagerModel, options):
239
239
 
240
240
  # Render the start/next/prev buttons
241
241
  if !optionHideNav && (nextPageName != null || prevPageName != null):
242
- navItems = arrayNew()
242
+ navItems = []
243
243
  arrayPush(navItems, \
244
- if(startPageName != curPageName, argsLink(arguments, 'Start', objectNew('page', startPageName)), 'Start'))
244
+ if(startPageName != curPageName, argsLink(arguments, 'Start', {'page': startPageName}), 'Start'))
245
245
  arrayPush(navItems, \
246
- if(prevPageName != null, argsLink(arguments, 'Previous', objectNew('page', prevPageName)), 'Previous'))
246
+ if(prevPageName != null, argsLink(arguments, 'Previous', {'page': prevPageName}), 'Previous'))
247
247
  arrayPush(navItems, \
248
- if(nextPageName != null, argsLink(arguments, 'Next', objectNew('page', nextPageName)), 'Next'))
248
+ if(nextPageName != null, argsLink(arguments, 'Next', {'page': nextPageName}), 'Next'))
249
249
  markdownPrint('(&nbsp;' + arrayJoin(navItems, '&nbsp;|&nbsp;') + '&nbsp;)', '')
250
250
  endif
251
251
 
@@ -294,15 +294,15 @@ function pagerKeyDown(arguments, curPageName, startPageName, endPageName, nextPa
294
294
  key = objectGet(event, 'key')
295
295
  if key == 's' && startPageName != curPageName:
296
296
  # Start slide
297
- windowSetLocation(argsURL(arguments, objectNew('page', startPageName)))
297
+ windowSetLocation(argsURL(arguments, {'page': startPageName}))
298
298
  elif key == 'e' && endPageName != curPageName:
299
299
  # End slide
300
- windowSetLocation(argsURL(arguments, objectNew('page', endPageName)))
300
+ windowSetLocation(argsURL(arguments, {'page': endPageName}))
301
301
  elif key == 'n' && nextPageName:
302
302
  # Next page
303
- windowSetLocation(argsURL(arguments, objectNew('page', nextPageName)))
303
+ windowSetLocation(argsURL(arguments, {'page': nextPageName}))
304
304
  elif key == 'p' && prevPageName:
305
305
  # Previous page
306
- windowSetLocation(argsURL(arguments, objectNew('page', prevPageName)))
306
+ windowSetLocation(argsURL(arguments, {'page': prevPageName}))
307
307
  endif
308
308
  endfunction