greek-name-correction 2.2.1 → 2.2.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # GreekNameCorrection
2
2
 
3
- A powerful, zero-dependency Node.js library for correcting, formatting, and validating Greek names with advanced features including transliteration, genitive conversion, and intelligent name processing.
3
+ A powerful, zero-dependency library for correcting, formatting, and validating Greek names with advanced features including transliteration, genitive conversion, and intelligent name processing. Works seamlessly in both Node.js and browser environments.
4
4
 
5
5
  ![NPM Version](https://img.shields.io/npm/v/greek-name-correction)
6
6
  ![License](https://img.shields.io/npm/l/greek-name-correction)
@@ -719,7 +719,29 @@ console.log(`${pronoun} ${person.corrected}`);
719
719
 
720
720
  ## Browser Support
721
721
 
722
- While designed for Node.js, the library can be bundled for browser use with tools like Webpack or Browserify.
722
+ The library is fully compatible with browser environments! It automatically detects the runtime environment and works seamlessly in both Node.js and browsers.
723
+
724
+ ### Features
725
+
726
+ - ✅ **Automatic Environment Detection** - No configuration needed
727
+ - ✅ **Zero Browser Errors** - No `__dirname` or Node.js-specific globals required
728
+ - ✅ **Full Feature Support** - All features work in browsers, including case conversion
729
+ - ✅ **Smart Fallback** - Uses hard-coded rules in browsers, markdown files in Node.js when available
730
+
731
+ ### Usage in Browser
732
+
733
+ ```javascript
734
+ // Works directly in browser (with bundler like Webpack, Browserify, or Vite)
735
+ import GreekNameCorrection from 'greek-name-correction';
736
+
737
+ // All features work, including case conversion
738
+ const result = GreekNameCorrection('Γιώργος Παπαδόπουλος', {
739
+ convertToCase: 'vocative',
740
+ detectGender: true
741
+ });
742
+ ```
743
+
744
+ The library automatically uses hard-coded rules for case conversion in browser environments, ensuring full functionality without file system access.
723
745
 
724
746
  ## TypeScript
725
747
 
@@ -815,7 +837,10 @@ The test suite covers:
815
837
 
816
838
  ## Changelog
817
839
 
818
- ### Version 2.2.1 (Current)
840
+ ### Version 2.2.2 (Current)
841
+ - 🔧 **Package Configuration** - Updated repository URL format in package.json
842
+
843
+ ### Version 2.2.1
819
844
  - 🔧 **Enhanced Accent Addition** - Improved `addAccents` feature with comprehensive name dictionary support. Now uses actual Greek name dictionaries from `generate_greek_names.js` for accurate accent placement on common names. Includes CLI support with `-addAccents` flag.
820
845
  - ✨ **Name Dictionary** - Built-in dictionary with 1,100+ Greek names (first names, surnames, compound surnames) for accurate accent placement
821
846
  - 🐛 **CLI Fix** - Added missing `-addAccents` flag to command-line interface
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greek-name-correction",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "A zero-dependency Node.js library for correcting and formatting Greek names with transliteration, genitive conversion, and advanced features",
5
5
  "main": "src/index.js",
6
6
  "types": "index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "license": "MIT",
27
27
  "repository": {
28
28
  "type": "git",
29
- "url": "https://github.com/sraftopo/greek-name-correction.git"
29
+ "url": "git+https://github.com/sraftopo/greek-name-correction.git"
30
30
  },
31
31
  "bugs": {
32
32
  "url": "https://github.com/sraftopo/greek-name-correction/issues"
@@ -36,7 +36,7 @@
36
36
  "node": ">=12.0.0"
37
37
  },
38
38
  "bin": {
39
- "greek-name-correction": "./bin/greek-name-correction.js"
39
+ "greek-name-correction": "bin/greek-name-correction.js"
40
40
  },
41
41
  "files": [
42
42
  "src/",
@@ -67,4 +67,4 @@
67
67
  }
68
68
  }
69
69
  }
70
- }
70
+ }
@@ -1,8 +1,31 @@
1
1
  // rulesParser.js
2
2
  "use strict";
3
3
 
4
- const fs = require("fs");
5
- const path = require("path");
4
+ // Browser environment detection
5
+ // Check if Node.js globals are available
6
+ function isNodeEnvironment() {
7
+ return (
8
+ typeof __dirname !== "undefined" &&
9
+ typeof require !== "undefined" &&
10
+ typeof module !== "undefined"
11
+ );
12
+ }
13
+
14
+ // Safely require Node.js modules only in Node.js environment
15
+ let fs, path;
16
+ if (isNodeEnvironment()) {
17
+ try {
18
+ fs = require("fs");
19
+ path = require("path");
20
+ } catch (e) {
21
+ // If require fails, we're likely in a browser environment
22
+ fs = null;
23
+ path = null;
24
+ }
25
+ } else {
26
+ fs = null;
27
+ path = null;
28
+ }
6
29
 
7
30
  /**
8
31
  * Parse markdown file and extract Greek name case conversion rules
@@ -10,6 +33,11 @@ const path = require("path");
10
33
  * @returns {Object} Parsed rules structure
11
34
  */
12
35
  function parseMarkdownRules(filePath) {
36
+ // In browser environments, fs is not available
37
+ if (!fs || !path) {
38
+ return null;
39
+ }
40
+
13
41
  try {
14
42
  const content = fs.readFileSync(filePath, "utf8");
15
43
  return parseMarkdownContent(content);
@@ -260,6 +288,12 @@ function extractEnding(name) {
260
288
  * Parse vocative rules from names_klitiki.md
261
289
  */
262
290
  function parseVocativeRules() {
291
+ // In browser environments, skip file reading and return null
292
+ // This will trigger fallback to hard-coded rules in cases.js
293
+ if (!isNodeEnvironment() || !path || typeof __dirname === "undefined") {
294
+ return null;
295
+ }
296
+
263
297
  const filePath = path.join(__dirname, "..", "names_klitiki.md");
264
298
  const rules = parseMarkdownRules(filePath);
265
299
 
@@ -448,6 +482,12 @@ function extractNameListsFromExamples(structuredRules, examples) {
448
482
  * Parse accusative rules from names_aitiatiki.md
449
483
  */
450
484
  function parseAccusativeRules() {
485
+ // In browser environments, skip file reading and return null
486
+ // This will trigger fallback to hard-coded rules in cases.js
487
+ if (!isNodeEnvironment() || !path || typeof __dirname === "undefined") {
488
+ return null;
489
+ }
490
+
451
491
  const filePath = path.join(__dirname, "..", "names_aitiatiki.md");
452
492
  const rules = parseMarkdownRules(filePath);
453
493