echokyt 0.0.2 → 0.0.3

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
@@ -15,5 +15,5 @@ A lightweight, zero-dependency utility library for smart text manipulation in Ty
15
15
  ## 🚀 Installation
16
16
 
17
17
  ```bash
18
- npm install echo-kit
18
+ npm install echokyt
19
19
  ```
@@ -0,0 +1 @@
1
+ export * from './readingTime.js';
@@ -0,0 +1 @@
1
+ export * from './readingTime.js';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./readingTime.js"), exports);
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readingTime = void 0;
4
+ /**
5
+ * Estimates reading time in minutes.
6
+ * Assumes an average reading speed of 200 WPM.
7
+ */
8
+ const readingTime = (text, wordsPerMinute = 200) => {
9
+ if (!text.trim())
10
+ return 0;
11
+ const words = text.trim().split(/\s+/).length;
12
+ return Math.ceil(words / wordsPerMinute);
13
+ };
14
+ exports.readingTime = readingTime;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./slugify.js"), exports);
18
+ __exportStar(require("./truncate.js"), exports);
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.slugify = void 0;
4
+ /**
5
+ * Converts a string into a URL-friendly slug.
6
+ * Example: "Hello World!" -> "hello-world"
7
+ */
8
+ const slugify = (text) => {
9
+ return text
10
+ .toLowerCase()
11
+ .trim()
12
+ .replace(/[^\w\s-]/g, '') // Remove special characters
13
+ .replace(/[\s_-]+/g, '-') // Replace spaces/underscores with a single hyphen
14
+ .replace(/^-+|-+$/g, ''); // Remove leading/trailing hyphens
15
+ };
16
+ exports.slugify = slugify;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.smartTruncate = void 0;
4
+ /**
5
+ * Truncates text at the nearest whole word.
6
+ */
7
+ const smartTruncate = (text, limit) => {
8
+ if (text.length <= limit)
9
+ return text;
10
+ const truncated = text.slice(0, limit);
11
+ const lastSpace = truncated.lastIndexOf(' ');
12
+ const cleanCut = lastSpace > 0 ? truncated.slice(0, lastSpace) : truncated;
13
+ return `${cleanCut}...`;
14
+ };
15
+ exports.smartTruncate = smartTruncate;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./format/index.js"), exports);
18
+ __exportStar(require("./analyze/index.js"), exports);
19
+ __exportStar(require("./parse/index.js"), exports);
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractHashtags = void 0;
4
+ const HASHTAG_REGEX = /(^|[^\w])#([\p{L}\p{M}0-9_]{1,64})/gu;
5
+ /**
6
+ * Extracts #hashtags from text.
7
+ */
8
+ const extractHashtags = (text) => {
9
+ if (!text)
10
+ return [];
11
+ const results = [];
12
+ let match;
13
+ HASHTAG_REGEX.lastIndex = 0;
14
+ while ((match = HASHTAG_REGEX.exec(text)) !== null) {
15
+ const prefix = match[1];
16
+ const value = match[2];
17
+ const index = match.index + prefix.length;
18
+ results.push({ value, index, raw: `#${value}` });
19
+ }
20
+ return results;
21
+ };
22
+ exports.extractHashtags = extractHashtags;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseMentionsAndHashtags = exports.extractHashtags = exports.extractMentions = void 0;
4
+ const mentions_js_1 = require("./mentions.js");
5
+ const hashtags_js_1 = require("./hashtags.js");
6
+ var mentions_js_2 = require("./mentions.js");
7
+ Object.defineProperty(exports, "extractMentions", { enumerable: true, get: function () { return mentions_js_2.extractMentions; } });
8
+ var hashtags_js_2 = require("./hashtags.js");
9
+ Object.defineProperty(exports, "extractHashtags", { enumerable: true, get: function () { return hashtags_js_2.extractHashtags; } });
10
+ const parseMentionsAndHashtags = (text) => ({
11
+ mentions: (0, mentions_js_1.extractMentions)(text),
12
+ hashtags: (0, hashtags_js_1.extractHashtags)(text),
13
+ });
14
+ exports.parseMentionsAndHashtags = parseMentionsAndHashtags;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractMentions = void 0;
4
+ const MENTION_REGEX = /(^|[^\w])@([\p{L}\p{M}0-9_]{1,32})/gu;
5
+ /**
6
+ * Extracts @mentions from text.
7
+ */
8
+ const extractMentions = (text) => {
9
+ if (!text)
10
+ return [];
11
+ const results = [];
12
+ let match;
13
+ MENTION_REGEX.lastIndex = 0;
14
+ while ((match = MENTION_REGEX.exec(text)) !== null) {
15
+ const prefix = match[1];
16
+ const value = match[2];
17
+ const index = match.index + prefix.length;
18
+ results.push({ value, index, raw: `@${value}` });
19
+ }
20
+ return results;
21
+ };
22
+ exports.extractMentions = extractMentions;
@@ -0,0 +1,2 @@
1
+ export * from './slugify.js';
2
+ export * from './truncate.js';
@@ -0,0 +1,2 @@
1
+ export * from './slugify.js';
2
+ export * from './truncate.js';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './format/truncate.js';
2
- export * from './format/slugify.js';
3
- export * from './analyze/readingTime.js';
1
+ export * from './format/index.js';
2
+ export * from './analyze/index.js';
3
+ export * from './parse/index.js';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from './format/truncate.js';
2
- export * from './format/slugify.js';
3
- export * from './analyze/readingTime.js';
1
+ export * from './format/index.js';
2
+ export * from './analyze/index.js';
3
+ export * from './parse/index.js';
@@ -0,0 +1,9 @@
1
+ export type HashtagToken = {
2
+ value: string;
3
+ index: number;
4
+ raw: string;
5
+ };
6
+ /**
7
+ * Extracts #hashtags from text.
8
+ */
9
+ export declare const extractHashtags: (text: string) => HashtagToken[];
@@ -0,0 +1,18 @@
1
+ const HASHTAG_REGEX = /(^|[^\w])#([\p{L}\p{M}0-9_]{1,64})/gu;
2
+ /**
3
+ * Extracts #hashtags from text.
4
+ */
5
+ export const extractHashtags = (text) => {
6
+ if (!text)
7
+ return [];
8
+ const results = [];
9
+ let match;
10
+ HASHTAG_REGEX.lastIndex = 0;
11
+ while ((match = HASHTAG_REGEX.exec(text)) !== null) {
12
+ const prefix = match[1];
13
+ const value = match[2];
14
+ const index = match.index + prefix.length;
15
+ results.push({ value, index, raw: `#${value}` });
16
+ }
17
+ return results;
18
+ };
@@ -0,0 +1,8 @@
1
+ export { extractMentions } from './mentions.js';
2
+ export type { MentionToken } from './mentions.js';
3
+ export { extractHashtags } from './hashtags.js';
4
+ export type { HashtagToken } from './hashtags.js';
5
+ export declare const parseMentionsAndHashtags: (text: string) => {
6
+ mentions: import("./mentions.js").MentionToken[];
7
+ hashtags: import("./hashtags.js").HashtagToken[];
8
+ };
@@ -0,0 +1,8 @@
1
+ import { extractMentions } from './mentions.js';
2
+ import { extractHashtags } from './hashtags.js';
3
+ export { extractMentions } from './mentions.js';
4
+ export { extractHashtags } from './hashtags.js';
5
+ export const parseMentionsAndHashtags = (text) => ({
6
+ mentions: extractMentions(text),
7
+ hashtags: extractHashtags(text),
8
+ });
@@ -0,0 +1,9 @@
1
+ export type MentionToken = {
2
+ value: string;
3
+ index: number;
4
+ raw: string;
5
+ };
6
+ /**
7
+ * Extracts @mentions from text.
8
+ */
9
+ export declare const extractMentions: (text: string) => MentionToken[];
@@ -0,0 +1,18 @@
1
+ const MENTION_REGEX = /(^|[^\w])@([\p{L}\p{M}0-9_]{1,32})/gu;
2
+ /**
3
+ * Extracts @mentions from text.
4
+ */
5
+ export const extractMentions = (text) => {
6
+ if (!text)
7
+ return [];
8
+ const results = [];
9
+ let match;
10
+ MENTION_REGEX.lastIndex = 0;
11
+ while ((match = MENTION_REGEX.exec(text)) !== null) {
12
+ const prefix = match[1];
13
+ const value = match[2];
14
+ const index = match.index + prefix.length;
15
+ results.push({ value, index, raw: `@${value}` });
16
+ }
17
+ return results;
18
+ };
package/package.json CHANGED
@@ -1,23 +1,85 @@
1
1
  {
2
2
  "name": "echokyt",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "A lightweight text utility library",
5
- "main": "./dist/index.js",
5
+ "main": "./dist/cjs/index.cjs",
6
+ "module": "./dist/index.js",
6
7
  "types": "./dist/index.d.ts",
7
8
  "exports": {
8
9
  ".": {
9
10
  "types": "./dist/index.d.ts",
10
- "import": "./dist/index.js"
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/cjs/index.cjs"
13
+ },
14
+ "./format": {
15
+ "types": "./dist/format/index.d.ts",
16
+ "import": "./dist/format/index.js",
17
+ "require": "./dist/cjs/format/index.cjs"
18
+ },
19
+ "./format/*": {
20
+ "types": "./dist/format/*.d.ts",
21
+ "import": "./dist/format/*.js",
22
+ "require": "./dist/cjs/format/*.cjs"
23
+ },
24
+ "./analyze": {
25
+ "types": "./dist/analyze/index.d.ts",
26
+ "import": "./dist/analyze/index.js",
27
+ "require": "./dist/cjs/analyze/index.cjs"
28
+ },
29
+ "./analyze/*": {
30
+ "types": "./dist/analyze/*.d.ts",
31
+ "import": "./dist/analyze/*.js",
32
+ "require": "./dist/cjs/analyze/*.cjs"
33
+ },
34
+ "./parse": {
35
+ "types": "./dist/parse/index.d.ts",
36
+ "import": "./dist/parse/index.js",
37
+ "require": "./dist/cjs/parse/index.cjs"
38
+ },
39
+ "./parse/*": {
40
+ "types": "./dist/parse/*.d.ts",
41
+ "import": "./dist/parse/*.js",
42
+ "require": "./dist/cjs/parse/*.cjs"
43
+ },
44
+ "./package.json": "./package.json"
45
+ },
46
+ "typesVersions": {
47
+ "*": {
48
+ "format": [
49
+ "dist/format/index.d.ts"
50
+ ],
51
+ "format/*": [
52
+ "dist/format/*.d.ts"
53
+ ],
54
+ "analyze": [
55
+ "dist/analyze/index.d.ts"
56
+ ],
57
+ "analyze/*": [
58
+ "dist/analyze/*.d.ts"
59
+ ],
60
+ "parse": [
61
+ "dist/parse/index.d.ts"
62
+ ],
63
+ "parse/*": [
64
+ "dist/parse/*.d.ts"
65
+ ],
66
+ "*": [
67
+ "dist/*"
68
+ ]
11
69
  }
12
70
  },
13
71
  "files": [
14
72
  "dist"
15
73
  ],
16
74
  "scripts": {
17
- "build": "tsc",
18
- "clean": "rimraf dist coverage *.tsbuildinfo",
75
+ "build": "npm run clean && npm run build:esm && npm run build:cjs",
76
+ "build:esm": "tsc -p tsconfig.json",
77
+ "build:cjs": "tsc -p tsconfig.cjs.json && node scripts/rename-cjs.mjs",
78
+ "clean": "rimraf dist coverage && rimraf --glob \"*.tsbuildinfo\"",
19
79
  "lint": "eslint \"{src,tests}/**/*.ts\"",
20
- "format": "prettier --write \"**/*.{ts,js,json,md,yml,yaml}\"",
80
+ "format": "prettier --write \"**/*.{ts,js,mjs,cjs,json,md,yml,yaml}\"",
81
+ "bench": "npm run build && node benchmarks/bench.mjs",
82
+ "release": "standard-version",
21
83
  "test": "jest",
22
84
  "prepublishOnly": "npm run test && npm run build"
23
85
  },
@@ -38,7 +100,7 @@
38
100
  "esm"
39
101
  ],
40
102
  "author": "nyigoro",
41
- "license": "ISC",
103
+ "license": "MIT",
42
104
  "type": "module",
43
105
  "sideEffects": false,
44
106
  "engines": {
@@ -56,6 +118,7 @@
56
118
  "jest": "^29.0.0",
57
119
  "prettier": "^3.2.5",
58
120
  "rimraf": "^5.0.0",
121
+ "standard-version": "^9.5.0",
59
122
  "ts-jest": "^29.0.0",
60
123
  "typescript": "^5.9.3"
61
124
  }