@hardlydifficult/text 1.0.5 → 1.0.6
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 +29 -1
- package/dist/formatWithLineNumbers.d.ts +20 -0
- package/dist/formatWithLineNumbers.d.ts.map +1 -0
- package/dist/formatWithLineNumbers.js +30 -0
- package/dist/formatWithLineNumbers.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @hardlydifficult/text
|
|
2
2
|
|
|
3
|
-
Text utilities for error formatting, template replacement, and
|
|
3
|
+
Text utilities for error formatting, template replacement, chunking, and line numbering.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -121,3 +121,31 @@ convertFormat("name: Alice\nage: 30", "json");
|
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
The function tries to parse as JSON first, then falls back to YAML. Returns pretty-printed JSON with 2-space indent or clean YAML. Throws a descriptive error if the input is neither valid JSON nor YAML.
|
|
124
|
+
|
|
125
|
+
### `formatWithLineNumbers(content: string, startLine?: number): string`
|
|
126
|
+
|
|
127
|
+
Format text content with right-aligned line numbers. Each line is prefixed with its line number, padded to align properly based on the maximum line number.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import { formatWithLineNumbers } from "@hardlydifficult/text";
|
|
131
|
+
|
|
132
|
+
// Default: starts at line 1
|
|
133
|
+
formatWithLineNumbers("foo\nbar\nbaz");
|
|
134
|
+
// 1: foo
|
|
135
|
+
// 2: bar
|
|
136
|
+
// 3: baz
|
|
137
|
+
|
|
138
|
+
// Custom starting line for displaying file ranges
|
|
139
|
+
formatWithLineNumbers("hello\nworld", 10);
|
|
140
|
+
// 10: hello
|
|
141
|
+
// 11: world
|
|
142
|
+
|
|
143
|
+
// Proper alignment for larger line numbers
|
|
144
|
+
formatWithLineNumbers("line 1\nline 2\n...\nline 100", 98);
|
|
145
|
+
// 98: line 1
|
|
146
|
+
// 99: line 2
|
|
147
|
+
// 100: ...
|
|
148
|
+
// 101: line 100
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
This is useful for displaying code snippets, file contents, or log output with line numbers for reference.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format text content with right-aligned line numbers.
|
|
3
|
+
*
|
|
4
|
+
* @param content - The text content to format
|
|
5
|
+
* @param startLine - The starting line number (default: 1)
|
|
6
|
+
* @returns The formatted text with line numbers
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* formatWithLineNumbers("foo\nbar\nbaz")
|
|
11
|
+
* // Returns:
|
|
12
|
+
* // "1: foo\n2: bar\n3: baz"
|
|
13
|
+
*
|
|
14
|
+
* formatWithLineNumbers("hello\nworld", 10)
|
|
15
|
+
* // Returns:
|
|
16
|
+
* // "10: hello\n11: world"
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatWithLineNumbers(content: string, startLine?: number): string;
|
|
20
|
+
//# sourceMappingURL=formatWithLineNumbers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatWithLineNumbers.d.ts","sourceRoot":"","sources":["../src/formatWithLineNumbers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,SAAI,GAAG,MAAM,CAO5E"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatWithLineNumbers = formatWithLineNumbers;
|
|
4
|
+
/**
|
|
5
|
+
* Format text content with right-aligned line numbers.
|
|
6
|
+
*
|
|
7
|
+
* @param content - The text content to format
|
|
8
|
+
* @param startLine - The starting line number (default: 1)
|
|
9
|
+
* @returns The formatted text with line numbers
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* formatWithLineNumbers("foo\nbar\nbaz")
|
|
14
|
+
* // Returns:
|
|
15
|
+
* // "1: foo\n2: bar\n3: baz"
|
|
16
|
+
*
|
|
17
|
+
* formatWithLineNumbers("hello\nworld", 10)
|
|
18
|
+
* // Returns:
|
|
19
|
+
* // "10: hello\n11: world"
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function formatWithLineNumbers(content, startLine = 1) {
|
|
23
|
+
const lines = content.split("\n");
|
|
24
|
+
const maxNum = startLine + lines.length - 1;
|
|
25
|
+
const width = String(maxNum).length;
|
|
26
|
+
return lines
|
|
27
|
+
.map((line, i) => `${String(startLine + i).padStart(width)}: ${line}`)
|
|
28
|
+
.join("\n");
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=formatWithLineNumbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatWithLineNumbers.js","sourceRoot":"","sources":["../src/formatWithLineNumbers.ts"],"names":[],"mappings":";;AAkBA,sDAOC;AAzBD;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,qBAAqB,CAAC,OAAe,EAAE,SAAS,GAAG,CAAC;IAClE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;IACpC,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;SACrE,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,5 @@ export { buildFileTree, FILE_TREE_DEFAULTS } from "./buildFileTree.js";
|
|
|
7
7
|
export type { BuildTreeOptions } from "./buildFileTree.js";
|
|
8
8
|
export { convertFormat } from "./convertFormat.js";
|
|
9
9
|
export type { TextFormat } from "./convertFormat.js";
|
|
10
|
+
export { formatWithLineNumbers } from "./formatWithLineNumbers.js";
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACvE,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACvE,YAAY,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertFormat = exports.FILE_TREE_DEFAULTS = exports.buildFileTree = exports.formatDuration = exports.slugify = exports.chunkText = exports.extractPlaceholders = exports.replaceTemplate = exports.formatErrorForLog = exports.formatError = exports.getErrorMessage = void 0;
|
|
3
|
+
exports.formatWithLineNumbers = exports.convertFormat = exports.FILE_TREE_DEFAULTS = exports.buildFileTree = exports.formatDuration = exports.slugify = exports.chunkText = exports.extractPlaceholders = exports.replaceTemplate = exports.formatErrorForLog = exports.formatError = exports.getErrorMessage = void 0;
|
|
4
4
|
var errors_js_1 = require("./errors.js");
|
|
5
5
|
Object.defineProperty(exports, "getErrorMessage", { enumerable: true, get: function () { return errors_js_1.getErrorMessage; } });
|
|
6
6
|
Object.defineProperty(exports, "formatError", { enumerable: true, get: function () { return errors_js_1.formatError; } });
|
|
@@ -19,4 +19,6 @@ Object.defineProperty(exports, "buildFileTree", { enumerable: true, get: functio
|
|
|
19
19
|
Object.defineProperty(exports, "FILE_TREE_DEFAULTS", { enumerable: true, get: function () { return buildFileTree_js_1.FILE_TREE_DEFAULTS; } });
|
|
20
20
|
var convertFormat_js_1 = require("./convertFormat.js");
|
|
21
21
|
Object.defineProperty(exports, "convertFormat", { enumerable: true, get: function () { return convertFormat_js_1.convertFormat; } });
|
|
22
|
+
var formatWithLineNumbers_js_1 = require("./formatWithLineNumbers.js");
|
|
23
|
+
Object.defineProperty(exports, "formatWithLineNumbers", { enumerable: true, get: function () { return formatWithLineNumbers_js_1.formatWithLineNumbers; } });
|
|
22
24
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA8E;AAArE,4GAAA,eAAe,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AACxD,6CAAqE;AAA5D,8GAAA,eAAe,OAAA;AAAE,kHAAA,mBAAmB,OAAA;AAC7C,+CAA2C;AAAlC,yGAAA,SAAS,OAAA;AAClB,2CAAuC;AAA9B,qGAAA,OAAO,OAAA;AAChB,yDAAqD;AAA5C,mHAAA,cAAc,OAAA;AACvB,uDAAuE;AAA9D,iHAAA,aAAa,OAAA;AAAE,sHAAA,kBAAkB,OAAA;AAE1C,uDAAmD;AAA1C,iHAAA,aAAa,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA8E;AAArE,4GAAA,eAAe,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AACxD,6CAAqE;AAA5D,8GAAA,eAAe,OAAA;AAAE,kHAAA,mBAAmB,OAAA;AAC7C,+CAA2C;AAAlC,yGAAA,SAAS,OAAA;AAClB,2CAAuC;AAA9B,qGAAA,OAAO,OAAA;AAChB,yDAAqD;AAA5C,mHAAA,cAAc,OAAA;AACvB,uDAAuE;AAA9D,iHAAA,aAAa,OAAA;AAAE,sHAAA,kBAAkB,OAAA;AAE1C,uDAAmD;AAA1C,iHAAA,aAAa,OAAA;AAEtB,uEAAmE;AAA1D,iIAAA,qBAAqB,OAAA"}
|