@ai-workbench/connect 0.0.0-stage → 0.7.6

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 (131) hide show
  1. package/NOTICE.md +18 -0
  2. package/README.md +26 -2
  3. package/client/index.cjs +124 -0
  4. package/cordis.patch.yml +3 -0
  5. package/helper/auth-status.cjs +18 -0
  6. package/helper/claude-callback.cjs +29 -0
  7. package/helper/main.cjs +19 -0
  8. package/helper/projects.cjs +57 -0
  9. package/helper/remote-command.cjs +15 -0
  10. package/helper/remote-login.cjs +25 -0
  11. package/helper/window.cjs +52 -0
  12. package/lib/api.d.ts +196 -0
  13. package/lib/api.js +1 -0
  14. package/lib/archive.d.ts +1 -0
  15. package/lib/archive.js +63 -0
  16. package/lib/auth-status.d.ts +3 -0
  17. package/lib/auth-status.js +18 -0
  18. package/lib/cache.d.ts +21 -0
  19. package/lib/cache.js +156 -0
  20. package/lib/component-download.d.ts +32 -0
  21. package/lib/component-download.js +76 -0
  22. package/lib/component-source.d.ts +52 -0
  23. package/lib/component-source.js +146 -0
  24. package/lib/components.d.ts +10 -0
  25. package/lib/components.js +154 -0
  26. package/lib/connect.d.ts +10 -0
  27. package/lib/connect.js +246 -0
  28. package/lib/cordis.d.ts +15 -0
  29. package/lib/cordis.js +1 -0
  30. package/lib/defaults.d.ts +30 -0
  31. package/lib/defaults.js +4 -0
  32. package/lib/electron.d.ts +8 -0
  33. package/lib/electron.js +83 -0
  34. package/lib/enrollment.d.ts +3 -0
  35. package/lib/enrollment.js +78 -0
  36. package/lib/index.d.ts +42 -0
  37. package/lib/index.js +55 -0
  38. package/lib/integration.d.ts +6 -0
  39. package/lib/integration.js +56 -0
  40. package/lib/login.d.ts +35 -0
  41. package/lib/login.js +81 -0
  42. package/lib/native-import-picker.d.ts +11 -0
  43. package/lib/native-import-picker.js +49 -0
  44. package/lib/needs.d.ts +9 -0
  45. package/lib/needs.js +52 -0
  46. package/lib/network.d.ts +26 -0
  47. package/lib/network.js +226 -0
  48. package/lib/physical-fs.d.ts +3 -0
  49. package/lib/physical-fs.js +7 -0
  50. package/lib/ports.d.ts +43 -0
  51. package/lib/ports.js +1 -0
  52. package/lib/private-files.d.ts +3 -0
  53. package/lib/private-files.js +41 -0
  54. package/lib/processes.d.ts +5 -0
  55. package/lib/processes.js +147 -0
  56. package/lib/profile-activation.d.ts +32 -0
  57. package/lib/profile-activation.js +118 -0
  58. package/lib/profile-enrollment.d.ts +21 -0
  59. package/lib/profile-enrollment.js +275 -0
  60. package/lib/profile-runtime.d.ts +6 -0
  61. package/lib/profile-runtime.js +47 -0
  62. package/lib/profile-settings.d.ts +2 -0
  63. package/lib/profile-settings.js +13 -0
  64. package/lib/projects.d.ts +4 -0
  65. package/lib/projects.js +41 -0
  66. package/lib/provider.d.ts +73 -0
  67. package/lib/provider.js +39 -0
  68. package/lib/remote-login.d.ts +2 -0
  69. package/lib/remote-login.js +9 -0
  70. package/lib/ssh.d.ts +10 -0
  71. package/lib/ssh.js +78 -0
  72. package/lib/startup.d.ts +18 -0
  73. package/lib/startup.js +211 -0
  74. package/lib/workspace-bindings.d.ts +32 -0
  75. package/lib/workspace-bindings.js +328 -0
  76. package/locale/en.json +6 -0
  77. package/locale/zh.json +6 -0
  78. package/node_modules/argparse/LICENSE +254 -0
  79. package/node_modules/argparse/README.md +84 -0
  80. package/node_modules/argparse/argparse.js +3707 -0
  81. package/node_modules/argparse/lib/sub.js +67 -0
  82. package/node_modules/argparse/lib/textwrap.js +440 -0
  83. package/node_modules/argparse/package.json +31 -0
  84. package/node_modules/js-yaml/LICENSE +21 -0
  85. package/node_modules/js-yaml/README.md +233 -0
  86. package/node_modules/js-yaml/bin/js-yaml.js +117 -0
  87. package/node_modules/js-yaml/dist/js-yaml.js +3022 -0
  88. package/node_modules/js-yaml/dist/js-yaml.js.map +1 -0
  89. package/node_modules/js-yaml/dist/js-yaml.min.js +2 -0
  90. package/node_modules/js-yaml/dist/js-yaml.min.js.map +1 -0
  91. package/node_modules/js-yaml/dist/js-yaml.mjs +3082 -0
  92. package/node_modules/js-yaml/dist/js-yaml.mjs.map +1 -0
  93. package/node_modules/js-yaml/index.js +44 -0
  94. package/node_modules/js-yaml/lib/common.js +50 -0
  95. package/node_modules/js-yaml/lib/dumper.js +937 -0
  96. package/node_modules/js-yaml/lib/exception.js +51 -0
  97. package/node_modules/js-yaml/lib/index_vite_proxy.tmp.mjs +37 -0
  98. package/node_modules/js-yaml/lib/loader.js +1803 -0
  99. package/node_modules/js-yaml/lib/schema/core.js +9 -0
  100. package/node_modules/js-yaml/lib/schema/default.js +20 -0
  101. package/node_modules/js-yaml/lib/schema/failsafe.js +14 -0
  102. package/node_modules/js-yaml/lib/schema/json.js +17 -0
  103. package/node_modules/js-yaml/lib/schema.js +109 -0
  104. package/node_modules/js-yaml/lib/snippet.js +96 -0
  105. package/node_modules/js-yaml/lib/type/binary.js +122 -0
  106. package/node_modules/js-yaml/lib/type/bool.js +35 -0
  107. package/node_modules/js-yaml/lib/type/float.js +99 -0
  108. package/node_modules/js-yaml/lib/type/int.js +142 -0
  109. package/node_modules/js-yaml/lib/type/map.js +8 -0
  110. package/node_modules/js-yaml/lib/type/merge.js +12 -0
  111. package/node_modules/js-yaml/lib/type/null.js +35 -0
  112. package/node_modules/js-yaml/lib/type/omap.js +45 -0
  113. package/node_modules/js-yaml/lib/type/pairs.js +50 -0
  114. package/node_modules/js-yaml/lib/type/seq.js +8 -0
  115. package/node_modules/js-yaml/lib/type/set.js +29 -0
  116. package/node_modules/js-yaml/lib/type/str.js +8 -0
  117. package/node_modules/js-yaml/lib/type/timestamp.js +88 -0
  118. package/node_modules/js-yaml/lib/type.js +66 -0
  119. package/node_modules/js-yaml/package.json +83 -0
  120. package/node_modules/pend/LICENSE +23 -0
  121. package/node_modules/pend/README.md +41 -0
  122. package/node_modules/pend/index.js +55 -0
  123. package/node_modules/pend/package.json +18 -0
  124. package/node_modules/pend/test.js +137 -0
  125. package/node_modules/yauzl/LICENSE +21 -0
  126. package/node_modules/yauzl/README.md +1015 -0
  127. package/node_modules/yauzl/crc32.js +45 -0
  128. package/node_modules/yauzl/fd-slicer.js +188 -0
  129. package/node_modules/yauzl/index.js +1096 -0
  130. package/node_modules/yauzl/package.json +40 -0
  131. package/package.json +89 -4
