{"id":20420309,"url":"https://github.com/grantmacken/csv","last_synced_at":"2026-04-17T08:32:40.995Z","repository":{"id":72351350,"uuid":"172177930","full_name":"grantmacken/csv","owner":"grantmacken","description":"Yet another CSV xQuery library","archived":false,"fork":false,"pushed_at":"2019-03-09T07:59:35.000Z","size":50,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-05T04:29:39.117Z","etag":null,"topics":["arrow-functions","csv-converter","existdb","financial-data","xquery"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grantmacken.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":".github/SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-23T06:02:22.000Z","updated_at":"2022-01-05T04:46:27.000Z","dependencies_parsed_at":"2023-02-28T08:15:47.824Z","dependency_job_id":null,"html_url":"https://github.com/grantmacken/csv","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/grantmacken/csv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantmacken%2Fcsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantmacken%2Fcsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantmacken%2Fcsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantmacken%2Fcsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grantmacken","download_url":"https://codeload.github.com/grantmacken/csv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantmacken%2Fcsv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31921937,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"online","status_checked_at":"2026-04-17T02:00:06.879Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["arrow-functions","csv-converter","existdb","financial-data","xquery"],"created_at":"2024-11-15T06:42:26.839Z","updated_at":"2026-04-17T08:32:40.978Z","avatar_url":"https://github.com/grantmacken.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yet another CSV xQuery Library module\n\n[![Build Status](https://travis-ci.org/grantmacken/csv.svg?branch=master)](https://travis-ci.org/grantmacken/csv)\n\n[![GitHub release](https://img.shields.io/github/release/grantmacken/csv/all.svg)](https://gitHub.com/grantmacken/csv/releases/latest)\n\nThe \u003cb\u003ecsv\u003c/b\u003e xQuery library provides functions turn a CSV file into an array of\narrays. You can visualise the array of arrays as being like a spreadsheet.\nWe have multiple records where each record is in a row and each record contains fields in field column.\n\n[![asciicast](https://asciinema.org/a/232587.svg)](https://asciinema.org/a/232587)\n\n## Use Case\n\nI intend to use this library for handling downloaded CSV financial statements. \n\n## Basics\n\nStart some CSV properties, \nin the form of a key-value map. \nThen this map to create an array of arrays\n\n```\n let $map := map { \n    'href' : '/db/unit-tests/fixtures/2018-12.csv', \n    'header-line': 6,\n    'record-start': 8,\n    'separator': ','\n    } \n return\n $map =\u003e csv:lines() =\u003e csv:toArray($map)\n```\n\n## Convenience Functions\n\nThe lib provides a simple mapping of the CSV header line to the fields index integer\nSo if we have a header named 'amount' we can 'sum' the amount field column.\ne.g.\n\n```\n let $lines :=  $map =\u003e csv:lines()\n let $field := $lines =\u003e csv:mapFields($map)\n let $records := $lines =\u003e csv:toArray($map)\n let $sumAmount := string(sum( $records?*?($field('amount')) ! number(.)))\n```\n\nThe library also provides some formating alignment functions so when rendering on a terminal all the field columns will be lined up.\n\n```\nlet $lines :=  $map =\u003e csv:lines()\nlet $field := $lines =\u003e csv:mapFields($map)\nlet $records := $lines =\u003e csv:toArray($map)\nlet $width := $records =\u003e csv:colWidth($field) \nreturn ( \nfor $record in $records?*\n  let $date :=   csv:pad($record?($field('date')), $width('date') )\n  let $payee  := csv:pad($record?($field('payee')), $width('payee') )\n  let $amount := csv:pad($record?($field('amount')), $width('amount') )\n  return (\n  string-join(($date,$payee,$amount,$nl),'\u0026#9;')\n  )\n```\n\nThe following asciicast showcases the above mentioned field column alignment and \nperforming a sum calculation on the field column. \nThe CSV data comes from a downloaded monthly statement and is found in the unit-tests/fixtures folder \n\n[![asciicast](https://asciinema.org/a/232385.svg)](https://asciinema.org/a/232385)\n\n\u003c!--\n# Using This Library\n\n# Example\n\n# Deployment\n\n\nTODO!\n\n## Built With\n\n* [eXistdb docker image]() - xQuery engine and database\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. \n\n[latest release on this repo](https://github.com/grantmacken/csv/releases/latest\n--\u003e\n\u003c!--\n[![GitHub tag](https://img.shields.io/github/tag/grantmacken/csv.svg)](https://gitHub.com/grantmacken/csv/tags/)\n--\u003e\n\n\u003c!--\n## Contributing\n\nPlease read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426).\n--\u003e\n\u003c!--\n# TESTS\n\ncast of running tests\n\nLink to travis build\n--\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrantmacken%2Fcsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrantmacken%2Fcsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrantmacken%2Fcsv/lists"}