{"id":19338249,"url":"https://github.com/gbv/pica-data-js","last_synced_at":"2025-04-23T01:31:22.024Z","repository":{"id":57323388,"uuid":"295660699","full_name":"gbv/pica-data-js","owner":"gbv","description":"EcmaScript utilities to process PICA data","archived":false,"fork":false,"pushed_at":"2022-09-22T12:11:32.000Z","size":163,"stargazers_count":3,"open_issues_count":4,"forks_count":0,"subscribers_count":6,"default_branch":"dev","last_synced_at":"2025-04-15T18:06:50.632Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gbv.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-15T08:17:04.000Z","updated_at":"2024-07-23T09:16:55.000Z","dependencies_parsed_at":"2022-08-26T01:10:59.120Z","dependency_job_id":null,"html_url":"https://github.com/gbv/pica-data-js","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbv%2Fpica-data-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbv%2Fpica-data-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbv%2Fpica-data-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbv%2Fpica-data-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gbv","download_url":"https://codeload.github.com/gbv/pica-data-js/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250352269,"owners_count":21416461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T03:16:47.907Z","updated_at":"2025-04-23T01:31:21.549Z","avatar_url":"https://github.com/gbv.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pica-data\n\n[![Test and build](https://github.com/gbv/pica-data-js/workflows/Test/badge.svg)](https://github.com/gbv/pica-data-js/actions?query=workflow%3A%22Test%22)\n[![npm release](https://img.shields.io/npm/v/pica-data)](https://www.npmjs.com/package/pica-data)\n\nPICA+ record processing\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n  - [Parsing](#parsing)\n  - [Serializing](#serializing)\n  - [Access](#access)\n  - [Validation](#validation)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Install\n\n`npm install pica-data` (requires Node \u003e= v16)\n\n## Usage\n\nThis EcmaScript Module contains utility functions to process [PICA+ data](https://format.gbv.de/pica).\n\nThe following serialization formats are supported:\n\n- [PICA Plain](http://format.gbv.de/pica/plain) parsing and serialization (`plain`)\n- [Annotated PICA](http://format.gbv.de/pica/plain) parsing and serialization (`annotated`)\n- PICA Patch Plain (annotated PICA with annotation `+`, `-`, ` ` parsing (`patch-plain`)\n- [Normalized PICA](http://format.gbv.de/pica/normalized) parsing (`normalized`)\n- PICA Patch Normalized parsing (`patch-normalized`)\n- [PICA JSON](http://format.gbv.de/pica/json)\n\n### Parsing\n\nParsing from string is supported by exported function `parsePica`. The serialization format is passed as second argument or as option. The function always returns an array of records. Parsing errors result in skipped records unless option `error` is enabled. \n\n~~~js\nimport { parsePica } from \"pica-data\"\n\nconst records = parsePica(input, { format: \"plain\" })\n~~~\n\nParsing from readable streams is supported by parser functions `parseStream` (returns a stream of records) and `parseAll` (returns a promise resolving in an array of records).\n\n~~~js\nimport { parseStream, parseAll } from \"pica-data\"\n\n// transform stream\nparseStream(process.stdin, { format: \"plain\" })\n  .on(\"data\", record =\u003e console.log(record))\n  .on(\"error\", ({message, line}) =\u003e console.error(`${message} on line ${line}`))\n\n// promise stream to array\nparseAll(process.stdin, { format: \"plain\"})\n  .then(records =\u003e console.log(records))\n  .catch(e =\u003e console.error(`${e.message} on line ${e.line}`))\n~~~\n\nIn addition the function `parsePicaLine` can be used to parse a single line of PICA Plain (optionally annotated) into a PICA field.\n\nTo process PICA/XML as returned via SRU use [xml2js](https://www.npmjs.com/package/xml2js) and transform records with exported function `fromXML`:\n\n~~~js\nimport { fromXML, serializePica } from 'pica-data'\nimport createClient from '@natlibfi/sru-client'\n\ncreateClient({\n  url:'https://sru.k10plus.de/opac-de-627', version: '1.1',\n  recordSchema: 'picaxml', recordFormat: 'object'\n}).searchRetrieve('pica.tit=Beowulf')\n  .on('record', record =\u003e {\n     const pica = fromXML(record)\n     console.log(serializePica(pica))\n  })\n~~~\n\n### Serializing\n\n* function `serializePica` to serialize a PICA record in PICA Plain syntax (optionally annotated)\n* function `serializePicaField` to serialize a PICA field in PICA Plain syntax (optionally annotated)\n* function `picaFieldIdentifier` to generate a field identifier from a field or from an Avram field schedule\n\n### Access\n\n* function `getPPN` to extract the PPN of a record\n* class `PicaPath` to work with PICA Path expressions\n  * method `fieldIdentifier` to get the path's field identifier (tag and optional occurrence)\n  * method `tagString` to get the path's PICA tag, without occurrence\n  * method `occurrenceString` to get the path's occurrence (or an empty string)\n  * method `startOccurrence` to get the path's start occurrence (or an empty string)\n  * method `endOccurrence` to get the path's end occurrence (or an empty string)\n  * method `subfieldString` to get the path's subfield identifier (or an empty string)\n  * method `toString` to get field identifier and subfield identifier combined\n  * method `matchField(field)` to check whether a PICA field matches the path\n  * method `getFields(record)` to filter all matching PICA fields \n  * method `extractSubfields(field)` to filter out all matching subfield values\n  * method `getValues(record)` to get a (possibly empty) array of matching subfield values\n  * method `getUniqueValues(record)` same as `getValues` but unique values only\n\n### Validation\n\n* function `picaFieldSchedule` to look up a field schedule for a given field in an Avram schema\n* function `picaFieldScheduleIdentifier` to look up the field identifier of a field in an Avram schema\n* function `isPPN` to check whether a string looks like a valid PPN (including checksum)\n* function `ppnChecksum` to calculate the checksum of a PPN\n\n## Contributing\n\nPRs accepted against the `dev` branch. Never directly work on the main branch.\n\nFor releases (maintainers only) make changes on `dev` and then run the release script:\n\n```bash\nnpm run release:patch # or minor or major\n```\n\n## License\n\n[MIT License](LICENSE) Verbundzentrale des GBV (VZG)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbv%2Fpica-data-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgbv%2Fpica-data-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbv%2Fpica-data-js/lists"}