@@ -0,0 +1,9 @@
1
+ // Standard YAML's Core schema.
2
+ // http://www.yaml.org/spec/1.2/spec.html#id2804923
3
+ //
4
+ // NOTE: JS-YAML does not support schema-specific tag resolution restrictions.
5
+ // So, Core schema has no distinctions from JSON schema is JS-YAML.
6
+
7
+ 'use strict'
8
+
9
+ module.exports = require('./json')
@@ -0,0 +1,20 @@
1
+ // JS-YAML's default schema for `safeLoad` function.
2
+ // It is not described in the YAML specification.
3
+ //
4
+ // This schema is based on standard YAML's Core schema and includes most of
5
+ // extra types described at YAML tag repository. (http://yaml.org/type/)
6
+
7
+ 'use strict'
8
+
9
+ module.exports = require('./core').extend({
10
+ implicit: [
11
+ require('../type/timestamp'),
12
+ require('../type/merge')
13
+ ],
14
+ explicit: [
15
+ require('../type/binary'),
16
+ require('../type/omap'),
17
+ require('../type/pairs'),
18
+ require('../type/set')
19
+ ]
20
+ })
@@ -0,0 +1,14 @@
1
+ // Standard YAML's Failsafe schema.
2
+ // http://www.yaml.org/spec/1.2/spec.html#id2802346
3
+
4
+ 'use strict'
5
+
6
+ const Schema = require('../schema')
7
+
8
+ module.exports = new Schema({
9
+ explicit: [
10
+ require('../type/str'),
11
+ require('../type/seq'),
12
+ require('../type/map')
13
+ ]
14
+ })
@@ -0,0 +1,17 @@
1
+ // Standard YAML's JSON schema.
2
+ // http://www.yaml.org/spec/1.2/spec.html#id2803231
3
+ //
4
+ // NOTE: JS-YAML does not support schema-specific tag resolution restrictions.
5
+ // So, this schema is not such strict as defined in the YAML specification.
6
+ // It allows numbers in binary notaion, use `Null` and `NULL` as `null`, etc.
7
+
8
+ 'use strict'
9
+
10
+ module.exports = require('./failsafe').extend({
11
+ implicit: [
12
+ require('../type/null'),
13
+ require('../type/bool'),
14
+ require('../type/int'),
15
+ require('../type/float')
16
+ ]
17
+ })
@@ -0,0 +1,109 @@
1
+ 'use strict'
2
+
3
+ const YAMLException = require('./exception')
4
+ const Type = require('./type')
5
+
6
+ function compileList (schema, name) {
7
+ const result = []
8
+
9
+ schema[name].forEach(function (currentType) {
10
+ let newIndex = result.length
11
+
12
+ result.forEach(function (previousType, previousIndex) {
13
+ if (previousType.tag === currentType.tag &&
14
+ previousType.kind === currentType.kind &&
15
+ previousType.multi === currentType.multi) {
16
+ newIndex = previousIndex
17
+ }
18
+ })
19
+
20
+ result[newIndex] = currentType
21
+ })
22
+
23
+ return result
24
+ }
25
+
26
+ function compileMap (/* lists... */) {
27
+ const result = {
28
+ scalar: {},
29
+ sequence: {},
30
+ mapping: {},
31
+ fallback: {},
32
+ multi: {
33
+ scalar: [],
34
+ sequence: [],
35
+ mapping: [],
36
+ fallback: []
37
+ }
38
+ }
39
+ function collectType (type) {
40
+ if (type.multi) {
41
+ result.multi[type.kind].push(type)
42
+ result.multi['fallback'].push(type)
43
+ } else {
44
+ result[type.kind][type.tag] = result['fallback'][type.tag] = type
45
+ }
46
+ }
47
+
48
+ for (let index = 0, length = arguments.length; index < length; index += 1) {
49
+ arguments[index].forEach(collectType)
50
+ }
51
+ return result
52
+ }
53
+
54
+ function Schema (definition) {
55
+ return this.extend(definition)
56
+ }
57
+
58
+ Schema.prototype.extend = function extend (definition) {
59
+ let implicit = []
60
+ let explicit = []
61
+
62
+ if (definition instanceof Type) {
63
+ // Schema.extend(type)
64
+ explicit.push(definition)
65
+ } else if (Array.isArray(definition)) {
66
+ // Schema.extend([ type1, type2, ... ])
67
+ explicit = explicit.concat(definition)
68
+ } else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
69
+ // Schema.extend({ explicit: [ type1, type2, ... ], implicit: [ type1, type2, ... ] })
70
+ if (definition.implicit) implicit = implicit.concat(definition.implicit)
71
+ if (definition.explicit) explicit = explicit.concat(definition.explicit)
72
+ } else {
73
+ throw new YAMLException('Schema.extend argument should be a Type, [ Type ], ' +
74
+ 'or a schema definition ({ implicit: [...], explicit: [...] })')
75
+ }
76
+
77
+ implicit.forEach(function (type) {
78
+ if (!(type instanceof Type)) {
79
+ throw new YAMLException('Specified list of YAML types (or a single Type object) contains a non-Type object.')
80
+ }
81
+
82
+ if (type.loadKind && type.loadKind !== 'scalar') {
83
+ throw new YAMLException('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.')
84
+ }
85
+
86
+ if (type.multi) {
87
+ throw new YAMLException('There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.')
88
+ }
89
+ })
90
+
91
+ explicit.forEach(function (type) {
92
+ if (!(type instanceof Type)) {
93
+ throw new YAMLException('Specified list of YAML types (or a single Type object) contains a non-Type object.')
94
+ }
95
+ })
96
+
97
+ const result = Object.create(Schema.prototype)
98
+
99
+ result.implicit = (this.implicit || []).concat(implicit)
100
+ result.explicit = (this.explicit || []).concat(explicit)
101
+
102
+ result.compiledImplicit = compileList(result, 'implicit')
103
+ result.compiledExplicit = compileList(result, 'explicit')
104
+ result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit)
105
+
106
+ return result
107
+ }
108
+
109
+ module.exports = Schema
@@ -0,0 +1,96 @@
1
+ 'use strict'
2
+
3
+ const common = require('./common')
4
+
5
+ // get snippet for a single line, respecting maxLength
6
+ function getLine (buffer, lineStart, lineEnd, position, maxLineLength) {
7
+ let head = ''
8
+ let tail = ''
9
+ const maxHalfLength = Math.floor(maxLineLength / 2) - 1
10
+
11
+ if (position - lineStart > maxHalfLength) {
12
+ head = ' ... '
13
+ lineStart = position - maxHalfLength + head.length
14
+ }
15
+
16
+ if (lineEnd - position > maxHalfLength) {
17
+ tail = ' ...'
18
+ lineEnd = position + maxHalfLength - tail.length
19
+ }
20
+
21
+ return {
22
+ str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, '→') + tail,
23
+ pos: position - lineStart + head.length // relative position
24
+ }
25
+ }
26
+
27
+ function padStart (string, max) {
28
+ return common.repeat(' ', max - string.length) + string
29
+ }
30
+
31
+ function makeSnippet (mark, options) {
32
+ options = Object.create(options || null)
33
+
34
+ if (!mark.buffer) return null
35
+
36
+ if (!options.maxLength) options.maxLength = 79
37
+ if (typeof options.indent !== 'number') options.indent = 1
38
+ if (typeof options.linesBefore !== 'number') options.linesBefore = 3
39
+ if (typeof options.linesAfter !== 'number') options.linesAfter = 2
40
+
41
+ const re = /\r?\n|\r|\0/g
42
+ const lineStarts = [0]
43
+ const lineEnds = []
44
+ let match
45
+ let foundLineNo = -1
46
+
47
+ while ((match = re.exec(mark.buffer))) {
48
+ lineEnds.push(match.index)
49
+ lineStarts.push(match.index + match[0].length)
50
+
51
+ if (mark.position <= match.index && foundLineNo < 0) {
52
+ foundLineNo = lineStarts.length - 2
53
+ }
54
+ }
55
+
56
+ if (foundLineNo < 0) foundLineNo = lineStarts.length - 1
57
+
58
+ let result = ''
59
+ const lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length
60
+ const maxLineLength = options.maxLength - (options.indent + lineNoLength + 3)
61
+
62
+ for (let i = 1; i <= options.linesBefore; i++) {
63
+ if (foundLineNo - i < 0) break
64
+ const line = getLine(
65
+ mark.buffer,
66
+ lineStarts[foundLineNo - i],
67
+ lineEnds[foundLineNo - i],
68
+ mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
69
+ maxLineLength
70
+ )
71
+ result = common.repeat(' ', options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) +
72
+ ' | ' + line.str + '\n' + result
73
+ }
74
+
75
+ const line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength)
76
+ result += common.repeat(' ', options.indent) + padStart((mark.line + 1).toString(), lineNoLength) +
77
+ ' | ' + line.str + '\n'
78
+ result += common.repeat('-', options.indent + lineNoLength + 3 + line.pos) + '^' + '\n'
79
+
80
+ for (let i = 1; i <= options.linesAfter; i++) {
81
+ if (foundLineNo + i >= lineEnds.length) break
82
+ const line = getLine(
83
+ mark.buffer,
84
+ lineStarts[foundLineNo + i],
85
+ lineEnds[foundLineNo + i],
86
+ mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
87
+ maxLineLength
88
+ )
89
+ result += common.repeat(' ', options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) +
90
+ ' | ' + line.str + '\n'
91
+ }
92
+
93
+ return result.replace(/\n$/, '')
94
+ }
95
+
96
+ module.exports = makeSnippet
@@ -0,0 +1,122 @@
1
+ 'use strict'
2
+
3
+ const Type = require('../type')
4
+
5
+ // [ 64, 65, 66 ] -> [ padding, CR, LF ]
6
+ const BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r'
7
+
8
+ function resolveYamlBinary (data) {
9
+ if (data === null) return false
10
+
11
+ let bitlen = 0
12
+ const max = data.length
13
+ const map = BASE64_MAP
14
+
15
+ // Convert one by one.
16
+ for (let idx = 0; idx < max; idx++) {
17
+ const code = map.indexOf(data.charAt(idx))
18
+
19
+ // Skip CR/LF
20
+ if (code > 64) continue
21
+
22
+ // Fail on illegal characters
23
+ if (code < 0) return false
24
+
25
+ bitlen += 6
26
+ }
27
+
28
+ // If there are any bits left, source was corrupted
29
+ return (bitlen % 8) === 0
30
+ }
31
+
32
+ function constructYamlBinary (data) {
33
+ const input = data.replace(/[\r\n=]/g, '') // remove CR/LF & padding to simplify scan
34
+ const max = input.length
35
+ const map = BASE64_MAP
36
+ let bits = 0
37
+ const result = []
38
+
39
+ // Collect by 6*4 bits (3 bytes)
40
+
41
+ for (let idx = 0; idx < max; idx++) {
42
+ if ((idx % 4 === 0) && idx) {
43
+ result.push((bits >> 16) & 0xFF)
44
+ result.push((bits >> 8) & 0xFF)
45
+ result.push(bits & 0xFF)
46
+ }
47
+
48
+ bits = (bits << 6) | map.indexOf(input.charAt(idx))
49
+ }
50
+
51
+ // Dump tail
52
+
53
+ const tailbits = (max % 4) * 6
54
+
55
+ if (tailbits === 0) {
56
+ result.push((bits >> 16) & 0xFF)
57
+ result.push((bits >> 8) & 0xFF)
58
+ result.push(bits & 0xFF)
59
+ } else if (tailbits === 18) {
60
+ result.push((bits >> 10) & 0xFF)
61
+ result.push((bits >> 2) & 0xFF)
62
+ } else if (tailbits === 12) {
63
+ result.push((bits >> 4) & 0xFF)
64
+ }
65
+
66
+ return new Uint8Array(result)
67
+ }
68
+
69
+ function representYamlBinary (object /*, style */) {
70
+ let result = ''
71
+ let bits = 0
72
+ const max = object.length
73
+ const map = BASE64_MAP
74
+
75
+ // Convert every three bytes to 4 ASCII characters.
76
+
77
+ for (let idx = 0; idx < max; idx++) {
78
+ if ((idx % 3 === 0) && idx) {
79
+ result += map[(bits >> 18) & 0x3F]
80
+ result += map[(bits >> 12) & 0x3F]
81
+ result += map[(bits >> 6) & 0x3F]
82
+ result += map[bits & 0x3F]
83
+ }
84
+
85
+ bits = (bits << 8) + object[idx]
86
+ }
87
+
88
+ // Dump tail
89
+
90
+ const tail = max % 3
91
+
92
+ if (tail === 0) {
93
+ result += map[(bits >> 18) & 0x3F]
94
+ result += map[(bits >> 12) & 0x3F]
95
+ result += map[(bits >> 6) & 0x3F]
96
+ result += map[bits & 0x3F]
97
+ } else if (tail === 2) {
98
+ result += map[(bits >> 10) & 0x3F]
99
+ result += map[(bits >> 4) & 0x3F]
100
+ result += map[(bits << 2) & 0x3F]
101
+ result += map[64]
102
+ } else if (tail === 1) {
103
+ result += map[(bits >> 2) & 0x3F]
104
+ result += map[(bits << 4) & 0x3F]
105
+ result += map[64]
106
+ result += map[64]
107
+ }
108
+
109
+ return result
110
+ }
111
+
112
+ function isBinary (obj) {
113
+ return Object.prototype.toString.call(obj) === '[object Uint8Array]'
114
+ }
115
+
116
+ module.exports = new Type('tag:yaml.org,2002:binary', {
117
+ kind: 'scalar',
118
+ resolve: resolveYamlBinary,
119
+ construct: constructYamlBinary,
120
+ predicate: isBinary,
121
+ represent: representYamlBinary
122
+ })
@@ -0,0 +1,35 @@
1
+ 'use strict'
2
+
3
+ const Type = require('../type')
4
+
5
+ function resolveYamlBoolean (data) {
6
+ if (data === null) return false
7
+
8
+ const max = data.length
9
+
10
+ return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
11
+ (max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'))
12
+ }
13
+
14
+ function constructYamlBoolean (data) {
15
+ return data === 'true' ||
16
+ data === 'True' ||
17
+ data === 'TRUE'
18
+ }
19
+
20
+ function isBoolean (object) {
21
+ return Object.prototype.toString.call(object) === '[object Boolean]'
22
+ }
23
+
24
+ module.exports = new Type('tag:yaml.org,2002:bool', {
25
+ kind: 'scalar',
26
+ resolve: resolveYamlBoolean,
27
+ construct: constructYamlBoolean,
28
+ predicate: isBoolean,
29
+ represent: {
30
+ lowercase: function (object) { return object ? 'true' : 'false' },
31
+ uppercase: function (object) { return object ? 'TRUE' : 'FALSE' },
32
+ camelcase: function (object) { return object ? 'True' : 'False' }
33
+ },
34
+ defaultStyle: 'lowercase'
35
+ })
@@ -0,0 +1,99 @@
1
+ 'use strict'
2
+
3
+ const common = require('../common')
4
+ const Type = require('../type')
5
+
6
+ const YAML_FLOAT_PATTERN = new RegExp(
7
+ // 2.5e4, 2.5 and integers
8
+ '^(?:[-+]?(?:[0-9]+)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?' +
9
+ // .2e4, .2
10
+ // special case, seems not from spec
11
+ '|\\.[0-9]+(?:[eE][-+]?[0-9]+)?' +
12
+ // .inf
13
+ '|[-+]?\\.(?:inf|Inf|INF)' +
14
+ // .nan
15
+ '|\\.(?:nan|NaN|NAN))$')
16
+
17
+ const YAML_FLOAT_SPECIAL_PATTERN = new RegExp(
18
+ '^(?:' +
19
+ // .inf
20
+ '[-+]?\\.(?:inf|Inf|INF)' +
21
+ // .nan
22
+ '|\\.(?:nan|NaN|NAN))$')
23
+
24
+ function resolveYamlFloat (data) {
25
+ if (data === null) return false
26
+
27
+ if (!YAML_FLOAT_PATTERN.test(data)) {
28
+ return false
29
+ }
30
+
31
+ if (isFinite(parseFloat(data, 10))) {
32
+ return true
33
+ }
34
+
35
+ return YAML_FLOAT_SPECIAL_PATTERN.test(data)
36
+ }
37
+
38
+ function constructYamlFloat (data) {
39
+ let value = data.toLowerCase()
40
+ const sign = value[0] === '-' ? -1 : 1
41
+
42
+ if ('+-'.indexOf(value[0]) >= 0) {
43
+ value = value.slice(1)
44
+ }
45
+
46
+ if (value === '.inf') {
47
+ return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY
48
+ } else if (value === '.nan') {
49
+ return NaN
50
+ }
51
+ return sign * parseFloat(value, 10)
52
+ }
53
+
54
+ const SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/
55
+
56
+ function representYamlFloat (object, style) {
57
+ if (isNaN(object)) {
58
+ switch (style) {
59
+ case 'lowercase': return '.nan'
60
+ case 'uppercase': return '.NAN'
61
+ case 'camelcase': return '.NaN'
62
+ }
63
+ } else if (Number.POSITIVE_INFINITY === object) {
64
+ switch (style) {
65
+ case 'lowercase': return '.inf'
66
+ case 'uppercase': return '.INF'
67
+ case 'camelcase': return '.Inf'
68
+ }
69
+ } else if (Number.NEGATIVE_INFINITY === object) {
70
+ switch (style) {
71
+ case 'lowercase': return '-.inf'
72
+ case 'uppercase': return '-.INF'
73
+ case 'camelcase': return '-.Inf'
74
+ }
75
+ } else if (common.isNegativeZero(object)) {
76
+ return '-0.0'
77
+ }
78
+
79
+ const res = object.toString(10)
80
+
81
+ // JS stringifier can build scientific format without dots: 5e-100,
82
+ // while YAML requres dot: 5.e-100. Fix it with simple hack
83
+
84
+ return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res
85
+ }
86
+
87
+ function isFloat (object) {
88
+ return (Object.prototype.toString.call(object) === '[object Number]') &&
89
+ (object % 1 !== 0 || common.isNegativeZero(object))
90
+ }
91
+
92
+ module.exports = new Type('tag:yaml.org,2002:float', {
93
+ kind: 'scalar',
94
+ resolve: resolveYamlFloat,
95
+ construct: constructYamlFloat,
96
+ predicate: isFloat,
97
+ represent: representYamlFloat,
98
+ defaultStyle: 'lowercase'
99
+ })
@@ -0,0 +1,142 @@
1
+ 'use strict'
2
+
3
+ const common = require('../common')
4
+ const Type = require('../type')
5
+
6
+ function isHexCode (c) {
7
+ return ((c >= 0x30/* 0 */) && (c <= 0x39/* 9 */)) ||
8
+ ((c >= 0x41/* A */) && (c <= 0x46/* F */)) ||
9
+ ((c >= 0x61/* a */) && (c <= 0x66/* f */))
10
+ }
11
+
12
+ function isOctCode (c) {
13
+ return ((c >= 0x30/* 0 */) && (c <= 0x37/* 7 */))
14
+ }
15
+
16
+ function isDecCode (c) {
17
+ return ((c >= 0x30/* 0 */) && (c <= 0x39/* 9 */))
18
+ }
19
+
20
+ function resolveYamlInteger (data) {
21
+ if (data === null) return false
22
+
23
+ const max = data.length
24
+ let index = 0
25
+ let hasDigits = false
26
+
27
+ if (!max) return false
28
+
29
+ let ch = data[index]
30
+
31
+ // sign
32
+ if (ch === '-' || ch === '+') {
33
+ ch = data[++index]
34
+ }
35
+
36
+ if (ch === '0') {
37
+ // 0
38
+ if (index + 1 === max) return true
39
+ ch = data[++index]
40
+
41
+ // base 2, base 8, base 16
42
+
43
+ if (ch === 'b') {
44
+ // base 2
45
+ index++
46
+
47
+ for (; index < max; index++) {
48
+ ch = data[index]
49
+ if (ch !== '0' && ch !== '1') return false
50
+ hasDigits = true
51
+ }
52
+ return hasDigits && isFinite(parseYamlInteger(data))
53
+ }
54
+
55
+ if (ch === 'x') {
56
+ // base 16
57
+ index++
58
+
59
+ for (; index < max; index++) {
60
+ if (!isHexCode(data.charCodeAt(index))) return false
61
+ hasDigits = true
62
+ }
63
+ return hasDigits && isFinite(parseYamlInteger(data))
64
+ }
65
+
66
+ if (ch === 'o') {
67
+ // base 8
68
+ index++
69
+
70
+ for (; index < max; index++) {
71
+ if (!isOctCode(data.charCodeAt(index))) return false
72
+ hasDigits = true
73
+ }
74
+ return hasDigits && isFinite(parseYamlInteger(data))
75
+ }
76
+ }
77
+
78
+ // base 10 (except 0)
79
+
80
+ for (; index < max; index++) {
81
+ if (!isDecCode(data.charCodeAt(index))) {
82
+ return false
83
+ }
84
+ hasDigits = true
85
+ }
86
+
87
+ if (!hasDigits) return false
88
+
89
+ return isFinite(parseYamlInteger(data))
90
+ }
91
+
92
+ function parseYamlInteger (data) {
93
+ let value = data
94
+ let sign = 1
95
+
96
+ let ch = value[0]
97
+
98
+ if (ch === '-' || ch === '+') {
99
+ if (ch === '-') sign = -1
100
+ value = value.slice(1)
101
+ ch = value[0]
102
+ }
103
+
104
+ if (value === '0') return 0
105
+
106
+ if (ch === '0') {
107
+ if (value[1] === 'b') return sign * parseInt(value.slice(2), 2)
108
+ if (value[1] === 'x') return sign * parseInt(value.slice(2), 16)
109
+ if (value[1] === 'o') return sign * parseInt(value.slice(2), 8)
110
+ }
111
+
112
+ return sign * parseInt(value, 10)
113
+ }
114
+
115
+ function constructYamlInteger (data) {
116
+ return parseYamlInteger(data)
117
+ }
118
+
119
+ function isInteger (object) {
120
+ return (Object.prototype.toString.call(object)) === '[object Number]' &&
121
+ (object % 1 === 0 && !common.isNegativeZero(object))
122
+ }
123
+
124
+ module.exports = new Type('tag:yaml.org,2002:int', {
125
+ kind: 'scalar',
126
+ resolve: resolveYamlInteger,
127
+ construct: constructYamlInteger,
128
+ predicate: isInteger,
129
+ represent: {
130
+ binary: function (obj) { return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1) },
131
+ octal: function (obj) { return obj >= 0 ? '0o' + obj.toString(8) : '-0o' + obj.toString(8).slice(1) },
132
+ decimal: function (obj) { return obj.toString(10) },
133
+ hexadecimal: function (obj) { return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1) }
134
+ },
135
+ defaultStyle: 'decimal',
136
+ styleAliases: {
137
+ binary: [2, 'bin'],
138
+ octal: [8, 'oct'],
139
+ decimal: [10, 'dec'],
140
+ hexadecimal: [16, 'hex']
141
+ }
142
+ })
@@ -0,0 +1,8 @@
1
+ 'use strict'
2
+
3
+ const Type = require('../type')
4
+
5
+ module.exports = new Type('tag:yaml.org,2002:map', {
6
+ kind: 'mapping',
7
+ construct: function (data) { return data !== null ? data : {} }
8
+ })
@@ -0,0 +1,12 @@
1
+ 'use strict'
2
+
3
+ const Type = require('../type')
4
+
5
+ function resolveYamlMerge (data) {
6
+ return data === '<<' || data === null
7
+ }
8
+
9
+ module.exports = new Type('tag:yaml.org,2002:merge', {
10
+ kind: 'scalar',
11
+ resolve: resolveYamlMerge
12
+ })