@markuplint/shared 5.0.0-alpha.2 → 5.0.0-dev.5

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/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [5.0.0-alpha.3](https://github.com/markuplint/markuplint/compare/v5.0.0-alpha.2...v5.0.0-alpha.3) (2026-02-26)
7
+
8
+ ### Features
9
+
10
+ - **shared:** add getPosition utility for offset-to-line/column conversion ([1cfab8b](https://github.com/markuplint/markuplint/commit/1cfab8b69614e9f9e8da87cfce5a96b2865b9a0e))
11
+
6
12
  # [5.0.0-alpha.2](https://github.com/markuplint/markuplint/compare/v5.0.0-alpha.1...v5.0.0-alpha.2) (2026-02-23)
7
13
 
8
14
  **Note:** Version bump only for package @markuplint/shared
@@ -86,4 +86,15 @@ export declare function branchesToPatterns<T>(branches: ReadonlyArray<Nullable<T
86
86
  * @param regexpLikeString - The regular expression pattern to parse.
87
87
  * @returns - The parsed regular expression or null if the pattern is invalid.
88
88
  */
89
+ /**
90
+ * Computes the line and column of a position within a code fragment.
91
+ *
92
+ * @param rawCodeFragment - The full raw source text
93
+ * @param startOffset - The zero-based byte offset to compute the position of
94
+ * @returns An object containing one-based `line` and `column`
95
+ */
96
+ export declare function getPosition(rawCodeFragment: string, startOffset: number): {
97
+ readonly line: number;
98
+ readonly column: number;
99
+ };
89
100
  export declare function regexParser(regexpLikeString: string): RegExp | null;
package/lib/functions.js CHANGED
@@ -120,6 +120,19 @@ export function branchesToPatterns(branches) {
120
120
  * @param regexpLikeString - The regular expression pattern to parse.
121
121
  * @returns - The parsed regular expression or null if the pattern is invalid.
122
122
  */
123
+ /**
124
+ * Computes the line and column of a position within a code fragment.
125
+ *
126
+ * @param rawCodeFragment - The full raw source text
127
+ * @param startOffset - The zero-based byte offset to compute the position of
128
+ * @returns An object containing one-based `line` and `column`
129
+ */
130
+ export function getPosition(rawCodeFragment, startOffset) {
131
+ const lines = rawCodeFragment.slice(0, startOffset).split('\n');
132
+ const line = lines.length;
133
+ const column = (lines.at(-1) ?? '').length + 1;
134
+ return { line, column };
135
+ }
123
136
  export function regexParser(regexpLikeString) {
124
137
  if (!regexpLikeString.startsWith('/')) {
125
138
  // Early return if the string does not start with a slash.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/shared",
3
- "version": "5.0.0-alpha.2",
3
+ "version": "5.0.0-dev.5+e96392f56",
4
4
  "description": "Shared functions for Markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -29,5 +29,5 @@
29
29
  "dependencies": {
30
30
  "html-entities": "2.6.0"
31
31
  },
32
- "gitHead": "31ccf1e81443ea3f93597d287595211f1823ddcf"
32
+ "gitHead": "e96392f56e4bc8165ba59622b41c822703a96372"
33
33
  }