@tricoteuses/senat 2.5.7 → 2.5.9

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.
Files changed (2) hide show
  1. package/lib/model/texte.js +23 -10
  2. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { JSDOM } from "jsdom";
2
- import { AKN_WORKFLOW_IDENTIFICATION_STRUCTURE_REGEXP, AKN_IDENTIFICATION_STRUCTURE_REGEXP, } from "../scripts/datautil";
2
+ import { AKN_IDENTIFICATION_STRUCTURE_REGEXP, AKN_WORKFLOW_IDENTIFICATION_STRUCTURE_REGEXP } from "../scripts/datautil";
3
3
  import { DivisionType, } from "../types/texte";
4
4
  function buildWorklow(metaElement) {
5
5
  const stepElements = metaElement.querySelectorAll("workflow step");
@@ -136,6 +136,7 @@ export function transformTexte(document) {
136
136
  ?.getAttribute("value") ?? "";
137
137
  const identificationParts = AKN_IDENTIFICATION_STRUCTURE_REGEXP.exec(identification)?.groups;
138
138
  const bodyElement = document.querySelector("body");
139
+ const sessionYears = identificationParts?.["session"]?.split("-") || null;
139
140
  const datePresentation = metaElement
140
141
  ?.querySelector("FRBRdate[name='#presentation']")
141
142
  ?.getAttribute("date");
@@ -160,7 +161,7 @@ export function transformTexte(document) {
160
161
  ?.querySelector("FRBRalias[name='url-AN']")
161
162
  ?.getAttribute("value") || null,
162
163
  type: identificationParts?.["type"] || null,
163
- session: identificationParts?.["session"] || null,
164
+ session: sessionYears && sessionYears.length > 0 ? sessionYears[0] : null,
164
165
  numero: identificationParts?.["numTexte"]
165
166
  ? parseInt(identificationParts["numTexte"])
166
167
  : null,
@@ -194,10 +195,10 @@ export function transformExposeDesMotifs(document) {
194
195
  continue;
195
196
  }
196
197
  else {
197
- sectionElement.removeChild(secondParagraph);
198
+ secondParagraph.remove();
198
199
  }
199
200
  }
200
- sectionElement.removeChild(firstParagraph);
201
+ firstParagraph.remove();
201
202
  return {
202
203
  text: sectionElement.textContent?.trim() ?? null,
203
204
  html: sectionElement.innerHTML?.trim() ?? null,
@@ -230,14 +231,26 @@ export async function parseTexteFromFile(xmlFilePath) {
230
231
  return null;
231
232
  }
232
233
  export function parseExposeDesMotifs(exposeDesMotifsHtml) {
233
- const { document } = new JSDOM(exposeDesMotifsHtml, {
234
- contentType: "text/html",
235
- }).window;
236
- return transformExposeDesMotifs(document);
234
+ try {
235
+ const { document } = new JSDOM(exposeDesMotifsHtml, {
236
+ contentType: "text/html",
237
+ }).window;
238
+ return transformExposeDesMotifs(document);
239
+ }
240
+ catch (error) {
241
+ console.error(`Could not parse exposé des motifs with error ${error}`);
242
+ }
243
+ return null;
237
244
  }
238
245
  // Prevent from memory leak
239
246
  // https://github.com/jsdom/jsdom/issues/2583#issuecomment-559520814
240
247
  export async function parseExposeDesMotifsFromFile(htmlFilePath) {
241
- const { document } = (await JSDOM.fromFile(htmlFilePath, { contentType: "text/html" })).window;
242
- return transformExposeDesMotifs(document);
248
+ try {
249
+ const { document } = (await JSDOM.fromFile(htmlFilePath, { contentType: "text/html" })).window;
250
+ return transformExposeDesMotifs(document);
251
+ }
252
+ catch (error) {
253
+ console.error(`Could not parse exposé des motifs with error ${error}`);
254
+ }
255
+ return null;
243
256
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tricoteuses/senat",
3
- "version": "2.5.7",
3
+ "version": "2.5.9",
4
4
  "description": "Handle French Sénat's open data",
5
5
  "keywords": [
6
6
  "France",