podns 1.0.0 → 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.
package/dist/index.js CHANGED
@@ -12,8 +12,8 @@ const parser_js_1 = require("./parser.js");
12
12
  async function getPronouns(domain, silenceParseErrors = true) {
13
13
  const pronounsRecords = await (0, http_js_1.getPronounsRecords)(domain);
14
14
  let processed = [];
15
- for (let r in pronounsRecords) {
16
- const parsed = (0, parser_js_1.parseRecord)(r, silenceParseErrors);
15
+ for (let i in pronounsRecords) {
16
+ const parsed = (0, parser_js_1.parseRecord)(pronounsRecords[i], silenceParseErrors);
17
17
  if (parsed != null) {
18
18
  processed.push(parsed);
19
19
  }
@@ -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.0",
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",
@@ -0,0 +1,7 @@
1
+ import { test } from "vitest";
2
+ import getPronouns from "./"
3
+
4
+ test("get some and see what it outputs", async () => {
5
+ const pronouns = await getPronouns("mauve.beer")
6
+ console.log(pronouns)
7
+ })
package/src/index.ts CHANGED
@@ -12,8 +12,8 @@ export default async function getPronouns(domain: string, silenceParseErrors = t
12
12
  const pronounsRecords = await getPronounsRecords(domain);
13
13
 
14
14
  let processed: PronounRecord[] = []
15
- for (let r in pronounsRecords) {
16
- const parsed = parseRecord(r, silenceParseErrors)
15
+ for (let i in pronounsRecords) {
16
+ const parsed = parseRecord(pronounsRecords[i], silenceParseErrors)
17
17
  if (parsed != null) {
18
18
  processed.push(parsed)
19
19
  }
@@ -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
 
@@ -134,4 +131,4 @@ test("parse they/them is automatically plural", () => {
134
131
  assert.equal(parsed.pronouns.possessiveDeterminer, undefined)
135
132
  assert.equal(parsed.pronouns.possessivePronoun, undefined)
136
133
  assert.equal(parsed.pronouns.reflexive, undefined)
137
- })
134
+ })
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
  }