Browse Source

refactor: removes type definitions

e22m4u 4 days ago
parent
commit
56ef8d0752

+ 7 - 7
dist/cjs/index.cjs

@@ -71,17 +71,17 @@ function arrayToString(input) {
 __name(arrayToString, "arrayToString");
 __name(arrayToString, "arrayToString");
 
 
 // src/format.js
 // src/format.js
-function format(pattern) {
+function format(pattern, ...args) {
   if (pattern instanceof Date) {
   if (pattern instanceof Date) {
     pattern = pattern.toISOString();
     pattern = pattern.toISOString();
   } else if (typeof pattern !== "string") {
   } else if (typeof pattern !== "string") {
     pattern = String(pattern);
     pattern = String(pattern);
   }
   }
   const re = /(%?)(%([sdjvl]))/g;
   const re = /(%?)(%([sdjvl]))/g;
-  const args = Array.prototype.slice.call(arguments, 1);
-  if (args.length) {
+  const argsQueue = [...args];
+  if (argsQueue.length) {
     pattern = pattern.replace(re, function(match, escaped, ptn, flag) {
     pattern = pattern.replace(re, function(match, escaped, ptn, flag) {
-      let arg = args.shift();
+      let arg = argsQueue.shift();
       switch (flag) {
       switch (flag) {
         case "s":
         case "s":
           arg = String(arg);
           arg = String(arg);
@@ -100,11 +100,11 @@ function format(pattern) {
           break;
           break;
       }
       }
       if (!escaped) return arg;
       if (!escaped) return arg;
-      args.unshift(arg);
+      argsQueue.unshift(arg);
       return match;
       return match;
     });
     });
   }
   }
-  if (args.length) pattern += " " + args.join(" ");
+  if (argsQueue.length) pattern += " " + argsQueue.join(" ");
   pattern = pattern.replace(/%{2}/g, "%");
   pattern = pattern.replace(/%{2}/g, "%");
   return "" + pattern;
   return "" + pattern;
 }
 }
@@ -116,7 +116,7 @@ var _Errorf = class _Errorf extends Error {
    * Constructor.
    * Constructor.
    *
    *
    * @param {string|undefined} pattern
    * @param {string|undefined} pattern
-   * @param {any} args
+   * @param {*} args
    */
    */
   constructor(pattern = void 0, ...args) {
   constructor(pattern = void 0, ...args) {
     const message = pattern != null ? format(pattern, ...args) : void 0;
     const message = pattern != null ? format(pattern, ...args) : void 0;

+ 13 - 0
eslint.config.js

@@ -1,6 +1,8 @@
 import globals from 'globals';
 import globals from 'globals';
 import eslintJs from '@eslint/js';
 import eslintJs from '@eslint/js';
+import eslintJsdocPlugin from 'eslint-plugin-jsdoc';
 import eslintMochaPlugin from 'eslint-plugin-mocha';
 import eslintMochaPlugin from 'eslint-plugin-mocha';
+import eslintImportPlugin from 'eslint-plugin-import';
 import eslintPrettierConfig from 'eslint-config-prettier';
 import eslintPrettierConfig from 'eslint-config-prettier';
 import eslintChaiExpectPlugin from 'eslint-plugin-chai-expect';
 import eslintChaiExpectPlugin from 'eslint-plugin-chai-expect';
 
 
@@ -13,14 +15,25 @@ export default [{
     },
     },
   },
   },
   plugins: {
   plugins: {
+    'jsdoc': eslintJsdocPlugin,
     'mocha': eslintMochaPlugin,
     'mocha': eslintMochaPlugin,
+    'import': eslintImportPlugin,
     'chai-expect': eslintChaiExpectPlugin,
     'chai-expect': eslintChaiExpectPlugin,
   },
   },
   rules: {
   rules: {
     ...eslintJs.configs.recommended.rules,
     ...eslintJs.configs.recommended.rules,
     ...eslintPrettierConfig.rules,
     ...eslintPrettierConfig.rules,
+    ...eslintImportPlugin.flatConfigs.recommended.rules,
     ...eslintMochaPlugin.configs.recommended.rules,
     ...eslintMochaPlugin.configs.recommended.rules,
     ...eslintChaiExpectPlugin.configs['recommended-flat'].rules,
     ...eslintChaiExpectPlugin.configs['recommended-flat'].rules,
+    ...eslintJsdocPlugin.configs['flat/recommended-error'].rules,
+    'no-duplicate-imports': 'error',
+    'jsdoc/reject-any-type': 0,
+    'jsdoc/reject-function-type': 0,
+    'jsdoc/require-param-description': 0,
+    'jsdoc/require-returns-description': 0,
+    'jsdoc/require-property-description': 0,
+    'jsdoc/tag-lines': ['error', 'any', {startLines: 1}],
   },
   },
   files: ['src/**/*.js'],
   files: ['src/**/*.js'],
 }];
 }];

