podns 1.0.1 → 1.0.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2C,aAAa,EAA8C,MAAM,YAAY,CAAC;AAEhI;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,UAAQ,GAAG,aAAa,GAAG,IAAI,CA8GvF"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2C,aAAa,EAA8C,MAAM,YAAY,CAAC;AAEhI;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,UAAQ,GAAG,aAAa,GAAG,IAAI,CAgHvF"}
package/dist/parser.js CHANGED
@@ -17,7 +17,7 @@ function parseRecord(record, silenceErrors = false) {
17
17
  parsed = record.split("#")[0];
18
18
  }
19
19
  // remove all whitespaces, make everything lowercase
20
- parsed = parsed.trim().toLocaleLowerCase().replace(/\s/g, "");
20
+ parsed = parsed.trim().toLocaleLowerCase();
21
21
  // check special cases (wildcard, none, nothing other than a comment)
22
22
  switch (parsed) {
23
23
  case "*": {
@@ -55,7 +55,7 @@ function parseRecord(record, silenceErrors = false) {
55
55
  if (parsed.includes(";")) {
56
56
  const parsedTags = parsed.split(";").slice(1);
57
57
  for (const i in parsedTags) {
58
- let t = parsedTags[i];
58
+ let t = parsedTags[i].trim();
59
59
  if (t == "") {
60
60
  continue;
61
61
  }
@@ -84,7 +84,8 @@ function parseRecord(record, silenceErrors = false) {
84
84
  }
85
85
  }
86
86
  for (const i in parts) {
87
- if (!/^[a-z]+$/.test(parts[i])) {
87
+ parts[i] = parts[i].trim();
88
+ if (/^[!\*]+$/.test(parts[i]) || !parts[i]) {
88
89
  if (!silenceErrors) {
89
90
  throw Error("fetched pronoun \"" + record + "\" contains invalid characters in its pronoun set");
90
91
  }
@@ -93,6 +94,7 @@ function parseRecord(record, silenceErrors = false) {
93
94
  }
94
95
  }
95
96
  }
97
+ const cleanedRaw = parts;
96
98
  // special cases
97
99
  if (parts[0] == "it" && parts[1] == "its") {
98
100
  parts = ["it", "it", "its", "its", "itself"];
@@ -112,6 +114,6 @@ function parseRecord(record, silenceErrors = false) {
112
114
  type: "pronouns",
113
115
  raw: record,
114
116
  comment: comment,
115
- cleanedRaw: parsed
117
+ cleanedRaw: cleanedRaw.join("/")
116
118
  };
117
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podns",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "author": "lumap <lumap@duck.com>",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -44,9 +44,6 @@ test("parse invalid tag", () => {
44
44
  })
45
45
 
46
46
  test("parse invalid pronoun set", () => {
47
- expect(() => parseRecord("she/Ìê®;")).toThrowError("fetched pronoun \"she/Ìê®;\" contains invalid characters in its pronoun set")
48
- })
49
- test("parse invalid pronoun set 2", () => {
50
47
  expect(() => parseRecord("she/")).toThrowError("fetched pronoun \"she/\" contains invalid characters in its pronoun set")
51
48
  })
52
49
 
package/src/parser.ts CHANGED
@@ -16,7 +16,7 @@ export function parseRecord(record: string, silenceErrors = false): PronounRecor
16
16
  }
17
17
 
18
18
  // remove all whitespaces, make everything lowercase
19
- parsed = parsed.trim().toLocaleLowerCase().replace(/\s/g, "")
19
+ parsed = parsed.trim().toLocaleLowerCase()
20
20
 
21
21
  // check special cases (wildcard, none, nothing other than a comment)
22
22
  switch (parsed) {
@@ -55,7 +55,7 @@ export function parseRecord(record: string, silenceErrors = false): PronounRecor
55
55
  if (parsed.includes(";")) {
56
56
  const parsedTags = parsed.split(";").slice(1);
57
57
  for (const i in parsedTags) {
58
- let t = parsedTags[i]
58
+ let t = parsedTags[i].trim()
59
59
  if (t == "") {
60
60
  continue
61
61
  }
@@ -84,7 +84,8 @@ export function parseRecord(record: string, silenceErrors = false): PronounRecor
84
84
  }
85
85
 
86
86
  for (const i in parts) {
87
- if (!/^[a-z]+$/.test(parts[i])) {
87
+ parts[i]=parts[i].trim()
88
+ if (/^[!\*]+$/.test(parts[i]) || !parts[i]) {
88
89
  if (!silenceErrors) {
89
90
  throw Error("fetched pronoun \"" + record +"\" contains invalid characters in its pronoun set")
90
91
  } else {
@@ -92,6 +93,7 @@ export function parseRecord(record: string, silenceErrors = false): PronounRecor
92
93
  }
93
94
  }
94
95
  }
96
+ const cleanedRaw = parts
95
97
 
96
98
  // special cases
97
99
  if (parts[0] == "it" && parts[1] == "its") {
@@ -114,6 +116,6 @@ export function parseRecord(record: string, silenceErrors = false): PronounRecor
114
116
  type: "pronouns",
115
117
  raw: record,
116
118
  comment: comment,
117
- cleanedRaw: parsed
119
+ cleanedRaw: cleanedRaw.join("/")
118
120
  } as PronounsRecord
119
121
  }