@koine/node 2.0.0-beta.80 → 2.0.0-beta.83

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/fsWrite.cjs.js CHANGED
@@ -6,14 +6,39 @@ var promises = require('node:fs/promises');
6
6
  var node_os = require('node:os');
7
7
  var node_path = require('node:path');
8
8
 
9
- async function fsWrite(filepath, content, eol = true) {
10
- await promises.mkdir(node_path.dirname(filepath), { recursive: true });
11
- content = content.replace(/^\s*/m, "");
12
- await promises.writeFile(filepath, content);
13
- if (eol) {
14
- await promises.appendFile(filepath, node_os.EOL, "utf8");
15
- }
16
- }
9
+ // * Returns the index of the last element in the array where predicate is true, and -1
10
+ // * otherwise.
11
+ // *
12
+ // * @borrows [SO's answer by Nico Timmerman](https://stackoverflow.com/a/53187807/1938970)
13
+ // *
14
+ // * @param array The source array to search in
15
+ // * @param predicate find calls predicate once for each element of the array, in descending
16
+ // * order, until it finds one where predicate returns true. If such an element is found,
17
+ // * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
18
+ // */
19
+ // let findLastIndex = <T>(array: Array<T>, predicate: (value: T, index: number, obj: T[]) => boolean): number => {
20
+ // let l = array.length;
21
+ // while (l--) {
22
+ // if (predicate(array[l], l, array))
23
+ // return l;
24
+ // }
25
+ // return -1;
26
+ // }
27
+ /**
28
+ * Write file
29
+ *
30
+ * @param filepath The absolute file path
31
+ * @param content The file content string
32
+ * @param eol By default we apend a `node:os.EOL` end of line a the end of the file
33
+ */async function fsWrite(a,f,s=!0){await promises.mkdir(node_path.dirname(a),{recursive:!0}),// remove empty first line
34
+ f=f.replace(/^\s*/m,""),await promises.writeFile(a,f),s&&// multiline trim: removes empty lines at begininng and end of a multiline string
35
+ // const lines = content.split("\n");
36
+ // content = lines
37
+ // // .slice(lines.findIndex(Boolean), lines.findLastIndex(Boolean) - 1)
38
+ // .slice(lines.findIndex(Boolean), findLastIndex(lines, Boolean) - 1)
39
+ // .join("\n");
40
+ // @see https://stackoverflow.com/a/72653325/1938970
41
+ await promises.appendFile(a,node_os.EOL,"utf8");}// await appendFile(filepath, EOL, "utf8");
17
42
 
18
43
  exports["default"] = fsWrite;
19
44
  exports.fsWrite = fsWrite;
package/fsWrite.esm.js CHANGED
@@ -2,13 +2,38 @@ import { mkdir, writeFile, appendFile } from 'node:fs/promises';
2
2
  import { EOL } from 'node:os';
3
3
  import { dirname } from 'node:path';
4
4
 
