pickier 0.1.22 → 0.1.23

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/dist/bin/cli.js CHANGED
@@ -19287,8 +19287,12 @@ var init_link_fragments = __esm(() => {
19287
19287
  check: (text, ctx) => {
19288
19288
  const issues = [];
19289
19289
  const lines = text.split(/\r?\n/);
19290
+ const inCode = getCodeBlockLines(lines);
19290
19291
  const headingIds = new Set;
19291
- for (const line of lines) {
19292
+ for (let li = 0;li < lines.length; li++) {
19293
+ if (inCode.has(li))
19294
+ continue;
19295
+ const line = lines[li];
19292
19296
  const atxMatch = line.match(/^#{1,6}\s+(.+?)(?:\s*#+\s*)?$/);
19293
19297
  if (atxMatch) {
19294
19298
  const headingText = atxMatch[1].trim();
@@ -19297,6 +19301,8 @@ var init_link_fragments = __esm(() => {
19297
19301
  }
19298
19302
  }
19299
19303
  for (let i = 0;i < lines.length; i++) {
19304
+ if (inCode.has(i))
19305
+ continue;
19300
19306
  const line = lines[i];
19301
19307
  const matches = line.matchAll(/\[[^\]]+\]\(#([^)]+)\)/g);
19302
19308
  for (const match of matches) {
@@ -19329,8 +19335,11 @@ var init_link_image_reference_definitions = __esm(() => {
19329
19335
  check: (text, ctx) => {
19330
19336
  const issues = [];
19331
19337
  const lines = text.split(/\r?\n/);
19338
+ const inCode = getCodeBlockLines(lines);
19332
19339
  const definitions = new Map;
19333
19340
  for (let i = 0;i < lines.length; i++) {
19341
+ if (inCode.has(i))
19342
+ continue;
19334
19343
  const line = lines[i];
19335
19344
  const defMatch = line.match(/^\[([^\]]+)\]:\s*\S+/);
19336
19345
  if (defMatch) {
@@ -19338,7 +19347,10 @@ var init_link_image_reference_definitions = __esm(() => {
19338
19347
  }
19339
19348
  }
19340
19349
  const usages = new Set;
19341
- for (const line of lines) {
19350
+ for (let i = 0;i < lines.length; i++) {
19351
+ if (inCode.has(i))
19352
+ continue;
19353
+ const line = lines[i];
19342
19354
  if (line.match(/^\[(?:[^\]]+)\]:\s*\S+/)) {
19343
19355
  continue;
19344
19356
  }
@@ -20309,7 +20321,10 @@ var init_no_reversed_links = __esm(() => {
20309
20321
  check: (text, ctx) => {
20310
20322
  const issues = [];
20311
20323
  const lines = text.split(/\r?\n/);
20324
+ const inCode = getCodeBlockLines(lines);
20312
20325
  for (let i = 0;i < lines.length; i++) {
20326
+ if (inCode.has(i))
20327
+ continue;
20313
20328
  const line = lines[i];
20314
20329
  const matches = line.matchAll(/\(([^)]+)\)\[(?:[^\]]+)\]/g);
20315
20330
  for (const match of matches) {
@@ -20469,7 +20484,10 @@ var init_no_space_in_links = __esm(() => {
20469
20484
  check: (text, ctx) => {
20470
20485
  const issues = [];
20471
20486
  const lines = text.split(/\r?\n/);
20487
+ const inCode = getCodeBlockLines(lines);
20472
20488
  for (let i = 0;i < lines.length; i++) {
20489
+ if (inCode.has(i))
20490
+ continue;
20473
20491
  const line = lines[i];
20474
20492
  const matches = line.matchAll(/\[(\s+(?:\S.*?|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF])|\s*(?:\S.*?|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF])\s+)\]\([^)]+\)/g);
20475
20493
  for (const match of matches) {
@@ -20715,16 +20733,11 @@ var init_proper_names = __esm(() => {
20715
20733
  if (properNames.length === 0) {
20716
20734
  return issues;
20717
20735
  }
20718
- let inCodeBlock = false;
20736
+ const inCode = getCodeBlockLines(lines);
20719
20737
  for (let i = 0;i < lines.length; i++) {
20720
- const line = lines[i];
20721
- if (/^(?:`{3,}|~{3,})/.test(line)) {
20722
- inCodeBlock = !inCodeBlock;
20738
+ if (inCode.has(i) && !checkCodeBlocks)
20723
20739
  continue;
20724
- }
20725
- if (inCodeBlock && !checkCodeBlocks) {
20726
- continue;
20727
- }
20740
+ const line = lines[i];
20728
20741
  for (const properName of properNames) {
20729
20742
  const regex = new RegExp(`\\b${properName}\\b`, "gi");
20730
20743
  const matches = line.matchAll(regex);
@@ -20954,10 +20967,13 @@ var init_strong_style = __esm(() => {
20954
20967
  check: (text, ctx) => {
20955
20968
  const issues = [];
20956
20969
  const lines = text.split(/\r?\n/);
20970
+ const inCode = getCodeBlockLines(lines);
20957
20971
  const options = ctx.options || {};
20958
20972
  const style = options.style || "consistent";
20959
20973
  let detectedStyle = null;
20960
20974
  for (let i = 0;i < lines.length; i++) {
20975
+ if (inCode.has(i))
20976
+ continue;
20961
20977
  const line = lines[i];
20962
20978
  const asteriskMatches = line.matchAll(/\*\*([^*]+)\*\*/g);
20963
20979
  for (const match of asteriskMatches) {
@@ -21017,27 +21033,51 @@ var init_strong_style = __esm(() => {
21017
21033
  fix: (text, ctx) => {
21018
21034
  const options = ctx.options || {};
21019
21035
  const style = options.style || "consistent";
21036
+ const lines = text.split(/\r?\n/);
21037
+ const inCode = getCodeBlockLines(lines);
21020
21038
  let targetStyle = "asterisk";
21021
21039
  if (style === "asterisk") {
21022
21040
  targetStyle = "asterisk";
21023
21041
  } else if (style === "underscore") {
21024
21042
  targetStyle = "underscore";
21025
21043
  } else if (style === "consistent") {
21026
- const asteriskMatch = text.match(/\*\*([^*]+)\*\*/);
21027
- const underscoreMatch = text.match(/__([^_]+)__/);
21028
- if (asteriskMatch && (!underscoreMatch || asteriskMatch.index < underscoreMatch.index)) {
21044
+ let firstAsterisk = null;
21045
+ let firstUnderscore = null;
21046
+ for (let i = 0;i < lines.length; i++) {
21047
+ if (inCode.has(i))
21048
+ continue;
21049
+ if (firstAsterisk === null) {
21050
+ const m = lines[i].match(/\*\*([^*]+)\*\*/);
21051
+ if (m)
21052
+ firstAsterisk = { line: i, col: m.index };
21053
+ }
21054
+ if (firstUnderscore === null) {
21055
+ const m = lines[i].match(/__([^_]+)__/);
21056
+ if (m)
21057
+ firstUnderscore = { line: i, col: m.index };
21058
+ }
21059
+ if (firstAsterisk && firstUnderscore)
21060
+ break;
21061
+ }
21062
+ const cmp = (a, b) => a.line !== b.line ? a.line - b.line : a.col - b.col;
21063
+ if (firstAsterisk && (!firstUnderscore || cmp(firstAsterisk, firstUnderscore) < 0))
21029
21064
  targetStyle = "asterisk";
21030
- } else if (underscoreMatch) {
21065
+ else if (firstUnderscore)
21031
21066
  targetStyle = "underscore";
21032
- }
21033
21067
  }
21034
- let fixed = text;
21035
- if (targetStyle === "asterisk") {
21036
- fixed = fixed.replace(/__([^_]+)__/g, "**$1**");
21037
- } else {
21038
- fixed = fixed.replace(/\*\*([^*]+)\*\*/g, "__$1__");
21068
+ let changed = false;
21069
+ for (let i = 0;i < lines.length; i++) {
21070
+ if (inCode.has(i))
21071
+ continue;
21072
+ const before = lines[i];
21073
+ const after = targetStyle === "asterisk" ? before.replace(/__([^_]+)__/g, "**$1**") : before.replace(/\*\*([^*]+)\*\*/g, "__$1__");
21074
+ if (after !== before) {
21075
+ lines[i] = after;
21076
+ changed = true;
21077
+ }
21039
21078
  }
21040
- return fixed;
21079
+ return changed ? lines.join(`
21080
+ `) : text;
21041
21081
  }
21042
21082
  };
21043
21083
  });
@@ -37844,7 +37884,7 @@ var require_package = __commonJS((exports, module) => {
37844
37884
  module.exports = {
37845
37885
  name: "pickier",
37846
37886
  type: "module",
37847
- version: "0.1.22",
37887
+ version: "0.1.23",
37848
37888
  description: "Format, lint and more in a fraction of seconds.",
37849
37889
  author: "Chris Breuer <chris@stacksjs.org>",
37850
37890
  license: "MIT",
package/dist/src/index.js CHANGED
@@ -18904,8 +18904,12 @@ var init_link_fragments = __esm(() => {
18904
18904
  check: (text, ctx) => {
18905
18905
  const issues = [];
18906
18906
  const lines = text.split(/\r?\n/);
18907
+ const inCode = getCodeBlockLines(lines);
18907
18908
  const headingIds = new Set;
18908
- for (const line of lines) {
18909
+ for (let li = 0;li < lines.length; li++) {
18910
+ if (inCode.has(li))
18911
+ continue;
18912
+ const line = lines[li];
18909
18913
  const atxMatch = line.match(/^#{1,6}\s+(.+?)(?:\s*#+\s*)?$/);
18910
18914
  if (atxMatch) {
18911
18915
  const headingText = atxMatch[1].trim();
@@ -18914,6 +18918,8 @@ var init_link_fragments = __esm(() => {
18914
18918
  }
18915
18919
  }
18916
18920
  for (let i = 0;i < lines.length; i++) {
18921
+ if (inCode.has(i))
18922
+ continue;
18917
18923
  const line = lines[i];
18918
18924
  const matches = line.matchAll(/\[[^\]]+\]\(#([^)]+)\)/g);
18919
18925
  for (const match of matches) {
@@ -18946,8 +18952,11 @@ var init_link_image_reference_definitions = __esm(() => {
18946
18952
  check: (text, ctx) => {
18947
18953
  const issues = [];
18948
18954
  const lines = text.split(/\r?\n/);
18955
+ const inCode = getCodeBlockLines(lines);
18949
18956
  const definitions = new Map;
18950
18957
  for (let i = 0;i < lines.length; i++) {
18958
+ if (inCode.has(i))
18959
+ continue;
18951
18960
  const line = lines[i];
18952
18961
  const defMatch = line.match(/^\[([^\]]+)\]:\s*\S+/);
18953
18962
  if (defMatch) {
@@ -18955,7 +18964,10 @@ var init_link_image_reference_definitions = __esm(() => {
18955
18964
  }
18956
18965
  }
18957
18966
  const usages = new Set;
18958
- for (const line of lines) {
18967
+ for (let i = 0;i < lines.length; i++) {
18968
+ if (inCode.has(i))
18969
+ continue;
18970
+ const line = lines[i];
18959
18971
  if (line.match(/^\[(?:[^\]]+)\]:\s*\S+/)) {
18960
18972
  continue;
18961
18973
  }
@@ -19926,7 +19938,10 @@ var init_no_reversed_links = __esm(() => {
19926
19938
  check: (text, ctx) => {
19927
19939
  const issues = [];
19928
19940
  const lines = text.split(/\r?\n/);
19941
+ const inCode = getCodeBlockLines(lines);
19929
19942
  for (let i = 0;i < lines.length; i++) {
19943
+ if (inCode.has(i))
19944
+ continue;
19930
19945
  const line = lines[i];
19931
19946
  const matches = line.matchAll(/\(([^)]+)\)\[(?:[^\]]+)\]/g);
19932
19947
  for (const match of matches) {
@@ -20086,7 +20101,10 @@ var init_no_space_in_links = __esm(() => {
20086
20101
  check: (text, ctx) => {
20087
20102
  const issues = [];
20088
20103
  const lines = text.split(/\r?\n/);
20104
+ const inCode = getCodeBlockLines(lines);
20089
20105
  for (let i = 0;i < lines.length; i++) {
20106
+ if (inCode.has(i))
20107
+ continue;
20090
20108
  const line = lines[i];
20091
20109
  const matches = line.matchAll(/\[(\s+(?:\S.*?|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF])|\s*(?:\S.*?|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF])\s+)\]\([^)]+\)/g);
20092
20110
  for (const match of matches) {
@@ -20332,16 +20350,11 @@ var init_proper_names = __esm(() => {
20332
20350
  if (properNames.length === 0) {
20333
20351
  return issues;
20334
20352
  }
20335
- let inCodeBlock = false;
20353
+ const inCode = getCodeBlockLines(lines);
20336
20354
  for (let i = 0;i < lines.length; i++) {
20337
- const line = lines[i];
20338
- if (/^(?:`{3,}|~{3,})/.test(line)) {
20339
- inCodeBlock = !inCodeBlock;
20355
+ if (inCode.has(i) && !checkCodeBlocks)
20340
20356
  continue;
20341
- }
20342
- if (inCodeBlock && !checkCodeBlocks) {
20343
- continue;
20344
- }
20357
+ const line = lines[i];
20345
20358
  for (const properName of properNames) {
20346
20359
  const regex = new RegExp(`\\b${properName}\\b`, "gi");
20347
20360
  const matches = line.matchAll(regex);
@@ -20571,10 +20584,13 @@ var init_strong_style = __esm(() => {
20571
20584
  check: (text, ctx) => {
20572
20585
  const issues = [];
20573
20586
  const lines = text.split(/\r?\n/);
20587
+ const inCode = getCodeBlockLines(lines);
20574
20588
  const options = ctx.options || {};
20575
20589
  const style = options.style || "consistent";
20576
20590
  let detectedStyle = null;
20577
20591
  for (let i = 0;i < lines.length; i++) {
20592
+ if (inCode.has(i))
20593
+ continue;
20578
20594
  const line = lines[i];
20579
20595
  const asteriskMatches = line.matchAll(/\*\*([^*]+)\*\*/g);
20580
20596
  for (const match of asteriskMatches) {
@@ -20634,27 +20650,51 @@ var init_strong_style = __esm(() => {
20634
20650
  fix: (text, ctx) => {
20635
20651
  const options = ctx.options || {};
20636
20652
  const style = options.style || "consistent";
20653
+ const lines = text.split(/\r?\n/);
20654
+ const inCode = getCodeBlockLines(lines);
20637
20655
  let targetStyle = "asterisk";
20638
20656
  if (style === "asterisk") {
20639
20657
  targetStyle = "asterisk";
20640
20658
  } else if (style === "underscore") {
20641
20659
  targetStyle = "underscore";
20642
20660
  } else if (style === "consistent") {
20643
- const asteriskMatch = text.match(/\*\*([^*]+)\*\*/);
20644
- const underscoreMatch = text.match(/__([^_]+)__/);
20645
- if (asteriskMatch && (!underscoreMatch || asteriskMatch.index < underscoreMatch.index)) {
20661
+ let firstAsterisk = null;
20662
+ let firstUnderscore = null;
20663
+ for (let i = 0;i < lines.length; i++) {
20664
+ if (inCode.has(i))
20665
+ continue;
20666
+ if (firstAsterisk === null) {
20667
+ const m = lines[i].match(/\*\*([^*]+)\*\*/);
20668
+ if (m)
20669
+ firstAsterisk = { line: i, col: m.index };
20670
+ }
20671
+ if (firstUnderscore === null) {
20672
+ const m = lines[i].match(/__([^_]+)__/);
20673
+ if (m)
20674
+ firstUnderscore = { line: i, col: m.index };
20675
+ }
20676
+ if (firstAsterisk && firstUnderscore)
20677
+ break;
20678
+ }
20679
+ const cmp = (a, b) => a.line !== b.line ? a.line - b.line : a.col - b.col;
20680
+ if (firstAsterisk && (!firstUnderscore || cmp(firstAsterisk, firstUnderscore) < 0))
20646
20681
  targetStyle = "asterisk";
20647
- } else if (underscoreMatch) {
20682
+ else if (firstUnderscore)
20648
20683
  targetStyle = "underscore";
20649
- }
20650
20684
  }
20651
- let fixed = text;
20652
- if (targetStyle === "asterisk") {
20653
- fixed = fixed.replace(/__([^_]+)__/g, "**$1**");
20654
- } else {
20655
- fixed = fixed.replace(/\*\*([^*]+)\*\*/g, "__$1__");
20685
+ let changed = false;
20686
+ for (let i = 0;i < lines.length; i++) {
20687
+ if (inCode.has(i))
20688
+ continue;
20689
+ const before = lines[i];
20690
+ const after = targetStyle === "asterisk" ? before.replace(/__([^_]+)__/g, "**$1**") : before.replace(/\*\*([^*]+)\*\*/g, "__$1__");
20691
+ if (after !== before) {
20692
+ lines[i] = after;
20693
+ changed = true;
20694
+ }
20656
20695
  }
20657
- return fixed;
20696
+ return changed ? lines.join(`
20697
+ `) : text;
20658
20698
  }
20659
20699
  };
20660
20700
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pickier",
3
3
  "type": "module",
4
- "version": "0.1.22",
4
+ "version": "0.1.23",
5
5
  "description": "Format, lint and more in a fraction of seconds.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",