+ 0 - 2
tsconfig.json → jsconfig.json

@@ -1,7 +1,5 @@
 {
 {
   "compilerOptions": {
   "compilerOptions": {
-    "rootDir": "src",
-    "noEmit": true,
     "target": "es2022",
     "target": "es2022",
     "module": "NodeNext",
     "module": "NodeNext",
     "moduleResolution": "NodeNext"
     "moduleResolution": "NodeNext"

+ 8 - 9
package.json

@@ -9,17 +9,15 @@
     "format",
     "format",
     "error"
     "error"
   ],
   ],
-  "homepage": "https://github.com/e22m4u/js-format",
+  "homepage": "https://gitrepos.ru/e22m4u/js-format",
   "repository": {
   "repository": {
     "type": "git",
     "type": "git",
-    "url": "git+https://github.com/e22m4u/js-format.git"
+    "url": "git+https://gitrepos.ru/e22m4u/js-format.git"
   },
   },
   "type": "module",
   "type": "module",
-  "types": "./src/index.d.ts",
   "module": "./src/index.js",
   "module": "./src/index.js",
   "main": "./dist/cjs/index.cjs",
   "main": "./dist/cjs/index.cjs",
   "exports": {
   "exports": {
-    "types": "./src/index.d.ts",
     "import": "./src/index.js",
     "import": "./src/index.js",
     "require": "./dist/cjs/index.cjs"
     "require": "./dist/cjs/index.cjs"
   },
   },
@@ -27,8 +25,8 @@
     "node": ">=12"
     "node": ">=12"
   },
   },
   "scripts": {
   "scripts": {
-    "lint": "tsc && eslint ./src",
-    "lint:fix": "tsc && eslint ./src --fix",
+    "lint": "eslint ./src",
+    "lint:fix": "eslint ./src --fix",
     "format": "prettier --write \"./src/**/*.js\"",
     "format": "prettier --write \"./src/**/*.js\"",
     "test": "npm run lint && c8 --reporter=text-summary mocha",
     "test": "npm run lint && c8 --reporter=text-summary mocha",
     "test:coverage": "npm run lint && c8 --reporter=text mocha",
     "test:coverage": "npm run lint && c8 --reporter=text mocha",
@@ -45,12 +43,13 @@
     "eslint": "~9.39.1",
     "eslint": "~9.39.1",
     "eslint-config-prettier": "~10.1.8",
     "eslint-config-prettier": "~10.1.8",
     "eslint-plugin-chai-expect": "~3.1.0",
     "eslint-plugin-chai-expect": "~3.1.0",
+    "eslint-plugin-import": "^2.32.0",
+    "eslint-plugin-jsdoc": "^61.4.1",
     "eslint-plugin-mocha": "~11.2.0",
     "eslint-plugin-mocha": "~11.2.0",
     "globals": "~16.5.0",
     "globals": "~16.5.0",
     "husky": "~9.1.7",
     "husky": "~9.1.7",
     "mocha": "~11.7.5",
     "mocha": "~11.7.5",
-    "prettier": "~3.7.2",
-    "rimraf": "~6.1.2",
-    "typescript": "~5.9.3"
+    "prettier": "~3.7.3",
+    "rimraf": "~6.1.2"
   }
   }
 }
 }

+ 0 - 6
src/array-to-string.d.ts

@@ -1,6 +0,0 @@
-/**
- * Array to string.
- *
- * @param input
- */
-export declare function arrayToString(input: any): string;

+ 2 - 2
src/array-to-string.js

