keep-a-changelog 0.10.3 → 2.0.1
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/CHANGELOG.md +13 -185
- package/LICENSE +1 -1
- package/README.md +93 -63
- package/esm/_dnt.shims.js +62 -0
- package/esm/bin.js +114 -0
- package/esm/deps/deno_land/std_0.120.0/_util/assert.js +13 -0
- package/esm/deps/deno_land/std_0.120.0/_util/os.js +15 -0
- package/esm/deps/deno_land/std_0.120.0/flags/mod.js +255 -0
- package/esm/deps/deno_land/std_0.120.0/path/_constants.js +45 -0
- package/esm/deps/deno_land/std_0.120.0/path/_interface.js +3 -0
- package/esm/deps/deno_land/std_0.120.0/path/_util.js +114 -0
- package/esm/deps/deno_land/std_0.120.0/path/common.js +36 -0
- package/esm/deps/deno_land/std_0.120.0/path/glob.js +361 -0
- package/esm/deps/deno_land/std_0.120.0/path/mod.js +14 -0
- package/esm/deps/deno_land/std_0.120.0/path/posix.js +493 -0
- package/esm/deps/deno_land/std_0.120.0/path/separator.js +5 -0
- package/esm/deps/deno_land/std_0.120.0/path/win32.js +963 -0
- package/esm/deps/deno_land/std_0.51.0/fs/eol.js +29 -0
- package/esm/deps/deno_land/x/ini_v2.1.0/ini.js +226 -0
- package/esm/deps/deno_land/x/ini_v2.1.0/mod.js +1 -0
- package/esm/deps/deno_land/x/semver_v1.4.0/mod.js +1527 -0
- package/esm/mod.js +5 -0
- package/esm/package.json +3 -0
- package/esm/src/Change.js +48 -0
- package/esm/src/Changelog.js +137 -0
- package/esm/src/Release.js +204 -0
- package/esm/src/deps.js +1 -0
- package/esm/src/parser.js +159 -0
- package/esm/test/changelog.custom.type.md +24 -0
- package/esm/test/changelog.expected.md +169 -0
- package/esm/test/changelog.md +200 -0
- package/esm/test/empty.expected.md +6 -0
- package/package.json +26 -24
- package/types/_dnt.shims.d.ts +9 -0
- package/types/bin.d.ts +2 -0
- package/types/deps/deno_land/std_0.120.0/_util/assert.d.ts +5 -0
- package/types/deps/deno_land/std_0.120.0/_util/os.d.ts +3 -0
- package/types/deps/deno_land/std_0.120.0/flags/mod.d.ts +50 -0
- package/types/deps/deno_land/std_0.120.0/path/_constants.d.ts +39 -0
- package/types/deps/deno_land/std_0.120.0/path/_interface.d.ts +26 -0
- package/types/deps/deno_land/std_0.120.0/path/_util.d.ts +8 -0
- package/types/deps/deno_land/std_0.120.0/path/common.d.ts +13 -0
- package/types/deps/deno_land/std_0.120.0/path/glob.d.ts +78 -0
- package/types/deps/deno_land/std_0.120.0/path/mod.d.ts +9 -0
- package/types/deps/deno_land/std_0.120.0/path/posix.d.ts +80 -0
- package/types/deps/deno_land/std_0.120.0/path/separator.d.ts +2 -0
- package/types/deps/deno_land/std_0.120.0/path/win32.d.ts +87 -0
- package/types/deps/deno_land/std_0.51.0/fs/eol.d.ts +12 -0
- package/types/deps/deno_land/x/ini_v2.1.0/ini.d.ts +53 -0
- package/types/deps/deno_land/x/ini_v2.1.0/mod.d.ts +1 -0
- package/types/deps/deno_land/x/semver_v1.4.0/mod.d.ts +116 -0
- package/types/mod.d.ts +5 -0
- package/types/src/Change.d.ts +8 -0
- package/types/src/Changelog.d.ts +18 -0
- package/types/src/Release.d.ts +25 -0
- package/types/src/deps.d.ts +1 -0
- package/types/src/parser.d.ts +11 -0
- package/umd/_dnt.shims.js +76 -0
- package/umd/bin.js +145 -0
- package/umd/deps/deno_land/std_0.120.0/_util/assert.js +28 -0
- package/umd/deps/deno_land/std_0.120.0/_util/os.js +47 -0
- package/umd/deps/deno_land/std_0.120.0/flags/mod.js +269 -0
- package/umd/deps/deno_land/std_0.120.0/path/_constants.js +58 -0
- package/umd/deps/deno_land/std_0.120.0/path/_interface.js +14 -0
- package/umd/deps/deno_land/std_0.120.0/path/_util.js +134 -0
- package/umd/deps/deno_land/std_0.120.0/path/common.js +50 -0
- package/umd/deps/deno_land/std_0.120.0/path/glob.js +397 -0
- package/umd/deps/deno_land/std_0.120.0/path/mod.js +51 -0
- package/umd/deps/deno_land/std_0.120.0/path/posix.js +538 -0
- package/umd/deps/deno_land/std_0.120.0/path/separator.js +18 -0
- package/umd/deps/deno_land/std_0.120.0/path/win32.js +1008 -0
- package/umd/deps/deno_land/std_0.51.0/fs/eol.js +44 -0
- package/umd/deps/deno_land/x/ini_v2.1.0/ini.js +262 -0
- package/umd/deps/deno_land/x/ini_v2.1.0/mod.js +23 -0
- package/umd/deps/deno_land/x/semver_v1.4.0/mod.js +1578 -0
- package/umd/mod.js +24 -0
- package/umd/package.json +3 -0
- package/umd/src/Change.js +61 -0
- package/umd/src/Changelog.js +150 -0
- package/umd/src/Release.js +220 -0
- package/umd/src/deps.js +19 -0
- package/umd/src/parser.js +175 -0
- package/umd/test/changelog.custom.type.md +24 -0
- package/umd/test/changelog.expected.md +169 -0
- package/umd/test/changelog.md +200 -0
- package/umd/test/empty.expected.md +6 -0
- package/bin.js +0 -114
- package/src/Change.js +0 -40
- package/src/Changelog.js +0 -121
- package/src/Release.js +0 -220
- package/src/index.js +0 -6
- package/src/parser.js +0 -182
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
/** EndOfLine character enum */
|
|
3
|
+
export var EOL;
|
|
4
|
+
(function (EOL) {
|
|
5
|
+
EOL["LF"] = "\n";
|
|
6
|
+
EOL["CRLF"] = "\r\n";
|
|
7
|
+
})(EOL || (EOL = {}));
|
|
8
|
+
const regDetect = /(?:\r?\n)/g;
|
|
9
|
+
/**
|
|
10
|
+
* Detect the EOL character for string input.
|
|
11
|
+
* returns null if no newline
|
|
12
|
+
*/
|
|
13
|
+
export function detect(content) {
|
|
14
|
+
const d = content.match(regDetect);
|
|
15
|
+
if (!d || d.length === 0) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const crlf = d.filter((x) => x === EOL.CRLF);
|
|
19
|
+
if (crlf.length > 0) {
|
|
20
|
+
return EOL.CRLF;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return EOL.LF;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Format the file to the targeted EOL */
|
|
27
|
+
export function format(content, eol) {
|
|
28
|
+
return content.replace(regDetect, eol);
|
|
29
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
|
+
import * as eol from '../../std_0.51.0/fs/eol.js';
|
|
3
|
+
const isWindows = dntShim.Deno.build.os == "windows";
|
|
4
|
+
const EOL = isWindows ? eol.EOL.CRLF : eol.EOL.LF;
|
|
5
|
+
export const parse = decode;
|
|
6
|
+
export const stringify = encode;
|
|
7
|
+
/**
|
|
8
|
+
* Encode the object `object` into an ini-style formatted string. If the
|
|
9
|
+
* optional parameter `section` is given, then all top-level properties
|
|
10
|
+
* of the object are put into this section and the `section`-string is
|
|
11
|
+
* prepended to all sub-sections, see the usage example above.
|
|
12
|
+
*
|
|
13
|
+
* The `options` object may contain the following:
|
|
14
|
+
* - `section` A string which will be the first `section` in the encoded
|
|
15
|
+
* ini data. Defaults to none.
|
|
16
|
+
* - `whitespace` Boolean to specify whether to put whitespace around the
|
|
17
|
+
* `=` character. By default, whitespace is omitted, to be friendly to
|
|
18
|
+
* some persnickety old parsers that don't tolerate it well. But some
|
|
19
|
+
* find that it's more human-readable and pretty with the whitespace.
|
|
20
|
+
*
|
|
21
|
+
* For backwards compatibility reasons, if a `string` options is passed,
|
|
22
|
+
* then it is assumed to be the `section` value.
|
|
23
|
+
*
|
|
24
|
+
* @param obj Object to encode
|
|
25
|
+
* @param opt Encoding options
|
|
26
|
+
*/
|
|
27
|
+
export function encode(obj, opt = { whitespace: false }) {
|
|
28
|
+
const children = [];
|
|
29
|
+
let out = '';
|
|
30
|
+
let options = typeof opt === 'string' ? { section: opt, whitespace: false } : opt;
|
|
31
|
+
const separator = options.whitespace ? ' = ' : '=';
|
|
32
|
+
Object.keys(obj).forEach(function (k, _, __) {
|
|
33
|
+
const val = obj[k];
|
|
34
|
+
if (val && Array.isArray(val)) {
|
|
35
|
+
val.forEach(function (item) {
|
|
36
|
+
out += safe(k + '[]') + separator + safe(item) + EOL;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else if (val && typeof val === 'object') {
|
|
40
|
+
children.push(k);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
out += safe(k) + separator + safe(val) + EOL;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
if (options.section && out.length) {
|
|
47
|
+
out = '[' + safe(options.section) + ']' + EOL + out;
|
|
48
|
+
}
|
|
49
|
+
children.forEach(function (k, _, __) {
|
|
50
|
+
const nk = dotSplit(k).join('\\.');
|
|
51
|
+
const section = (options.section ? options.section + '.' : '') + nk;
|
|
52
|
+
const child = encode(obj[k], {
|
|
53
|
+
section: section,
|
|
54
|
+
whitespace: options.whitespace
|
|
55
|
+
});
|
|
56
|
+
if (out.length && child.length) {
|
|
57
|
+
out += EOL;
|
|
58
|
+
}
|
|
59
|
+
out += child;
|
|
60
|
+
});
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
function dotSplit(str) {
|
|
64
|
+
return str.replace(/\1/g, '\u0002LITERAL\\1LITERAL\u0002')
|
|
65
|
+
.replace(/\\\./g, '\u0001')
|
|
66
|
+
.split(/\./).map(function (part) {
|
|
67
|
+
return part.replace(/\1/g, '\\.')
|
|
68
|
+
.replace(/\2LITERAL\\1LITERAL\2/g, '\u0001');
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Decode the given ini-style formatted document into a nested object.
|
|
73
|
+
* @param str ini-style document
|
|
74
|
+
*/
|
|
75
|
+
export function decode(str) {
|
|
76
|
+
const out = {};
|
|
77
|
+
let p = out;
|
|
78
|
+
// section |key = value
|
|
79
|
+
const re = /^\[([^\]]*)\]$|^([^=]+)(=(.*))?$/i;
|
|
80
|
+
const lines = str.split(/[\r\n]+/g);
|
|
81
|
+
lines.forEach(function (line, _, __) {
|
|
82
|
+
if (!line || line.match(/^\s*[;#]/))
|
|
83
|
+
return;
|
|
84
|
+
const match = line.match(re);
|
|
85
|
+
if (!match)
|
|
86
|
+
return;
|
|
87
|
+
if (match[1] !== undefined) {
|
|
88
|
+
let section = unsafe(match[1]);
|
|
89
|
+
p = out[section] = out[section] || {};
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
let key = unsafe(match[2]);
|
|
93
|
+
let value = match[3] ? unsafe(match[4]) : true;
|
|
94
|
+
switch (value) {
|
|
95
|
+
case 'true':
|
|
96
|
+
case 'false':
|
|
97
|
+
case 'null': value = JSON.parse(value);
|
|
98
|
+
}
|
|
99
|
+
const valueAsFloat = parseFloat(`${value}`);
|
|
100
|
+
if (!Number.isNaN(valueAsFloat)) {
|
|
101
|
+
value = valueAsFloat;
|
|
102
|
+
}
|
|
103
|
+
// Convert keys with '[]' suffix to an array
|
|
104
|
+
if (key.length > 2 && key.slice(-2) === '[]') {
|
|
105
|
+
key = key.substring(0, key.length - 2);
|
|
106
|
+
if (!p[key]) {
|
|
107
|
+
p[key] = [];
|
|
108
|
+
}
|
|
109
|
+
else if (!Array.isArray(p[key])) {
|
|
110
|
+
p[key] = [p[key]];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// safeguard against resetting a previously defined
|
|
114
|
+
// array by accidentally forgetting the brackets
|
|
115
|
+
if (Array.isArray(p[key])) {
|
|
116
|
+
p[key].push(value);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
p[key] = value;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
// {a:{y:1},"a.b":{x:2}} --> {a:{y:1,b:{x:2}}}
|
|
123
|
+
// use a filter to return the keys that have to be deleted.
|
|
124
|
+
Object.keys(out).filter(function (k, _, __) {
|
|
125
|
+
if (!out[k] ||
|
|
126
|
+
typeof out[k] !== 'object' ||
|
|
127
|
+
Array.isArray(out[k])) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
// see if the parent section is also an object.
|
|
131
|
+
// if so, add it to that, and mark this one for deletion
|
|
132
|
+
const parts = dotSplit(k);
|
|
133
|
+
let parentSection = out;
|
|
134
|
+
const lastPart = parts.pop() ?? '';
|
|
135
|
+
const nl = lastPart.replace(/\\\./g, '.');
|
|
136
|
+
parts.forEach(function (part, _, __) {
|
|
137
|
+
if (!parentSection[part] || typeof parentSection[part] !== 'object')
|
|
138
|
+
parentSection[part] = {};
|
|
139
|
+
parentSection = parentSection[part];
|
|
140
|
+
});
|
|
141
|
+
if (parentSection === out && nl === lastPart) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
parentSection[nl] = out[k];
|
|
145
|
+
return true;
|
|
146
|
+
}).forEach(function (del, _, __) {
|
|
147
|
+
delete out[del];
|
|
148
|
+
});
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
function isQuoted(val) {
|
|
152
|
+
return (val.charAt(0) === '"' && val.slice(-1) === '"') ||
|
|
153
|
+
(val.charAt(0) === "'" && val.slice(-1) === "'");
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Escapes the string `val` such that it is safe to be used as a key or
|
|
157
|
+
* value in an ini-file. Basically escapes quotes. For example:
|
|
158
|
+
*
|
|
159
|
+
* ```javascript
|
|
160
|
+
* ini.safe('"unsafe string"')
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* would result in
|
|
164
|
+
*
|
|
165
|
+
* ```javascript
|
|
166
|
+
* "\"unsafe string\""
|
|
167
|
+
* ```
|
|
168
|
+
* @param val String to escape
|
|
169
|
+
*/
|
|
170
|
+
export function safe(val) {
|
|
171
|
+
return (typeof val !== 'string' ||
|
|
172
|
+
val.match(/[=\r\n]/) ||
|
|
173
|
+
val.match(/^\[/) ||
|
|
174
|
+
(val.length > 1 && isQuoted(val)) ||
|
|
175
|
+
val !== val.trim())
|
|
176
|
+
? JSON.stringify(val)
|
|
177
|
+
: val.replace(/;/g, '\\;').replace(/#/g, '\\#');
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Unescapes the given string value.
|
|
181
|
+
* @param val String to unescape
|
|
182
|
+
*/
|
|
183
|
+
export function unsafe(val = '') {
|
|
184
|
+
val = val.trim();
|
|
185
|
+
if (isQuoted(val)) {
|
|
186
|
+
// remove the single quotes before calling JSON.parse
|
|
187
|
+
if (val.charAt(0) === "'") {
|
|
188
|
+
val = val.substr(1, val.length - 2);
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
val = JSON.parse(val);
|
|
192
|
+
}
|
|
193
|
+
catch (_) { }
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
// walk the val to find the first unescaped ; character
|
|
197
|
+
let esc = false;
|
|
198
|
+
let unesc = '';
|
|
199
|
+
for (let i = 0, l = val.length; i < l; i++) {
|
|
200
|
+
const c = val.charAt(i);
|
|
201
|
+
if (esc) {
|
|
202
|
+
if ('\\;#'.indexOf(c) !== -1) {
|
|
203
|
+
unesc += c;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
unesc += '\\' + c;
|
|
207
|
+
}
|
|
208
|
+
esc = false;
|
|
209
|
+
}
|
|
210
|
+
else if (';#'.indexOf(c) !== -1) {
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
else if (c === '\\') {
|
|
214
|
+
esc = true;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
unesc += c;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (esc) {
|
|
221
|
+
unesc += '\\';
|
|
222
|
+
}
|
|
223
|
+
return unesc.trim();
|
|
224
|
+
}
|
|
225
|
+
return val;
|
|
226
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ini.js';
|