@vbarbarosh/node-helpers 3.52.0 → 3.53.0

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "3.52.0",
5
+ "version": "3.53.0",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @link https://stackoverflow.com/a/72823174
3
+ * @link https://github.com/jshttp/content-disposition/tree/master
4
+ */
5
+ function escape_content_disposition(s)
6
+ {
7
+ const out = s.replaceAll('\\', '\\\\').replaceAll('"', '\\"');
8
+ if (out.match(/\s|;/)) {
9
+ return `"${out}"`;
10
+ }
11
+ return out;
12
+ }
13
+
14
+ module.exports = escape_content_disposition;
@@ -0,0 +1,19 @@
1
+ const assert = require('assert');
2
+ const escape_content_disposition = require('./escape_content_disposition');
3
+
4
+ const items = [
5
+ ['foo.bar', 'foo.bar'],
6
+ ['foo"bar', 'foo\\"bar'],
7
+ ['foo;bar', '"foo;bar"'],
8
+ ['foo\\bar', 'foo\\\\bar'],
9
+ ['foo bar', '"foo bar"'],
10
+ ['foo "bar".txt', '"foo \\"bar\\".txt"'],
11
+ ];
12
+
13
+ describe('escape_content_disposition', function () {
14
+ items.forEach(function ([input, expected]) {
15
+ it(`${input} → ${expected}`, function () {
16
+ assert.strictEqual(escape_content_disposition(input), expected);
17
+ });
18
+ });
19
+ });
package/src/fs_append.js CHANGED
@@ -1,5 +1,8 @@
1
1
  const fs = require('fs');
2
- const util = require('util');
3
2
 
4
- // https://nodejs.org/api/util.html#util_util_promisify_original
5
- module.exports = util.promisify(fs.appendFile);
3
+ function fs_append(file, data, options = {})
4
+ {
5
+ return fs.promises.appendFile(file, data, options);
6
+ }
7
+
8
+ module.exports = fs_append;
@@ -0,0 +1,8 @@
1
+ const fs = require('fs');
2
+
3
+ function fs_append_utf8(file, text, options = {})
4
+ {
5
+ return fs.promises.appendFile(file, text, options);
6
+ }
7
+
8
+ module.exports = fs_append_utf8;