@@ -10,8 +10,8 @@ const SEPARATOR = ', ';
 /**
 /**
  * Array to string.
  * Array to string.
  *
  *
- * @param {any} input
- * @return {string}
+ * @param {*} input
+ * @returns {string}
  */
  */
 export function arrayToString(input) {
 export function arrayToString(input) {
   if (Array.isArray(input) && input.length)
   if (Array.isArray(input) && input.length)

+ 2 - 0
src/array-to-string.spec.js

@@ -85,6 +85,7 @@ describe('arrayToString', function () {
     });
     });
 
 
     it('returns a string representation of the given named function', function () {
     it('returns a string representation of the given named function', function () {
+      // eslint-disable-next-line jsdoc/require-jsdoc
       function foo() {}
       function foo() {}
       const res = arrayToString(foo);
       const res = arrayToString(foo);
       expect(res).to.be.eq('Function');
       expect(res).to.be.eq('Function');
@@ -221,6 +222,7 @@ describe('arrayToString', function () {
     });
     });
 
 
     it('returns an element representation of the given named function', function () {
     it('returns an element representation of the given named function', function () {
+      // eslint-disable-next-line jsdoc/require-jsdoc
       function foo() {}
       function foo() {}
       const res = arrayToString([foo]);
       const res = arrayToString([foo]);
       expect(res).to.be.eq('Function');
       expect(res).to.be.eq('Function');

+ 0 - 12
src/errorf.d.ts

@@ -1,12 +0,0 @@
-/**
- * Errorf.
- */
-export declare class Errorf extends Error {
-  /**
-   * Constructor.
-   *
-   * @param pattern
-   * @param args
-   */
-  constructor(pattern: string, ...args: any[]);
-}

+ 1 - 1
src/errorf.js

@@ -8,7 +8,7 @@ export class Errorf extends Error {
    * Constructor.
    * Constructor.
    *
    *
    * @param {string|undefined} pattern
    * @param {string|undefined} pattern
-   * @param {any} args
+   * @param {*} args
    */
    */
   constructor(pattern = undefined, ...args) {
   constructor(pattern = undefined, ...args) {
     const message = pattern != null ? format(pattern, ...args) : undefined;
     const message = pattern != null ? format(pattern, ...args) : undefined;

+ 0 - 16
src/format.d.ts

@@ -1,16 +0,0 @@
-/**
- * Format.
- *
- * native:
- * s - string
- * d - digits
- * j - json
- *
- * extras:
- * v - value (valueToString.js)
- * l - list (arrayToString.js)
- *
- * @param pattern
- * @param args
- */
-export declare function format(pattern: string, ...args: any[]): string;

+ 10 - 9
src/format.js

@@ -13,20 +13,21 @@ import {valueToString} from './value-to-string.js';
  * v - value (valueToString.js)
  * v - value (valueToString.js)
  * l - list (arrayToString.js)
  * l - list (arrayToString.js)
  *
  *
- * @param {string} pattern
- * @return {string}
+ * @param {*} pattern
+ * @param {...*} args
+ * @returns {string}
  */
  */
-export function format(pattern) {
+export function format(pattern, ...args) {
   if (pattern instanceof Date) {
   if (pattern instanceof Date) {
     pattern = pattern.toISOString();
     pattern = pattern.toISOString();
   } else if (typeof pattern !== 'string') {
   } else if (typeof pattern !== 'string') {
     pattern = String(pattern);
     pattern = String(pattern);
   }
   }
   const re = /(%?)(%([sdjvl]))/g;
   const re = /(%?)(%([sdjvl]))/g;
-  const args = Array.prototype.slice.call(arguments, 1);
-  if (args.length) {
+  const argsQueue = [...args];
+  if (argsQueue.length) {
     pattern = pattern.replace(re, function (match, escaped, ptn, flag) {
     pattern = pattern.replace(re, function (match, escaped, ptn, flag) {
-      let arg = args.shift();
+      let arg = argsQueue.shift();
       switch (flag) {
       switch (flag) {
         case 's':
         case 's':
           arg = String(arg);
           arg = String(arg);
@@ -45,12 +46,12 @@ export function format(pattern) {
           break;
           break;
       }
       }
       if (!escaped) return arg;
       if (!escaped) return arg;
-      args.unshift(arg);
+      argsQueue.unshift(arg);
       return match;
       return match;
     });
     });
   }
   }
-  // arguments remain after formatting
-  if (args.length) pattern += ' ' + args.join(' ');
+  // has arguments after interpolation
+  if (argsQueue.length) pattern += ' ' + argsQueue.join(' ');
   // update escaped %% values
   // update escaped %% values
   pattern = pattern.replace(/%{2}/g, '%');
   pattern = pattern.replace(/%{2}/g, '%');
   return '' + pattern;
   return '' + pattern;

+ 7 - 0
src/format.spec.js

@@ -91,6 +91,7 @@ describe('format', function () {
     });
     });
 
 
     it('converts the given pattern of a named function to a string', function () {
     it('converts the given pattern of a named function to a string', function () {
+      // eslint-disable-next-line jsdoc/require-jsdoc
       function foo() {}
       function foo() {}
       const res = format(foo);
       const res = format(foo);
       expect(res).to.be.eq('function foo() {}');
       expect(res).to.be.eq('function foo() {}');
@@ -238,6 +239,7 @@ describe('format', function () {
     });
     });
 
 
     it('returns a string representation of the given named function', function () {
     it('returns a string representation of the given named function', function () {
+      // eslint-disable-next-line jsdoc/require-jsdoc
       function foo() {}
       function foo() {}
       const res = format('%s', foo);
       const res = format('%s', foo);
       expect(res).to.be.eq('function foo() {}');
       expect(res).to.be.eq('function foo() {}');
@@ -370,6 +372,7 @@ describe('format', function () {
     });
     });
 
 
     it('returns a string representation of the given named function', function () {
     it('returns a string representation of the given named function', function () {
+      // eslint-disable-next-line jsdoc/require-jsdoc
       function foo() {}
       function foo() {}
       const res = format('%d', foo);
       const res = format('%d', foo);
       expect(res).to.be.eq('NaN');
       expect(res).to.be.eq('NaN');
@@ -492,6 +495,7 @@ describe('format', function () {
     });
     });
 
 
     it('returns a string representation of the given named function', function () {
     it('returns a string representation of the given named function', function () {
+      // eslint-disable-next-line jsdoc/require-jsdoc
       function foo() {}
       function foo() {}
       const res = format('%j', foo);
       const res = format('%j', foo);
       expect(res).to.be.eq('undefined');
       expect(res).to.be.eq('undefined');
@@ -628,6 +632,7 @@ describe('format', function () {
     });
     });
 
 
     it('returns a string representation of the given named function', function () {
     it('returns a string representation of the given named function', function () {
+      // eslint-disable-next-line jsdoc/require-jsdoc
       function foo() {}
       function foo() {}
       const res = format('%v', foo);
       const res = format('%v', foo);
       expect(res).to.be.eq('Function');
       expect(res).to.be.eq('Function');
@@ -755,6 +760,7 @@ describe('format', function () {
       });
       });
 
 
       it('returns a string representation of the given named function', function () {
       it('returns a string representation of the given named function', function () {
+        // eslint-disable-next-line jsdoc/require-jsdoc
         function foo() {}
         function foo() {}
         const res = format('%l', foo);
         const res = format('%l', foo);
         expect(res).to.be.eq('Function');
         expect(res).to.be.eq('Function');
@@ -891,6 +897,7 @@ describe('format', function () {
       });
       });
 
 
       it('returns an element representation of the given named function', function () {
       it('returns an element representation of the given named function', function () {
+        // eslint-disable-next-line jsdoc/require-jsdoc
         function foo() {}
         function foo() {}
         const res = format('%l', [foo]);
         const res = format('%l', [foo]);
         expect(res).to.be.eq('Function');
         expect(res).to.be.eq('Function');

+ 0 - 5
src/index.d.ts

@@ -1,5 +0,0 @@
-export * from './format.js';
-export * from './errorf.js';
-export * from './array-to-string.js';
-export * from './value-to-string.js';
-export * from './invalid-argument-error.js';

+ 0 - 6
src/invalid-argument-error.d.ts

@@ -1,6 +0,0 @@
-import {Errorf} from './errorf.js';
-
-/**
- * Invalid argument error.
- */
-export declare class InvalidArgumentError extends Errorf {}

+ 0 - 1
src/utils/index.d.ts

@@ -1 +0,0 @@
-export * from './is-class.js';

+ 0 - 7
src/utils/is-class.d.ts

@@ -1,7 +0,0 @@
-/**
- * Returns true if the given value is ES6 class.
- *
- * @param {*} value
- * @returns {boolean}
- */
-export declare function isClass(value: unknown): boolean;

+ 0 - 6
src/value-to-string.d.ts

@@ -1,6 +0,0 @@
-/**
- * Value to string.
- *
- * @param input
- */
-export declare function valueToString(input: any): string;

+ 2 - 2
src/value-to-string.js

@@ -16,8 +16,8 @@ const BASE_CTOR_NAMES = [
 /**
 /**
  * Value to string.
  * Value to string.
  *
  *
- * @param {any} input
- * @return {string}
+ * @param {*} input
+ * @returns {string}
  */
  */
 export function valueToString(input) {
 export function valueToString(input) {
   if (input == null) return String(input);
   if (input == null) return String(input);

+ 1 - 0
src/value-to-string.spec.js

@@ -94,6 +94,7 @@ describe('valueToString', function () {
   });
   });
 
 
   it('returns a string representation of the given named function', function () {
   it('returns a string representation of the given named function', function () {
+    // eslint-disable-next-line jsdoc/require-jsdoc
     function foo() {}
     function foo() {}
     const res = valueToString(foo);
     const res = valueToString(foo);
     expect(res).to.be.eq('Function');
     expect(res).to.be.eq('Function');