5
- async function fsWrite(filepath, content, eol = true) {
6
- await mkdir(dirname(filepath), { recursive: true });
7
- content = content.replace(/^\s*/m, "");
8
- await writeFile(filepath, content);
9
- if (eol) {
10
- await appendFile(filepath, EOL, "utf8");
11
- }
12
- }
5
+ // * Returns the index of the last element in the array where predicate is true, and -1
6
+ // * otherwise.
7
+ // *
8
+ // * @borrows [SO's answer by Nico Timmerman](https://stackoverflow.com/a/53187807/1938970)
9
+ // *
10
+ // * @param array The source array to search in
11
+ // * @param predicate find calls predicate once for each element of the array, in descending
12
+ // * order, until it finds one where predicate returns true. If such an element is found,
13
+ // * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
14
+ // */
15
+ // let findLastIndex = <T>(array: Array<T>, predicate: (value: T, index: number, obj: T[]) => boolean): number => {
16
+ // let l = array.length;
17
+ // while (l--) {
18
+ // if (predicate(array[l], l, array))
19
+ // return l;
20
+ // }
21
+ // return -1;
22
+ // }
23
+ /**
24
+ * Write file
25
+ *
26
+ * @param filepath The absolute file path
27
+ * @param content The file content string
28
+ * @param eol By default we apend a `node:os.EOL` end of line a the end of the file
29
+ */async function fsWrite(a,f,s=!0){await mkdir(dirname(a),{recursive:!0}),// remove empty first line
30
+ f=f.replace(/^\s*/m,""),await writeFile(a,f),s&&// multiline trim: removes empty lines at begininng and end of a multiline string
31
+ // const lines = content.split("\n");
32
+ // content = lines
33
+ // // .slice(lines.findIndex(Boolean), lines.findLastIndex(Boolean) - 1)
34
+ // .slice(lines.findIndex(Boolean), findLastIndex(lines, Boolean) - 1)
35
+ // .join("\n");
36
+ // @see https://stackoverflow.com/a/72653325/1938970
37
+ await appendFile(a,EOL,"utf8");}// await appendFile(filepath, EOL, "utf8");
13
38
 
14
39
  export { fsWrite as default, fsWrite };
@@ -6,14 +6,21 @@ var node_fs = require('node:fs');
6
6
  var node_os = require('node:os');
7
7
  var node_path = require('node:path');
8
8
 
9
- function fsWriteSync(filepath, content, eol = true) {
10
- node_fs.mkdirSync(node_path.dirname(filepath), { recursive: true });
11
- content = content.replace(/^\s*/m, "");
12
- node_fs.writeFileSync(filepath, content);
13
- if (eol) {
14
- node_fs.appendFileSync(filepath, node_os.EOL, "utf8");
15
- }
16
- }
9
+ /**
10
+ * Write file
11
+ *
12
+ * @param filepath The absolute file path
13
+ * @param content The file content string
14
+ * @param eol By default we apend a `node:os.EOL` end of line a the end of the file
15
+ */function fsWriteSync(i,m,n=!0){node_fs.mkdirSync(node_path.dirname(i),{recursive:!0}),node_fs.writeFileSync(i,// remove empty first line
16
+ m=m.replace(/^\s*/m,"")),n&&// multiline trim: removes empty lines at begininng and end of a multiline string
17
+ // const lines = content.split("\n");
18
+ // content = lines
19
+ // // .slice(lines.findIndex(Boolean), lines.findLastIndex(Boolean) - 1)
20
+ // .slice(lines.findIndex(Boolean), findLastIndex(lines, Boolean) - 1)
21
+ // .join("\n");
22
+ // @see https://stackoverflow.com/a/72653325/1938970
23
+ node_fs.appendFileSync(i,node_os.EOL,"utf8");}// appendFileSync(filepath, EOL, "utf8");
17
24
 
18
25
  exports["default"] = fsWriteSync;
19
26
  exports.fsWriteSync = fsWriteSync;
@@ -2,13 +2,20 @@ import { mkdirSync, writeFileSync, appendFileSync } from 'node:fs';
2
2
  import { EOL } from 'node:os';
3
3
  import { dirname } from 'node:path';
4
4
 
5
- function fsWriteSync(filepath, content, eol = true) {
6
- mkdirSync(dirname(filepath), { recursive: true });
7
- content = content.replace(/^\s*/m, "");
8
- writeFileSync(filepath, content);
9
- if (eol) {
10
- appendFileSync(filepath, EOL, "utf8");
11
- }
12
- }
5
+ /**
6
+ * Write file
7
+ *
8
+ * @param filepath The absolute file path
9
+ * @param content The file content string
10
+ * @param eol By default we apend a `node:os.EOL` end of line a the end of the file
11
+ */function fsWriteSync(i,m,n=!0){mkdirSync(dirname(i),{recursive:!0}),writeFileSync(i,// remove empty first line
12
+ m=m.replace(/^\s*/m,"")),n&&// multiline trim: removes empty lines at begininng and end of a multiline string
13
+ // const lines = content.split("\n");
14
+ // content = lines
15
+ // // .slice(lines.findIndex(Boolean), lines.findLastIndex(Boolean) - 1)
16
+ // .slice(lines.findIndex(Boolean), findLastIndex(lines, Boolean) - 1)
17
+ // .join("\n");
18
+ // @see https://stackoverflow.com/a/72653325/1938970
19
+ appendFileSync(i,EOL,"utf8");}// appendFileSync(filepath, EOL, "utf8");
13
20
 
