greek-name-correction 2.1.2 → 2.2.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/README.md CHANGED
@@ -22,7 +22,8 @@ A powerful, zero-dependency Node.js library for correcting, formatting, and vali
22
22
  💾 **Database-Safe** - SQL-ready output
23
23
  🔤 **Sort Keys** - Accent-free sorting support
24
24
  ✅ **Validation** - Greek name pattern validation
25
- 🔧 **Flexible I/O** - Supports strings, arrays, and objects
25
+ 🔧 **Flexible I/O** - Supports strings, arrays, and objects
26
+ ✨ **Accent Addition** - Automatically adds accents to unaccented Greek names (one accent per word)
26
27
 
27
28
  ## Installation
28
29
  ```bash
@@ -55,6 +56,94 @@ console.log(result);
55
56
  // }
56
57
  ```
57
58
 
59
+ ## Command-Line Interface (CLI)
60
+
61
+ The library includes a CLI tool for use from the command line.
62
+
63
+ ### Installation
64
+
65
+ To use the CLI globally:
66
+ ```bash
67
+ npm install -g greek-name-correction
68
+ ```
69
+
70
+ Or use it directly with `npx`:
71
+ ```bash
72
+ npx greek-name-correction -name "NAME" [OPTIONS]
73
+ ```
74
+
75
+ ### Usage
76
+
77
+ ```bash
78
+ # Basic usage
79
+ greek-name-correction -name "γιώργος παπαδόπουλος"
80
+ # → "Γιώργος Παπαδόπουλος"
81
+
82
+ # Positional argument (name without -name flag)
83
+ greek-name-correction "Ραυτόπουλος Σταύρος" -convertToCase vocative
84
+ # → "Ραυτόπουλε Σταύρο"
85
+
86
+ # With options
87
+ greek-name-correction -name "Γιώργος Παπαδόπουλος" -convertToCase vocative
88
+ # → "Γιώργο Παπαδόπουλο"
89
+
90
+ # JSON output with preserveOriginal
91
+ greek-name-correction -name "Μαρία Κωνσταντίνου" -detectGender -addGeneralTitle -preserveOriginal -json
92
+ # → JSON object with all details
93
+ ```
94
+
95
+ ### Available Options
96
+
97
+ | Option | Description |
98
+ |--------|-------------|
99
+ | `-name, --name <name>` | Name to correct (required if not provided as positional argument) |
100
+ | `-convertToCase <case>` | Convert to case: `vocative` or `accusative` |
101
+ | `-transliterate <type>` | Transliteration: `greeklish-to-greek`, `greek-to-latin`, `greek-to-greeklish` |
102
+ | `-convertToGenitive` | Convert to genitive case |
103
+ | `-preserveOriginal` | Return object with original and corrected name |
104
+ | `-detectGender` | Detect gender from name |
105
+ | `-detectDiminutive` | Detect diminutive forms |
106
+ | `-suggestCorrections` | Suggest corrections for common misspellings |
107
+ | `-recognizeKatharevousa` | Recognize and convert Katharevousa forms |
108
+ | `-databaseSafe` | Make output database-safe |
109
+ | `-generateSortKey` | Generate sort key (accent-free) |
110
+ | `-statistics` | Generate name statistics |
111
+ | `-addGeneralTitle` | Add general title (κ./κα) based on gender |
112
+ | `-addAccents` | Add accents to firstname and lastname (one accent per word) |
113
+ | `-handleTitles` | Handle titles (default: true) |
114
+ | `-handleParticles` | Handle Greek particles (default: true) |
115
+ | `-strictMode` | Enable strict mode |
116
+ | `-json` | Output result as JSON |
117
+ | `-help, -h` | Show help message |
118
+ | `-version, -v` | Show version |
119
+
120
+ ### Examples
121
+
122
+ ```bash
123
+ # Vocative case conversion
124
+ greek-name-correction -name "Γιώργος Παπαδόπουλος" -convertToCase vocative
125
+
126
+ # Accusative case conversion
127
+ greek-name-correction -name "Δημήτρης Νικολάου" -convertToCase accusative
128
+
129
+ # Transliteration
130
+ greek-name-correction -name "giorgos papadopoulos" -transliterate greeklish-to-greek
131
+
132
+ # Multiple options with JSON output
133
+ greek-name-correction -name "Μαρία Κωνσταντίνου" -detectGender -addGeneralTitle -preserveOriginal -json
134
+
135
+ # Add accents to unaccented names
136
+ greek-name-correction -name "γιωργος παπαδοπουλος" -addAccents
137
+ # → "Γιώργος Παπαδόπουλος"
138
+
139
+ # Get help
140
+ greek-name-correction -help
141
+ ```
142
+
143
+ **Note for Windows/PowerShell users:** If you encounter issues with Greek characters in quotes, try:
144
+ - Using single quotes: `greek-name-correction -name 'Γιώργος Παπαδόπουλος'`
145
+ - Or use a file input: `echo "Γιώργος Παπαδόπουλος" | greek-name-correction`
146
+
58
147
  ## Usage Examples
