functionalscript 0.0.197 → 0.0.202

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/btree/index.js CHANGED
@@ -1,4 +1,5 @@
1
- const { index3, index5 } = require('../cmp')
1
+ const cmp = require('../cmp')
2
+ const { index3, index5 } = cmp
2
3
  const seq = require('../sequence')
3
4
 
4
5
  /**
@@ -8,29 +9,29 @@ const seq = require('../sequence')
8
9
 
9
10
  /**
10
11
  * @template T
11
- * @typedef {import('../cmp').Cmp<T>} Cmp
12
+ * @typedef {cmp.Cmp<T>} Cmp
12
13
  */
13
14
 
14
15
  /**
15
16
  * @template T
16
- * @typedef {import('../sequence/array').Array1<T>} Array1
17
+ * @typedef {readonly[T]} Array1
17
18
  */
18
19
 
19
20
  /**
20
21
  * @template T
21
- * @typedef {import('../sequence/array').Array2<T>} Array2
22
+ * @typedef {readonly[T,T]} Array2
22
23
  */
23
24
 
24
25
  /**
25
26
  * @template T
26
- * @typedef {import('../sequence/array').Array3<T>} Array3
27
+ * @typedef {readonly[T,T,T]} Array3
27
28
  */
28
29
 
29
- /** @typedef {import('../sequence/array').Index2} Index2 */
30
+ /** @typedef {0|1} Index2 */
30
31
 
31
- /** @typedef {import('../sequence/array').Index3} Index3 */
32
+ /** @typedef {0|1|2} Index3 */
32
33
 
33
- /** @typedef {import('../sequence/array').Index5} Index5 */
34
+ /** @typedef {0|1|2|3|4} Index5 */
34
35
 
35
36
  //
36
37
 
@@ -59,14 +60,11 @@ const seq = require('../sequence')
59
60
  * @typedef { Leaf1<T> | Leaf2<T> | Branch3<T> | Branch5<T>} Node
60
61
  */
61
62
 
62
- /** @typedef {{ readonly done: false }} NotFoundDone */
63
+ /** @typedef {readonly['done']} NotFoundDone */
63
64
 
64
65
  /**
65
66
  * @template T
66
- * @typedef {{
67
- * readonly done: true
68
- * readonly value: T
69
- * }} FoundDone
67
+ * @typedef {readonly['done', T]} FoundDone
70
68
  */
71
69
 
72
70
  /**
@@ -76,12 +74,12 @@ const seq = require('../sequence')
76
74
 
77
75
  /**
78
76
  * @template T
79
- * @typedef {{ readonly replace: Node<T> }} Replace
77
+ * @typedef {readonly['replace', Node<T>]} Replace
80
78
  */
81
79
 
82
80
  /**
83
81
  * @template T
84
- * @typedef {{ readonly overflow: Branch3<T> }} Overflow
82
+ * @typedef {readonly['overflow', Branch3<T>]} Overflow
85
83
  */
86
84
 
87
85
  /**
@@ -137,9 +135,11 @@ const split = ([n0, v1, n2, v3, n4, v5, n6]) => [[n0, v1, n2], v3, [n4, v5, n6]]
137
135
  * Result<T>}
138
136
  */
139
137
  const merge = overflow => replace => result => {
140
- if ('done' in result) { return result }
141
- if ('replace' in result) { return { replace: replace(result.replace) } }
142
- return overflow(result.overflow)
138
+ switch (result[0]) {
139
+ case 'done': { return result }
140
+ case 'replace': { return ['replace', replace(result[1])] }
141
+ default: { return overflow(result[1]) }
142
+ }
143
143
  }
144
144
 
145
145
  /**
@@ -148,7 +148,7 @@ const merge = overflow => replace => result => {
148
148
  * (result: Result<T>) =>
149
149
  * Result<T>}
150
150
  */
151
- const merge2 = overflow => merge(o => ({ replace: overflow(o) }))
151
+ const merge2 = overflow => merge(o => ['replace', overflow(o)])
152
152
 
153
153
  /**
154
154
  * @type {<T>(overflow: (o: Branch3<T>) => Branch7<T>) =>
@@ -156,7 +156,7 @@ const merge2 = overflow => merge(o => ({ replace: overflow(o) }))
156
156
  * (result: Result<T>) =>
157
157
  * Result<T>}
158
158
  */