14
21
  export { fsWriteSync as default, fsWriteSync };
package/jest.cjs.js CHANGED
@@ -4,13 +4,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var console = require('console');
6
6
 
7
- const jestCreateExpectedThrownError = (pkgName, fnName) => (expectFn) => {
8
- try {
9
- expectFn().toThrow(new RegExp(`\\[${pkgName}\\]::${fnName}, .*`, "g"));
10
- }
11
- catch (e) {
12
- console.log("\x1b[32m", " ✓", "\x1b[0m", "throw", "\x1b[2m", e.message.replace(`[${pkgName}]::${fnName}, `, ""));
13
- }
14
- };
7
+ /**
8
+ *
9
+ * @see https://stackoverflow.com/a/41407246/1938970
10
+ *
11
+ * @usage
12
+ * ```ts
13
+ * const err = jestCreateExpectedThrownError("@org/pkg", "fnName");
14
+ *
15
+ * // @ts-expect-error test wrong implementation
16
+ * err(() => fnName("wrong arguments implementation"));
17
+ * ```
18
+ */const jestCreateExpectedThrownError=(r,t)=>o=>{try{o().toThrow(RegExp(`\\[${r}\\]::${t}, .*`,"g"));}catch(o){console.log("\x1b[32m"," ✓","\x1b[0m","throw","\x1b[2m",o.message.replace(`[${r}]::${t}, `,""));}};
15
19
 
16
20
  exports.jestCreateExpectedThrownError = jestCreateExpectedThrownError;
package/jest.esm.js CHANGED
@@ -1,12 +1,16 @@
1
1
  import { log } from 'console';
2
2
 
3
- const jestCreateExpectedThrownError = (pkgName, fnName) => (expectFn) => {
4
- try {
5
- expectFn().toThrow(new RegExp(`\\[${pkgName}\\]::${fnName}, .*`, "g"));
6
- }
7
- catch (e) {
8
- log("\x1b[32m", " ✓", "\x1b[0m", "throw", "\x1b[2m", e.message.replace(`[${pkgName}]::${fnName}, `, ""));
9
- }
10
- };
3
+ /**
4
+ *
5
+ * @see https://stackoverflow.com/a/41407246/1938970
6
+ *
7
+ * @usage
8
+ * ```ts
9
+ * const err = jestCreateExpectedThrownError("@org/pkg", "fnName");
10
+ *
11
+ * // @ts-expect-error test wrong implementation
12
+ * err(() => fnName("wrong arguments implementation"));
13
+ * ```
14
+ */const jestCreateExpectedThrownError=(r,t)=>o=>{try{o().toThrow(RegExp(`\\[${r}\\]::${t}, .*`,"g"));}catch(o){log("\x1b[32m"," ✓","\x1b[0m","throw","\x1b[2m",o.message.replace(`[${r}]::${t}, `,""));}};
11
15
 
12
16
  export { jestCreateExpectedThrownError };
package/package.json CHANGED
@@ -26,6 +26,6 @@
26
26
  },
27
27
  "module": "./index.esm.js",
28
28
  "main": "./index.cjs.js",
29
- "version": "2.0.0-beta.80",
29
+ "version": "2.0.0-beta.83",
30
30
  "dependencies": {}
31
31
  }