59
148
 
60
149
  ### Basic String Correction
@@ -222,6 +311,43 @@ GreekNameCorrection('Ελένη Γεωργίου', {
222
311
  // }
223
312
  ```
224
313
 
314
+ ### Accent Addition
315
+ ```javascript
316
+ // Add accents to unaccented Greek names (one accent per word)
317
+ GreekNameCorrection('γιωργος παπαδοπουλος', {
318
+ addAccents: true
319
+ });
320
+ // → "Γιώργος Παπαδόπουλος"
321
+
322
+ GreekNameCorrection('μαρια κωνσταντινου', {
323
+ addAccents: true
324
+ });
325
+ // → "Μαρία Κωνσταντίνου"
326
+
327
+ // Words that already have accents are preserved
328
+ GreekNameCorrection('Γιώργος Παπαδόπουλος', {
329
+ addAccents: true
330
+ });
331
+ // → "Γιώργος Παπαδόπουλος" (unchanged)
332
+
333
+ // Works with preserveOriginal option
334
+ GreekNameCorrection('νικος αλεξιου', {
335
+ addAccents: true,
336
+ preserveOriginal: true
337
+ });
338
+ // → {
339
+ // corrected: "Νίκος Αλεξίου",
340
+ // original: "νικος αλεξιου",
341
+ // isValid: true
342
+ // }
343
+
344
+ // Each word gets exactly one accent
345
+ GreekNameCorrection('δημήτρης νικολάου', {
346
+ addAccents: true
347
+ });
348
+ // → "Δημήτρης Νικολάου"
349
+ ```
350
+
225
351
  ### Name Corrections
226
352
  ```javascript
227
353
  GreekNameCorrection('γιοργος παπαδοπουλος', {
@@ -347,6 +473,7 @@ GreekNameCorrection(input, options)
347
473
  | `detectDiminutive` | `boolean` | `false` | Detect diminutive/nickname forms |
348
474
  | `handleTitles` | `boolean` | `true` | Extract and format titles |
349
475
  | `addGeneralTitle` | `boolean` | `false` | Automatically add general title (κ. for men, κα for women) if no title exists (always lowercase) |
476
+ | `addAccents` | `boolean` | `false` | Add accents to firstname and lastname (one accent per word) |
350
477
  | `suggestCorrections` | `boolean` | `false` | Suggest corrections for misspellings |
351
478
  | `recognizeKatharevousa` | `boolean` | `false` | Convert archaic Greek forms |
352
479
  | `databaseSafe` | `boolean` | `false` | Remove problematic characters |
@@ -444,6 +571,7 @@ const result = GreekNameCorrection('dr giorgos tou papa', {
444
571
  preserveOriginal: true,
445
572
  handleTitles: true,
446
573
  addGeneralTitle: true,
574
+ addAccents: true,
447
575
  handleParticles: true,
448
576
  suggestCorrections: true,
449
577
  detectGender: true,
@@ -585,19 +713,61 @@ While designed for Node.js, the library can be bundled for browser use with tool
585
713
 
586
714
  ## TypeScript
587
715
 
588
- TypeScript definitions can be added. Example:
716
+ Full TypeScript support is included! The library comes with comprehensive type definitions for all features.
717
+
718
+ ### Installation
719
+
720
+ TypeScript definitions are automatically included when you install the package:
721
+
722
+ ```bash
723
+ npm install greek-name-correction
724
+ ```
725
+
726
+ ### Usage
727
+
589
728
  ```typescript
590
- declare function GreekNameCorrection(
591
- input: string | string[] | object | object[],
592
- options?: {
593
- jsonKey?: string;
594
- outputKey?: string;
595
- preserveOriginal?: boolean;
596
- // ... other options
597
- }
598
- ): string | string[] | object | object[];
729
+ import GreekNameCorrection = require('greek-name-correction');
730
+ // or
731
+ import GreekNameCorrection from 'greek-name-correction';
732
+
733
+ // TypeScript will provide full type checking and IntelliSense
734
+ const result = GreekNameCorrection('γιάννης παπαδόπουλος', {
735
+ preserveOriginal: true,
736
+ detectGender: true,
737
+ convertToGenitive: true
738
+ });
739
+
740
+ // result is typed as GreekNameCorrectionResult
741
+ console.log(result.corrected); // string
742
+ console.log(result.gender); // 'male' | 'female' | 'unknown' | undefined
743
+ console.log(result.genitive); // string | undefined
599
744
  ```
600
745
 
746
+ ### Type Definitions
747
+
748
+ All types are exported for use in your TypeScript projects:
749
+
750
+ ```typescript
751
+ import {
752
+ GreekNameCorrectionOptions,
753
+ GreekNameCorrectionResult,
754
+ Gender,
755
+ NameParts,
756
+ DiminutiveInfo,
757
+ NameStatistics,
758
+ TransliterationMode,
759
+ CaseConversion
760
+ } from 'greek-name-correction';
761
+ ```
762
+
763
+ ### Features
764
+
765
+ - ✅ **Full type safety** - All function signatures are typed
766
+ - ✅ **IntelliSense support** - Autocomplete for all options
767
+ - ✅ **Type inference** - Return types are automatically inferred
768
+ - ✅ **Overloads** - Separate overloads for string, array, and object inputs
769
+ - ✅ **JSDoc comments** - Inline documentation in your IDE
770
+
601
771
  ## Contributing
602
772
 
603
773
  Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
@@ -627,6 +797,7 @@ The test suite covers:
627
797
  - Case conversions (genitive, vocative, accusative)
628
798
  - Title handling
629
799
  - Automatic general title addition
800
+ - Accent addition
630
801
  - Diminutive detection
631
802
  - Gender detection
632
803
  - Statistics generation
@@ -634,7 +805,11 @@ The test suite covers:
634
805
 
635
806
  ## Changelog
636
807
 
637
- ### Version 2.1.2 (Current)
808
+ ### Version 2.2.0 (Current)
809
+ - ✨ **Accent Addition Feature** - Added `addAccents` option to automatically add accents to unaccented Greek names (one accent per word). Intelligently places accents based on Greek accentuation rules and word endings.
810
+ - ✨ **TypeScript Support** - Added comprehensive TypeScript definitions (`index.d.ts`) with full type safety, IntelliSense support, and exported types
811
+
812
+ ### Version 2.1.2
638
813
  - 🐛 **Bug Fix** - Fixed `splitNameParts` to correctly filter out general titles (κ. and κα) from name parts
639
814
 
640
815
  ### Version 2.1.1
@@ -0,0 +1,196 @@
1
+ #!/usr/bin/env node
2
+ // bin/greek-name-correction.js - CLI for GreekNameCorrection
3
+ "use strict";
4
+
5
+ const GreekNameCorrection = require("../src/index");
6
+
7
+ /**
8
+ * Parse command-line arguments
9
+ */
10
+ function parseArgs() {
11
+ const args = process.argv.slice(2);
12
+ const options = {};
13
+ let name = null;
14
+
15
+ for (let i = 0; i < args.length; i++) {
16
+ const arg = args[i];
17
+ const nextArg = args[i + 1];
18
+
19
+ // Parse -name or --name
20
+ if ((arg === "-name" || arg === "--name") && nextArg) {
21
+ name = nextArg;
22
+ i++; // Skip next argument
23
+ }
24
+ // Parse -convertToCase or --convertToCase
25
+ else if ((arg === "-convertToCase" || arg === "--convertToCase") && nextArg) {
26
+ options.convertToCase = nextArg.toLowerCase();
27
+ i++;
28
+ }
29
+ // Parse -transliterate or --transliterate
30
+ else if ((arg === "-transliterate" || arg === "--transliterate") && nextArg) {
31
+ options.transliterate = nextArg.toLowerCase();
32
+ i++;
33
+ }
34
+ // Parse boolean flags
35
+ else if (arg === "-preserveOriginal" || arg === "--preserveOriginal") {
36
+ options.preserveOriginal = true;
37
+ }
38
+ else if (arg === "-convertToGenitive" || arg === "--convertToGenitive") {
39
+ options.convertToGenitive = true;
40
+ }
41
+ else if (arg === "-detectGender" || arg === "--detectGender") {
42
+ options.detectGender = true;
43
+ }
44
+ else if (arg === "-detectDiminutive" || arg === "--detectDiminutive") {
45
+ options.detectDiminutive = true;
46
+ }
47
+ else if (arg === "-suggestCorrections" || arg === "--suggestCorrections") {
48
+ options.suggestCorrections = true;
49
+ }
50
+ else if (arg === "-recognizeKatharevousa" || arg === "--recognizeKatharevousa") {
51
+ options.recognizeKatharevousa = true;
52
+ }
53
+ else if (arg === "-databaseSafe" || arg === "--databaseSafe") {
54
+ options.databaseSafe = true;
55
+ }
56
+ else if (arg === "-generateSortKey" || arg === "--generateSortKey") {
57
+ options.generateSortKey = true;
58
+ }
59
+ else if (arg === "-statistics" || arg === "--statistics") {
60
+ options.statistics = true;
61
+ }
62
+ else if (arg === "-addGeneralTitle" || arg === "--addGeneralTitle") {
63
+ options.addGeneralTitle = true;
64
+ }
65
+ else if (arg === "-addAccents" || arg === "--addAccents") {
66
+ options.addAccents = true;
67
+ }
68
+ else if (arg === "-handleTitles" || arg === "--handleTitles") {
69
+ options.handleTitles = true;
70
+ }
71
+ else if (arg === "-handleParticles" || arg === "--handleParticles") {
72
+ options.handleParticles = true;
73
+ }
74
+ else if (arg === "-strictMode" || arg === "--strictMode") {
75
+ options.strictMode = true;
76
+ }
77
+ else if (arg === "-json" || arg === "--json") {
78
+ options.json = true;
79
+ }
80
+ else if (arg === "-help" || arg === "--help" || arg === "-h" || arg === "--h") {
81
+ printHelp();
82
+ process.exit(0);
83
+ }
84
+ else if (arg === "-version" || arg === "--version" || arg === "-v" || arg === "--v") {
85
+ const pkg = require("../package.json");
86
+ console.log(pkg.version);
87
+ process.exit(0);
88
+ }
89
+ // If no flag, treat as name (for convenience)
90
+ else if (!name && !arg.startsWith("-")) {
91
+ name = arg;
92
+ }
93
+ }
94
+
95
+ return { name, options };
96
+ }
97
+
98
+ /**
99
+ * Print help message
100
+ */
101
+ function printHelp() {
102
+ console.log(`
103
+ Greek Name Correction CLI
104
+
105
+ Usage:
106
+ greek-name-correction -name "NAME" [OPTIONS]
107
+ greek-name-correction "NAME" [OPTIONS]
108
+
109
+ Options:
110
+ -name, --name <name> Name to correct (required if not provided as positional argument)
111
+ -convertToCase <case> Convert to case: 'vocative' or 'accusative'
112
+ -transliterate <type> Transliteration type: 'greeklish-to-greek', 'greek-to-latin', 'greek-to-greeklish'
113
+ -convertToGenitive Convert to genitive case
114
+ -preserveOriginal Return object with original and corrected name
115
+ -detectGender Detect gender from name
116
+ -detectDiminutive Detect diminutive forms
117
+ -suggestCorrections Suggest corrections for common misspellings
118
+ -recognizeKatharevousa Recognize and convert Katharevousa forms
119
+ -databaseSafe Make output database-safe
120
+ -generateSortKey Generate sort key (accent-free)
121
+ -statistics Generate name statistics
122
+ -addGeneralTitle Add general title (κ./κα) based on gender
123
+ -addAccents Add accents to firstname and lastname (one accent per word)
124
+ -handleTitles Handle titles (default: true)
125
+ -handleParticles Handle Greek particles (default: true)
126
+ -strictMode Enable strict mode
127
+ -json Output result as JSON
128
+ -help, -h Show this help message
129
+ -version, -v Show version
130
+
131
+ Examples:
132
+ greek-name-correction -name "γιώργος παπαδόπουλος"
133
+ greek-name-correction "Ραυτόπουλος Σταύρος" -convertToCase vocative
134
+ greek-name-correction -name "giorgos papadopoulos" -transliterate greeklish-to-greek
135
+ greek-name-correction -name "Γιώργος Παπαδόπουλος" -convertToGenitive -preserveOriginal -json
136
+ greek-name-correction -name "Μαρία Κωνσταντίνου" -detectGender -addGeneralTitle
137
+ greek-name-correction -name "γιωργος παπαδοπουλος" -addAccents
138
+ `);
139
+ }
140
+
141
+ /**
142
+ * Format output based on options
143
+ */
144
+ function formatOutput(result, options) {
145
+ if (options.json || options.preserveOriginal) {
146
+ // If JSON output requested or preserveOriginal is true, return JSON
147
+ return JSON.stringify(result, null, 2);
148
+ }
149
+
150
+ if (typeof result === "object" && result !== null && !Array.isArray(result)) {
151
+ // If it's an object result, check for case-specific fields first
152
+ if (options.convertToCase && result[options.convertToCase]) {
153
+ return result[options.convertToCase];
154
+ }
155
+ if (options.convertToGenitive && result.genitive) {
156
+ return result.genitive;
157
+ }
158
+ // Otherwise return corrected field
159
+ if (result.corrected !== undefined) {
160
+ return result.corrected;
161
+ }
162
+ // Fallback to JSON if object structure is unexpected
163
+ return JSON.stringify(result, null, 2);
164
+ }
165
+
166
+ return result;
167
+ }
168
+
169
+ /**
170
+ * Main CLI function
171
+ */
172
+ function main() {
173
+ const { name, options } = parseArgs();
174
+
175
+ if (!name) {
176
+ console.error("Error: Name is required. Use -name or provide as argument.");
177
+ console.error("Run with -help for usage information.");
178
+ process.exit(1);
179
+ }
180
+
181
+ try {
182
+ const result = GreekNameCorrection(name, options);
183
+ const output = formatOutput(result, options);
184
+ console.log(output);
185
+ } catch (error) {
186
+ console.error("Error:", error.message);
187
+ process.exit(1);
188
+ }
189
+ }
190
+
191
+ // Run if called directly
192
+ if (require.main === module) {
193
+ main();
194
+ }
195
+
196
+ module.exports = { parseArgs, formatOutput };