turkish-text-utils 1.0.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 ADDED
@@ -0,0 +1,79 @@
1
+ # turkish-text-utils
2
+
3
+ A lightweight, zero-dependency utility library for handling Turkish string operations. It provides reliable methods for Turkish text normalization, URL-friendly slug generation, and locale-aware case-insensitive substring searching.
4
+
5
+ ## Installation
6
+
7
+ Install using npm:
8
+
9
+ ```bash
10
+ npm install turkish-text-utils
11
+ ```
12
+
13
+ Or using yarn:
14
+
15
+ ```bash
16
+ yarn add turkish-text-utils
17
+ ```
18
+
19
+ Or using pnpm:
20
+
21
+ ```bash
22
+ pnpm add turkish-text-utils
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ You can import the required utility functions directly from the package:
28
+
29
+ ```javascript
30
+ import { normalizeTr, toSlug, includesInsensitive } from 'turkish-text-utils';
31
+ ```
32
+
33
+ If you are using CommonJS:
34
+
35
+ ```javascript
36
+ const { normalizeTr, toSlug, includesInsensitive } = require('turkish-text-utils');
37
+ ```
38
+
39
+ ## API
40
+
41
+ ### `normalizeTr(text: string): string`
42
+
43
+ Converts all Turkish-specific characters in a given string to their English/ASCII lowercase equivalents.
44
+
45
+ ```javascript
46
+ // Example
47
+ const text = "Şeker Fıstıkçı Şahap ÖĞÜTÜCÜ";
48
+ console.log(normalizeTr(text));
49
+ // Output: "seker fistikci sahap ogutucu"
50
+ ```
51
+
52
+ ### `toSlug(text: string): string`
53
+
54
+ Generates a URL-friendly slug from a given Turkish string. It automatically normalizes Turkish characters, removes irregular symbols, and replaces spaces with hyphens `-`.
55
+
56
+ ```javascript
57
+ // Example
58
+ const title = "Türkiye'nin En Güzel Dağları ve Gölleri 2024!";
59
+ console.log(toSlug(title));
60
+ // Output: "turkiyenin-en-guzel-daglari-ve-golleri-2024"
61
+ ```
62
+
63
+ ### `includesInsensitive(text: string, search: string): boolean`
64
+
65
+ Performs a locale-aware, case-insensitive check to determine if the `search` string is found within `text`. This correctly handles the `I`/`ı` and `İ`/`i` problems inherent in the Turkish alphabet.
66
+
67
+ ```javascript
68
+ // Example
69
+ const content = "İstanbul BÜYÜKŞEHİR Belediyesi";
70
+
71
+ console.log(includesInsensitive(content, "istanbul")); // true
72
+ console.log(includesInsensitive(content, "BÜYÜK")); // true
73
+ console.log(includesInsensitive(content, "sehir")); // true
74
+ console.log(includesInsensitive(content, "Ankara")); // false
75
+ ```
76
+
77
+ ## License
78
+
79
+ [MIT](LICENSE)
@@ -0,0 +1,7 @@
1
+ declare function normalizeTr(text: string): string;
2
+
3
+ declare function toSlug(text: string): string;
4
+
5
+ declare function includesInsensitive(text: string, search: string): boolean;
6
+
7
+ export { includesInsensitive, normalizeTr, toSlug };
@@ -0,0 +1,7 @@
1
+ declare function normalizeTr(text: string): string;
2
+
3
+ declare function toSlug(text: string): string;
4
+
5
+ declare function includesInsensitive(text: string, search: string): boolean;
6
+
7
+ export { includesInsensitive, normalizeTr, toSlug };
package/dist/index.js ADDED
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ includesInsensitive: () => includesInsensitive,
24
+ normalizeTr: () => normalizeTr,
25
+ toSlug: () => toSlug
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/normalizeTr.ts
30
+ var TR_MAP = {
31
+ \u00E7: "c",
32
+ \u00C7: "c",
33
+ \u011F: "g",
34
+ \u011E: "g",
35
+ \u0131: "i",
36
+ I: "i",
37
+ \u0130: "i",
38
+ \u00F6: "o",
39
+ \u00D6: "o",
40
+ \u015F: "s",
41
+ \u015E: "s",
42
+ \u00FC: "u",
43
+ \u00DC: "u"
44
+ };
45
+ function normalizeTr(text) {
46
+ return text.split("").map((char) => {
47
+ var _a;
48
+ return (_a = TR_MAP[char]) != null ? _a : char;
49
+ }).join("").toLowerCase();
50
+ }
51
+
52
+ // src/toSlug.ts
53
+ function toSlug(text) {
54
+ return normalizeTr(text).replace(/[^a-z0-9\s-]/g, "").trim().replace(/\s+/g, "-").replace(/-+/g, "-");
55
+ }
56
+
57
+ // src/includesInsensitive.ts
58
+ function includesInsensitive(text, search) {
59
+ return normalizeTr(text).includes(normalizeTr(search));
60
+ }
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ includesInsensitive,
64
+ normalizeTr,
65
+ toSlug
66
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,37 @@
1
+ // src/normalizeTr.ts
2
+ var TR_MAP = {
3
+ \u00E7: "c",
4
+ \u00C7: "c",
5
+ \u011F: "g",
6
+ \u011E: "g",
7
+ \u0131: "i",
8
+ I: "i",
9
+ \u0130: "i",
10
+ \u00F6: "o",
11
+ \u00D6: "o",
12
+ \u015F: "s",
13
+ \u015E: "s",
14
+ \u00FC: "u",
15
+ \u00DC: "u"
16
+ };
17
+ function normalizeTr(text) {
18
+ return text.split("").map((char) => {
19
+ var _a;
20
+ return (_a = TR_MAP[char]) != null ? _a : char;
21
+ }).join("").toLowerCase();
22
+ }
23
+
24
+ // src/toSlug.ts
25
+ function toSlug(text) {
26
+ return normalizeTr(text).replace(/[^a-z0-9\s-]/g, "").trim().replace(/\s+/g, "-").replace(/-+/g, "-");
27
+ }
28
+
29
+ // src/includesInsensitive.ts
30
+ function includesInsensitive(text, search) {
31
+ return normalizeTr(text).includes(normalizeTr(search));
32
+ }
33
+ export {
34
+ includesInsensitive,
35
+ normalizeTr,
36
+ toSlug
37
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "turkish-text-utils",
3
+ "version": "1.0.0",
4
+ "description": "Utility functions for Turkish text normalization, slug generation, and insensitive text search.",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsup src/index.ts --format cjs,esm --dts --clean",
13
+ "test": "vitest run",
14
+ "format": "prettier --write 'src/**/*.ts' 'tests/**/*.ts'",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "keywords": [
18
+ "turkish",
19
+ "text",
20
+ "slug",
21
+ "string",
22
+ "utils"
23
+ ],
24
+ "license": "MIT",
25
+ "devDependencies": {
26
+ "prettier": "^3.8.1",
27
+ "tsup": "^8.5.1",
28
+ "typescript": "^6.0.2",
29
+ "vitest": "^4.1.2"
30
+ },
31
+ "author": "Sergen",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/sergen/turkish-text-utils.git"
35
+ },
36
+ "homepage": "https://github.com/sergen/turkish-text-utils#readme",
37
+ "bugs": {
38
+ "url": "https://github.com/sergen/turkish-text-utils/issues"
39
+ },
40
+ "module": "./dist/index.mjs",
41
+ "exports": {
42
+ "types": "./dist/index.d.ts",
43
+ "require": "./dist/index.js",
44
+ "import": "./dist/index.mjs"
45
+ }
46
+ }