159
- const merge3 = overflow => merge(o => ({ overflow: split(overflow(o)) }))
159
+ const merge3 = overflow => merge(o => ['overflow', split(overflow(o))])
160
160
 
161
161
  /** @type {(visitor: Visitor) => <T>(cmp: Cmp<T>) => (init: Lazy<T>) => (node: Node<T>) => Result<T>} */
162
162
  const visit = ({ found, notFound }) => cmp => {
@@ -233,7 +233,7 @@ const visit = ({ found, notFound }) => cmp => {
233
233
  }
234
234
 
235
235
  /** @type { <T>(_: T) => Done<T> } */
236
- const found = value => ({ done: true, value })
236
+ const found = value => ['done', value]
237
237
 
238
238
  /** @type {Found} */
239
239
  const foundGet = {
@@ -245,7 +245,7 @@ const foundGet = {
245
245
  branch5_right: () => ([, , , value]) => found(value),
246
246
  }
247
247
  /** @type { () => () => NotFoundDone } */
248
- const notFound = () => () => ({ done: false })
248
+ const notFound = () => () => ['done']
249
249
 
250
250
  /** @type {NotFound} */
251
251
  const notFoundGet = {
@@ -257,7 +257,7 @@ const notFoundGet = {
257
257
  }
258
258
 
259
259
  /** @type { <T>(_: Node<T>) => Replace<T> } */
260
- const replace = node => ({ replace: node })
260
+ const replace = node => ['replace', node]
261
261
 
262
262
  /** @type {Found} */
263
263
  const foundReplace = {
@@ -270,7 +270,7 @@ const foundReplace = {
270
270
  }
271
271
 
272
272
  /** @type {<T>(leaf3: Array3<T>) => Result<T>} */
273
- const overflow = ([v0, v1, v2]) => ({ overflow: [[v0], v1, [v2]] })
273
+ const overflow = ([v0, v1, v2]) => ['overflow', [[v0], v1, [v2]]]
274
274
 
275
275
  /** @type {NotFound} */
276
276
  const notFoundInsert = {
@@ -339,8 +339,8 @@ module.exports = {
339
339
  * @type { <T>(cmp: Cmp<T>) => (node: Node<T>) => T|undefined }
340
340
  */
341
341
  getVisitor: cmp => node => {
342
- const _0 = visit(getVisitor)(cmp)(() => { throw '' })(node)
343
- if ('done' in _0 && _0.done) { return _0.value }
342
+ const result = visit(getVisitor)(cmp)(() => { throw '' })(node)
343
+ if (result[0] === 'done') { return result[1] }
344
344
  return undefined
345
345
  },
346
346
  /** @readonly */
package/btree/test.js CHANGED
@@ -1,14 +1,15 @@
1
1
  const btree = require('.')
2
- const { setVisitor, values: valuesList } = btree
2
+ const { setVisitor, values } = btree
3
3
  const { cmp } = require('../cmp')
4
4
  const list = require('../sequence')
5
5
 
6
6
  /** @type {(node: btree.Node<string>) => (value: string) => btree.Node<string>} */
7
7
  const set = node => value => {
8
8
  const result = setVisitor(cmp(value))(() => value)(node)
9
- if ('replace' in result) { return result.replace }
10
- if ('overflow' in result) { return result.overflow }
11
- return node
9
+ switch (result[0]) {
10
+ case 'replace': case 'overflow': { return result[1] }
11
+ default: { return node }
12
+ }
12
13
  }
13
14
 
14
15
  const test = () => {
@@ -22,7 +23,7 @@ const test = () => {
22
23
  //
23
24
  {
24
25
  /** @type {import('../sequence').Result<string>} */
25
- let _item = list.next(valuesList(_map))
26
+ let _item = list.next(values(_map))
26
27
  while (_item !== undefined) {
27
28
  _item = list.next(_item[1])
28
29
  }
package/json/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const seq = require('../sequence')
2
2
  const map = require('../map')
3
3
  const op = require('../sequence/operator')
4
- const option = require('../option')
4
+ const object = require('../object')
5
5
  const array = require('../sequence/array')
6
6
 
7
7
  /**
@@ -27,12 +27,28 @@ const addProperty = value => {
27
27
  return path => f(array.sequence(path))
28
28
  }
29
29
 
30
+ /** @type {(_: string) => seq.Sequence<string>} */
31
+ const stringSerialize = input => seq.list(JSON.stringify(input))
32
+
33
+ /** @type {(_: number) => seq.Sequence<string>} */
34
+ const numberSerialize = input => seq.list(JSON.stringify(input))
35
+
36
+ const nullSerialize = seq.list('null')
37
+
38
+ const trueSerialize = seq.list('true')
39
+
40
+ const falseSerialize = seq.list('false')
41
+
42
+ /** @type {(_: boolean) => seq.Sequence<string>} */
43
+ const boolSerialize = value => value ? trueSerialize : falseSerialize
44
+
30
45
  /** @type {(kv: readonly[string, Json]) => seq.Sequence<string>} */
31
- const property = ([k, v]) => seq.concat(
32
- seq.list(JSON.stringify(k)),
33
- seq.list(':'),
34
- stringSequence(v))
46
+ const propertySerialize = ([k, v]) => seq.concat(
47
+ stringSerialize(k),
48
+ colon,
49
+ serialize(v))
35
50
 
51
+ const colon = seq.list(':')
36
52
  const comma = seq.list(',')
37
53
 
38
54
  /** @type {op.Scan<seq.Sequence<string>, seq.Sequence<string>>} */
@@ -59,48 +75,54 @@ const objectList = list('{')('}')
59
75
  const arrayList = list('[')(']')
60
76
 
61
77
  /** @type {(object: Object) => seq.Sequence<string>} */
62
- const objectStringify = object => {
63
- const _0 = Object.entries(object)
64
- const _1 = array.sequence(_0)
65
- const _2 = map.fromEntries(_1)
66
- const _3 = _2.entries
67
- const _4 = seq.map(property)(_3)
68
- return objectList(_4)
78
+ const objectSerialize = input => {
79
+ const _0 = object.entries(input)
80
+ const _1 = map.fromEntries(_0).entries
81
+ const _2 = seq.map(propertySerialize)(_1)
82
+ return objectList(_2)
69
83
  }
70
84
 
71
85
  /** @type {(input: Array) => seq.Sequence<string>} */
72
- const arrayStringify = input => {
86
+ const arraySerialize = input => {
73
87
  const _0 = array.sequence(input)
74
- const _1 = seq.map(stringSequence)(_0)
88
+ const _1 = seq.map(serialize)(_0)
75
89
  return arrayList(_1)
76
90
  }
77
91
 
78
92
  /** @type {(value: Json) => seq.Sequence<string>} */
79
- const stringSequence = value => {
80
- const x = typeof value
93
+ const serialize = value => {
81
94
  switch (typeof value) {
82
- case 'boolean': { return seq.list(value ? "true" : "false") }
83
- // Note: we shouldn't use JSON.stringify since it has non determenistic behavior.
84
- // In particular: property order could be different.
85
- case 'number': case 'string': { return seq.list(JSON.stringify(value)) }
95
+ case 'boolean': { return boolSerialize(value) }
96
+ case 'number': { return numberSerialize(value) }
97
+ case 'string': { return stringSerialize(value) }
86
98
  default: {
87
- if (value === null) { return seq.list("null") }
88
- if (value instanceof Array) { return arrayStringify(value) }
89
- return objectStringify(value)
99
+ if (value === null) { return nullSerialize }
100
+ if (value instanceof Array) { return arraySerialize(value) }
101
+ return objectSerialize(value)
90
102
  }
91
103
  }
92
104
  }
93
105
 
94
106
  /**
95
- * A deterministic version of `JSON.stringify`
107
+ * A version of `JSON.stringify` with an alphabeticly ordered `keys`.
108
+ *
109
+ * The standard `JSON.stringify` rules determines by
110
+ * https://262.ecma-international.org/6.0/#sec-ordinary-object-internal-methods-and-internal-slots-ownpropertykeys
96
111
  *
97
112
  * @type {(value: Json) => string}
98
113
  */
99
- const stringify = value => seq.join('')(stringSequence(value))
114
+ const stringify = value => seq.join('')(serialize(value))
115
+
116
+ /** @type {(value: string) => Json} */
117
+ const parse = value => JSON.parse(value)
100
118
 
101
119
  module.exports = {
102
120
  /** @readonly */
103
121
  addProperty,
104
122
  /** @readonly */
105
123
  stringify,
124
+ /** @readonly */
125
+ serialize,
126
+ /** @readonly */
127
+ parse,
106
128
  }
package/map/index.js CHANGED
@@ -43,10 +43,11 @@ const keyCmp = a => ([b]) => cmp(a)(b)
43
43
  const create = root => ({
44
44
  get: name => option.map(([,value]) => value)(getVisitor(keyCmp(name))(root)),
45
45
  set: name => value => {
46
- const _0 = setVisitor(keyCmp(name))(() => [name, value])(root)
47
- if ('replace' in _0) { return create(_0.replace) }
48
- if ('overflow' in _0) { return create(_0.overflow) }
49
- throw ''
46
+ const result = setVisitor(keyCmp(name))(() => [name, value])(root)
47
+ switch (result[0]) {
48
+ case 'replace': case 'overflow': { return create(result[1]) }
49
+ default: { throw '' }
50
+ }
50
51
  },
51
52
  entries: values(root),
52
53
  root,
@@ -0,0 +1,14 @@
1
+ # Module Manager
2
+
3
+ ## Interface
4
+
5
+ ```js
6
+ /** @typedef {(packageName: string) => PackageMap|Package|undefined} PackageMap */
7
+
8
+ /**
9
+ * @typedef {readonly[
10
+ * PackageMap,
11
+ * (fileName: string) => string|undefined,
12
+ * ]} Package
13
+ */
14
+ ```
@@ -1,7 +1,7 @@
1
1
  const mm = require('..')
2
2
  const i = require('.')
3
3
 
4
- /** @type {{ [_ in string]: string}} */
4
+ /** @type {{ readonly [_ in string]: string}} */
5
5
  const files = {
6
6
  'index.js': './index.js',
7
7
  'a/index.js': './a/index.js',
@@ -31,7 +31,7 @@ if (cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('/') !== 'b/d') { thro
31
31
  const c = {
32
32
  dependencies: () => undefined,
33
33
  file: path => {
34
- /** @type {{ [_ in string]?: string}} */
34
+ /** @type {{ readonly [_ in string]?: string}} */
35
35
  const f = {
36
36
  'index.js': 'b/c ./index.js',
37
37
  'x/index.js': 'b/c ./x/index.js',
@@ -41,11 +41,11 @@ if (cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('/') !== 'b/d') { thro
41
41
  },
42
42
  id: ['c']
43
43
  }
44
- /** @type {{ [_ in string]: i.Package|i.Dependencies}} */
44
+ /** @type {{ readonly [_ in string]: i.Package|i.Dependencies}} */
45
45
  const packages = {
46
46
  a,
47
47
  b: s => {
48
- /** @type {{ [_ in string]: i.Package|i.Dependencies}} */
48
+ /** @type {{ readonly [_ in string]: i.Package|i.Dependencies}} */
49
49
  const p = { c }
50
50
  return p[s]
51
51
  }
@@ -54,7 +54,7 @@ if (cast(i.pathNorm('./a/../b/c/..//d/'.split('/'))).join('/') !== 'b/d') { thro
54
54
  const pack = {
55
55
  dependencies: s => packages[s],
56
56
  file: path => {
57
- /** @type {{ [_ in string]?: string}} */
57
+ /** @type {{ readonly [_ in string]?: string}} */
58
58
  const f = {
59
59
  'index.js': './index.js',
60
60
  'index/index.js': './index/index.js',
@@ -0,0 +1,17 @@
1
+ const array = require('../sequence/array')
2
+ const seq = require('../sequence')
3
+
4
+ /**
5
+ * @template T
6
+ * @typedef {{
7
+ * readonly [k in string]: T
8
+ * }} Object_
9
+ */
10
+
11
+ /** @type {<T>(object: Object_<T>) => seq.Sequence<readonly[string, T]>} */
12
+ const entries = object => array.sequence(Object.entries(object))
13
+
14
+ module.exports = {
15
+ /** @readonly */
16
+ entries,
17
+ }
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
- "name": "functionalscript",
3
- "version": "0.0.197",
4
- "description": "FunctionalScript is a functional subset of JavaScript",
5
- "main": "index.js",
6
- "scripts": {
7
- "tsc": "tsc",
8
- "test": "tsc && npm run test-only",
9
- "test-only": "node --trace-uncaught ./test"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "git+https://github.com/functionalscript/functionalscript.git"
14
- },
15
- "author": "Natfoam",
16
- "license": "Apache-2.0",
17
- "bugs": {
18
- "url": "https://github.com/functionalscript/functionalscript/issues"
19
- },
20
- "homepage": "https://github.com/functionalscript/functionalscript#readme",
21
- "devDependencies": {
22
- "@types/node": "^16.11.9",
23
- "typescript": "^4.5.2"
24
- }
2
+ "name": "functionalscript",
3
+ "version": "0.0.202",
4
+ "description": "FunctionalScript is a functional subset of JavaScript",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "tsc": "tsc",
8
+ "test": "tsc && npm run test-only",
9
+ "test-only": "node --trace-uncaught ./test"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/functionalscript/functionalscript.git"
14
+ },
15
+ "author": "Natfoam",
16
+ "license": "Apache-2.0",
17
+ "bugs": {
18
+ "url": "https://github.com/functionalscript/functionalscript/issues"
19
+ },
20
+ "homepage": "https://github.com/functionalscript/functionalscript#readme",
21
+ "devDependencies": {
22
+ "@types/node": "^16.11.9",
23
+ "typescript": "^4.5.2"
24
+ }
25
25
  }
@@ -107,6 +107,9 @@ const sequence = a => {
107
107
  return seq(0)
108
108
  }
109
109
 
110
+ /** @type {<T>(list: seq.Sequence<T>) => readonly T[]} */
111
+ const fromSequence = input => Array.from(seq.iterable(input))
112
+
110
113
  module.exports = {
111
114
  /** @readonly */
112
115
  at,
@@ -124,4 +127,6 @@ module.exports = {
124
127
  splitLast,
125
128
  /** @readonly */
126
129
  sequence,
130
+ /** @readonly */
131
+ fromSequence,
127
132
  }
package/sequence/index.js CHANGED
@@ -77,19 +77,23 @@ const first = input => {
77
77
  * @typedef {(list: Sequence<T>) => R} SequenceReduce
78
78
  */
79
79
 
80
- /** @type {<T>(...array: readonly T[]) => Sequence<T>} */
80
+ /**
81
+ * Note: the operation is not lazy. It traverse the given array and creates a linked list.
82
+ *
83
+ * @type {<T>(...array: readonly T[]) => Sequence<T>}
84
+ */
81
85
  const list = (...array) => {
82
86
  /** @typedef {typeof array extends readonly(infer T)[] ? T : never} T */
83
87
  let i = array.length
84
88
  /** @type {Sequence<T>} */
85
- let tail = empty
86
- while (true) {
87
- if (i === 0) { return tail }
89
+ let result = empty
90
+ while (i !== 0) {
88
91
  i = i - 1
89
92
  /** @type {FirstAndTail<T>} */
90
- const result = [array[i], tail]
91
- tail = () => result
93
+ const listResult = [array[i], result]
94
+ result = () => listResult
92
95
  }
96
+ return result
93
97
  }
94
98
 
95
99
  /** @type {<T>(...array: readonly Sequence<T>[]) => Sequence<T>} */
@@ -97,12 +101,12 @@ const concat = (...array) => {
97
101
  let i = array.length
98
102
  if (i == 0) { return empty }
99
103
  i = i - 1
100
- let tail = array[i]
101
- while (true) {
102
- if (i === 0) { return tail }
104
+ let result = array[i]
105
+ while (i !== 0) {
103
106
  i = i - 1
104
- tail = [array[i], tail]
107
+ result = [array[i], result]
105
108
  }
109
+ return result
106
110
  }
107
111
 
108
112
  /** @type {(_: number) => Sequence<number>} */
@@ -261,9 +265,6 @@ const zip = a => b => () => {
261
265
  return [[resultA[0], resultB[0]], zip(resultA[1])(resultB[1])]
262
266
  }
263
267
 
264
- /** @type {<T>(list: Sequence<T>) => readonly T[]} */
265
- const toArray = input => Array.from(iterable(input))
266
-
267
268
  module.exports = {
268
269
  /** @readonly */
269
270
  next,
@@ -280,8 +281,6 @@ module.exports = {
280
281
  /** @readonly */
281
282
  first,
282
283
  /** @readonly */
283
- toArray,
284
- /** @readonly */
285
284
  iterable,
286
285
  /** @readonly */
287
286
  asyncIterable,
package/sequence/test.js CHANGED
@@ -27,15 +27,18 @@ const print = input => {
27
27
  if (seq.some(x => x > 50)(big) !== true) { throw 'x' }
28
28
  if (seq.first(seq.drop(16)(big)) !== 42) { throw 'drop'}
29
29
  {
30
- const a = seq.toArray(seq.generate(1_000_000))
31
- let x = seq.concat(array.sequence(a), big)
30
+ const a = seq.map(seq.generate)(seq.generate(100_000))
31
+ const ar = array.fromSequence(a)
32
+ // This operation use a lot of stack because `...`
33
+ // puts array items on a stack.
34
+ // Use `array.sequence` instead
35
+ const x = seq.concat(...ar)
32
36
  const r = seq.next(x)
33
37
  // print(x)
34
38
  }
35
39
  {
36
- const a = seq.map(seq.generate)(seq.generate(100_000))
37
- const array = seq.toArray(a)
38
- const x = seq.concat(...array)
40
+ const a = array.fromSequence(seq.generate(1_000_000))
41
+ let x = seq.concat(array.sequence(a), big)
39
42
  const r = seq.next(x)
40
43
  // print(x)
41
44
  }
package/test.js CHANGED
@@ -59,3 +59,51 @@ const assert_if = c => { if (c) { throw 'assert_if' } }
59
59
  v.commit !== '4b14a7a2b11cf53f037931eb7bef240f96dcea64'),
60
60
  assert)
61
61
  }
62
+
63
+ {
64
+ const c = (()=>{})['constructor']
65
+ const f = c('return 5')
66
+ const result = f()
67
+ if (result !== 5) { throw 'function' }
68
+ }
69
+
70
+ {
71
+ /** @type {any} */
72
+ const o = {}
73
+ const c = o['constructor']
74
+ // console.log(c)
75
+ // console.log(c(()=>{}))
76
+ }
77
+
78
+ {
79
+ /** @type {any} */
80
+ const o = {
81
+ constructor: undefined
82
+ }
83
+ const c = o['constructor']
84
+ console.log(c)
85
+ }
86
+
87
+ {
88
+ /** @type {any} */
89
+ const b = '42'
90
+ const r = Number(b)
91
+ console.log(r)
92
+ }
93
+
94
+ {
95
+ /** @type {any} */
96
+ const o = {}
97
+ //const c = o['constructor']
98
+ //const c = o['__proto__']
99
+ //const c = o['__defineGetter__']
100
+ //const c = o['__defineSetter__']
101
+ //const c = o['__lookupGetter__']
102
+ //const c = o['__lookupSetter__']
103
+ //const c = o['hasOwnProperty']
104
+ //const c = o['isPrototypeOf']
105
+ //const c = o['propertyIsEnumerable']
106
+ //const c = o['toString']
107
+ const c = o['valueOf']
108
+ console.log(c)
109
+ }
package/version.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const cp = require('child_process')
2
2
  const fs = require('fs')
3
+ const json = require('./json')
3
4
 
4
5
  const b =cp.execSync('git log --oneline')
5
6
 
@@ -9,8 +10,8 @@ const v = `0.0.${r}`
9
10
 
10
11
  console.log(`version: ${v}`)
11
12
 
12
- const package_json = JSON.parse(fs.readFileSync('package.json').toString())
13
+ let package_json = json.parse(fs.readFileSync('package.json').toString())
13
14
 
14
- package_json.version = v
15
+ package_json = json.addProperty(v)(['version'])(package_json)
15
16
 
16
- fs.writeFileSync('package.json', JSON.stringify(package_json, null, 2))
17
+ fs.writeFileSync('package.json', JSON.stringify(package_json, null, 3))