├── .gitignore ├── README.md ├── package.json ├── LICENSE └── turkish-suffixes.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | bower_components 3 | coverage 4 | .DS_Store 5 | npm-debug.log 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # turkish-suffixes 2 | 3 | ## how to install 4 | 5 | ### npm 6 | ```sh 7 | npm install turkish-suffixes --save 8 | ``` 9 | 10 | ## how to use 11 | ### node 12 | ```js 13 | const ts = require('turkish-suffixes'); 14 | ``` 15 | 16 | #variables and values 17 | ```text 18 | suffix -> "in", "e", "i", "de", "den", "ile" 19 | apostrof -> true, false (if use false apostrof don't show) 20 | apostrofMark -> "'","`" 21 | ``` 22 | 23 | ## examples 24 | ```js 25 | ts("İstanbul", "de", true, "'"); //İstanbul'da 26 | ts("büyük masa", "de", false, "'"); //büyük masada 27 | ts("Atatürk", "in", true, "`"); // Atatürk`ün 28 | ``` 29 | 30 | ## thanks 31 | https://github.com/hicay 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "turkish-suffixes", 3 | "version": "1.1.2", 4 | "description": "Turkish Suffixes", 5 | "main": "turkish-suffixes.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/bhdrgkz/turkish-suffixes.git" 12 | }, 13 | "keywords": [ 14 | "turkish", 15 | "suffix", 16 | "string", 17 | "cases", 18 | "turkish", 19 | "suffixes", 20 | "possessive", 21 | "word" 22 | ], 23 | "author": "Bahadır Gököz ", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/bhdrgkz/turkish-suffixes/issues" 27 | }, 28 | "homepage": "https://github.com/bhdrgkz/turkish-suffixes" 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Bahadır 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /turkish-suffixes.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | function in_array(obj, arr) { 4 | for (let i = 0; i < arr.length; i++) { 5 | if (arr[i] == obj) return true; 6 | } 7 | return false; 8 | } 9 | 10 | function suffixes(string, suffix, apostrof, apostrofMark) { 11 | let result = ""; 12 | const hardConsonantLetters = ["ç", "f", "h", "k", "p", "s", "ş", "t"]; 13 | let matchesVowelLetters = string.match(/[aeıioöuü]/g); 14 | let lastVowelLetter = matchesVowelLetters[matchesVowelLetters.length - 1]; 15 | let lastLetter = string.charAt(string.length - 1); 16 | let stringSuffix = ""; 17 | 18 | if (apostrof === false) { 19 | apostrofMark = ""; 20 | } 21 | 22 | switch (suffix) { 23 | case "in": 24 | if (lastLetter == "a" || lastLetter == "ı") { 25 | stringSuffix = "nın"; 26 | } else if (lastLetter == "e" || lastLetter == "i") { 27 | stringSuffix = "nin"; 28 | } else if (lastLetter == "u" || lastLetter == "o") { 29 | stringSuffix = "nun"; 30 | } else if (lastLetter == "ö" || lastLetter == "ü") { 31 | stringSuffix = "nün"; 32 | } else if (lastVowelLetter == "a" || lastVowelLetter == "ı") { 33 | stringSuffix = "ın"; 34 | } else if (lastVowelLetter == "e" || lastVowelLetter == "i") { 35 | stringSuffix = "in"; 36 | } else if (lastVowelLetter == "u" || lastVowelLetter == "o") { 37 | stringSuffix = "un"; 38 | } else if (lastVowelLetter == "ö" || lastVowelLetter == "ü") { 39 | stringSuffix = "ün"; 40 | } else { 41 | stringSuffix = "ın"; 42 | } 43 | break; 44 | case "e": 45 | if ( 46 | lastLetter == "a" || 47 | lastLetter == "ı" || 48 | lastLetter == "u" || 49 | lastLetter == "o" 50 | ) { 51 | stringSuffix = "ya"; 52 | } else if ( 53 | lastLetter == "e" || 54 | lastLetter == "i" || 55 | lastLetter == "ö" || 56 | lastLetter == "ü" 57 | ) { 58 | stringSuffix = "ye"; 59 | } else if ( 60 | lastVowelLetter == "a" || 61 | lastVowelLetter == "ı" || 62 | lastVowelLetter == "u" || 63 | lastVowelLetter == "o" 64 | ) { 65 | stringSuffix = "a"; 66 | } else if ( 67 | lastVowelLetter == "e" || 68 | lastVowelLetter == "i" || 69 | lastVowelLetter == "ö" || 70 | lastVowelLetter == "ü" 71 | ) { 72 | stringSuffix = "e"; 73 | } else { 74 | stringSuffix = "a"; 75 | } 76 | break; 77 | case "i": 78 | if (lastLetter == "a" || lastLetter == "ı") { 79 | stringSuffix = "yı"; 80 | } else if (lastLetter == "e" || lastLetter == "i") { 81 | stringSuffix = "yi"; 82 | } else if (lastLetter == "u" || lastLetter == "o") { 83 | stringSuffix = "yu"; 84 | } else if (lastLetter == "ö" || lastLetter == "ü") { 85 | stringSuffix = "yü"; 86 | } else if (lastVowelLetter == "a" || lastVowelLetter == "ı") { 87 | stringSuffix = "ı"; 88 | } else if (lastVowelLetter == "e" || lastVowelLetter == "i") { 89 | stringSuffix = "i"; 90 | } else if (lastVowelLetter == "u" || lastVowelLetter == "o") { 91 | stringSuffix = "u"; 92 | } else if (lastVowelLetter == "ü" || lastVowelLetter == "ö") { 93 | stringSuffix = "ü"; 94 | } 95 | break; 96 | case "de": 97 | if ( 98 | lastLetter == "a" || 99 | lastLetter == "ı" || 100 | lastLetter == "u" || 101 | lastLetter == "o" 102 | ) { 103 | stringSuffix = "da"; 104 | } else if ( 105 | lastLetter == "e" || 106 | lastLetter == "i" || 107 | lastLetter == "ö" || 108 | lastLetter == "ü" 109 | ) { 110 | stringSuffix = "de"; 111 | } else if ( 112 | in_array(lastLetter, hardConsonantLetters) && 113 | (lastVowelLetter == "a" || 114 | lastVowelLetter == "ı" || 115 | lastVowelLetter === "u" || 116 | lastVowelLetter === "o") 117 | ) { 118 | stringSuffix = "ta"; 119 | } else if ( 120 | in_array(lastLetter, hardConsonantLetters) && 121 | (lastVowelLetter == "e" || 122 | lastVowelLetter == "i" || 123 | lastVowelLetter == "ü" || 124 | lastVowelLetter == "ö") 125 | ) { 126 | stringSuffix = "te"; 127 | } else if ( 128 | lastVowelLetter == "a" || 129 | lastVowelLetter == "ı" || 130 | lastVowelLetter == "u" || 131 | lastVowelLetter == "o" 132 | ) { 133 | stringSuffix = "da"; 134 | } else if ( 135 | lastVowelLetter == "e" || 136 | lastVowelLetter == "i" || 137 | lastVowelLetter == "ü" || 138 | lastVowelLetter == "ö" 139 | ) { 140 | stringSuffix = "de"; 141 | } else if (in_array(lastLetter, hardConsonantLetters)) { 142 | stringSuffix = "ta"; 143 | } else { 144 | stringSuffix = "da"; 145 | } 146 | break; 147 | case "den": 148 | if ( 149 | lastLetter == "a" || 150 | lastLetter == "ı" || 151 | lastLetter == "u" || 152 | lastLetter == "o" 153 | ) { 154 | stringSuffix = "dan"; 155 | } else if ( 156 | lastLetter == "e" || 157 | lastLetter == "i" || 158 | lastLetter == "ö" || 159 | lastLetter == "ü" 160 | ) { 161 | stringSuffix = "den"; 162 | } else if ( 163 | in_array(lastLetter, hardConsonantLetters) && 164 | (lastVowelLetter == "a" || 165 | lastVowelLetter == "ı" || 166 | lastVowelLetter == "u" || 167 | lastVowelLetter == "o") 168 | ) { 169 | stringSuffix = "tan"; 170 | } else if ( 171 | in_array(lastLetter, hardConsonantLetters) && 172 | (lastVowelLetter == "e" || 173 | lastVowelLetter == "i" || 174 | lastVowelLetter == "ö" || 175 | lastVowelLetter == "ü") 176 | ) { 177 | stringSuffix = "ten"; 178 | } else if ( 179 | lastVowelLetter == "a" || 180 | lastVowelLetter == "ı" || 181 | lastVowelLetter == "u" || 182 | lastVowelLetter == "o" 183 | ) { 184 | stringSuffix = "dan"; 185 | } else if ( 186 | lastVowelLetter == "e" || 187 | lastVowelLetter == "i" || 188 | lastVowelLetter == "ö" || 189 | lastVowelLetter == "ü" 190 | ) { 191 | stringSuffix = "den"; 192 | } else if (in_array(lastLetter, hardConsonantLetters)) { 193 | stringSuffix = "tan"; 194 | } else { 195 | stringSuffix = "dan"; 196 | } 197 | break; 198 | case "ile": 199 | apostrofMark = ""; 200 | if ( 201 | lastLetter == "a" || 202 | lastLetter == "ı" || 203 | lastLetter == "u" || 204 | lastLetter == "o" 205 | ) { 206 | stringSuffix = "yla"; 207 | } else if ( 208 | lastLetter == "e" || 209 | lastLetter == "i" || 210 | lastLetter == "ö" || 211 | lastLetter == "ü" 212 | ) { 213 | stringSuffix = "yle"; 214 | } else if ( 215 | lastVowelLetter == "a" || 216 | lastVowelLetter == "ı" || 217 | lastVowelLetter == "u" || 218 | lastVowelLetter == "o" 219 | ) { 220 | stringSuffix = "la"; 221 | } else if ( 222 | lastVowelLetter == "e" || 223 | lastVowelLetter == "i" || 224 | lastVowelLetter == "ö" || 225 | lastVowelLetter == "ü" 226 | ) { 227 | stringSuffix = "le"; 228 | } else { 229 | stringSuffix = "la"; 230 | } 231 | break; 232 | } 233 | result = string + apostrofMark + stringSuffix; 234 | return result; 235 | } 236 | 237 | module.exports = function (string, suffix, apostrof, apostrofMark) { 238 | return suffixes(string, suffix, apostrof, apostrofMark); 239 | }; 240 | --------------------------------------------------------------------------------