{"id":31530219,"url":"https://github.com/frictionlessdata/datapackage-js","last_synced_at":"2025-10-04T01:19:39.196Z","repository":{"id":57211503,"uuid":"44951060","full_name":"frictionlessdata/datapackage-js","owner":"frictionlessdata","description":"A JavaScript library for working with Data Package.","archived":false,"fork":false,"pushed_at":"2025-08-06T20:44:10.000Z","size":285,"stargazers_count":43,"open_issues_count":9,"forks_count":14,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-09-11T05:36:38.007Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://frictionlessdata.io/","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/frictionlessdata.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-26T06:49:25.000Z","updated_at":"2024-08-15T07:42:52.000Z","dependencies_parsed_at":"2022-08-30T13:11:52.788Z","dependency_job_id":null,"html_url":"https://github.com/frictionlessdata/datapackage-js","commit_stats":null,"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"purl":"pkg:github/frictionlessdata/datapackage-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Fdatapackage-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Fdatapackage-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Fdatapackage-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Fdatapackage-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frictionlessdata","download_url":"https://codeload.github.com/frictionlessdata/datapackage-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frictionlessdata%2Fdatapackage-js/sbom","scorecard":{"id":411427,"data":{"date":"2025-08-11","repo":{"name":"github.com/frictionlessdata/datapackage-js","commit":"7467c9ebe68b713fde15a28f4c78fe2b59ad2640"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 2/29 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/general.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/general.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/frictionlessdata/datapackage-js/general.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/general.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/frictionlessdata/datapackage-js/general.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/general.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/frictionlessdata/datapackage-js/general.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/general.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/frictionlessdata/datapackage-js/general.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/general.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/frictionlessdata/datapackage-js/general.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/general.yml:56: update your workflow using https://app.stepsecurity.io/secureworkflow/frictionlessdata/datapackage-js/general.yml/main?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/general.yml:28","Warn: npmCommand not pinned by hash: .github/workflows/general.yml:49","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned","Info:   0 out of   2 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: MIT License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 5 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T22:48:07.691Z","repository_id":57211503,"created_at":"2025-08-18T22:48:07.692Z","updated_at":"2025-08-18T22:48:07.692Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278252417,"owners_count":25956295,"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","status":"online","status_checked_at":"2025-10-03T02:00:06.070Z","response_time":53,"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":[],"created_at":"2025-10-04T01:19:30.034Z","updated_at":"2025-10-04T01:19:39.187Z","avatar_url":"https://github.com/frictionlessdata.png","language":"JavaScript","readme":"# datapackage-js\n\n[![Build](https://img.shields.io/github/workflow/status/frictionlessdata/tableschema-js/general/main)](https://github.com/frictionlessdata/datapackage-js/actions)\n[![Coverage](https://img.shields.io/codecov/c/github/frictionlessdata/datapackage-js/main)](https://codecov.io/gh/frictionlessdata/datapackage-js)\n[![Registry](https://img.shields.io/npm/v/frictionless-datapackage-js.svg)](https://www.npmjs.com/package/frictionless-datapackage-js)\n[![Codebase](https://img.shields.io/badge/github-main-brightgreen)](https://github.com/frictionlessdata/datapackage-js)\n[![Support](https://img.shields.io/badge/support-discord-brightgreen)](https://discordapp.com/invite/Sewv6av)\n\nA library for working with [Data Packages](http://specs.frictionlessdata.io/data-package/).\n\n## Features\n\n - `Package` class for working with data packages\n - `Resource` class for working with data resources\n - `Profile` class for working with profiles\n - `validate` function for validating data package descriptors\n - `infer` function for inferring data package descriptors\n\n## Contents\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n\n- [Getting Started](#getting-started)\n  - [Installation](#installation)\n- [Documentation](#documentation)\n  - [Introduction](#introduction)\n  - [Working with Package](#working-with-package)\n  - [Working with Resource](#working-with-resource)\n  - [Working with Profile](#working-with-profile)\n  - [Working with validate/infer](#working-with-validateinfer)\n  - [Working with Foreign Keys](#working-with-foreign-keys)\n- [API Referencer](#api-referencer)\n  - [Package](#package)\n  - [Resource](#resource)\n  - [Profile](#profile)\n  - [validate(descriptor) ⇒ `Object`](#validatedescriptor-%E2%87%92-codeobjectcode)\n  - [infer(pattern) ⇒ `Object`](#inferpattern-%E2%87%92-codeobjectcode)\n  - [DataPackageError](#datapackageerror)\n  - [TableSchemaError](#tableschemaerror)\n- [Contributing](#contributing)\n- [Changelog](#changelog)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Getting Started\n\n### Installation\n\nThe package use semantic versioning. It means that major versions  could include breaking changes. It's highly recommended to specify `datapackage` version range in your `package.json` file e.g. `datapackage: ^1.0` which  will be added by default by `npm install --save`.\n\n#### NPM\n\n```bash\n$ npm install datapackage@latest # v1.0\n$ npm install datapackage # v0.8\n```\n\n#### CDN\n\n```html\n\u003cscript src=\"//unpkg.com/datapackage/dist/datapackage.min.js\"\u003e\u003c/script\u003e\n```\n\n## Documentation\n\n### Introduction\n\nLet's start with a simple example for Node.js:\n\n```javascript\nconst {Package} = require('datapackage')\n\nconst descriptor = {\n  resources: [\n    {\n      name: 'example',\n      profile: 'tabular-data-resource',\n      data: [\n        ['height', 'age', 'name'],\n        ['180', '18', 'Tony'],\n        ['192', '32', 'Jacob'],\n      ],\n      schema:  {\n        fields: [\n          {name: 'height', type: 'integer'},\n          {name: 'age', type: 'integer'},\n          {name: 'name', type: 'string'},\n        ],\n      }\n    }\n  ]\n}\n\nconst dataPackage = await Package.load(descriptor)\nconst resource = dataPackage.getResource('example')\nawait resource.read() // [[180, 18, 'Tony'], [192, 32, 'Jacob']]\n```\n\nAnd for browser:\n\n\u003e https://jsfiddle.net/rollninja/jp60q3zd/\n\nAfter the script registration the library will be available as a global variable `datapackage`:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003ctitle\u003edatapackage-js\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cscript src=\"//unpkg.com/datapackage/dist/datapackage.min.js\"\u003e\u003c/script\u003e\n    \u003cscript\u003e\n      const main = async () =\u003e {\n        const resource = await datapackage.Resource.load({path: 'https://raw.githubusercontent.com/frictionlessdata/datapackage-js/master/data/data.csv'})\n        const rows = await resource.read()\n        document.body.innerHTML += `\u003cdiv\u003e${resource.headers}\u003c/div\u003e`\n        for (const row of rows) {\n          document.body.innerHTML += `\u003cdiv\u003e${row}\u003c/div\u003e`\n        }\n      }\n      main()\n    \u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Working with Package\n\nA class for working with data packages. It provides various capabilities like loading local or remote data package, inferring a data package descriptor, saving a data package descriptor and many more.\n\nConsider we have some local csv files in a `data` directory. Let's create a data package based on this data using a `Package` class:\n\n\u003e data/cities.csv\n\n```csv\ncity,location\nlondon,\"51.50,-0.11\"\nparis,\"48.85,2.30\"\nrome,\"41.89,12.51\"\n```\n\n\u003e data/population.csv\n\n```csv\ncity,year,population\nlondon,2017,8780000\nparis,2017,2240000\nrome,2017,2860000\n```\n\nFirst we create a blank data package::\n\n```javascript\nconst dataPackage = await Package.load()\n```\n\nNow we're ready to infer a data package descriptor based on data files we have. Because we have two csv files we use glob pattern `**/*.csv`:\n\n```javascript\nawait dataPackage.infer('**/*.csv')\ndataPackage.descriptor\n//{ profile: 'tabular-data-package',\n//  resources:\n//   [ { path: 'data/cities.csv',\n//       profile: 'tabular-data-resource',\n//       encoding: 'utf-8',\n//       name: 'cities',\n//       format: 'csv',\n//       mediatype: 'text/csv',\n//       schema: [Object] },\n//     { path: 'data/population.csv',\n//       profile: 'tabular-data-resource',\n//       encoding: 'utf-8',\n//       name: 'population',\n//       format: 'csv',\n//       mediatype: 'text/csv',\n//       schema: [Object] } ] }\n```\n\nAn `infer` method has found all our files and inspected it to extract useful metadata like profile, encoding, format, Table Schema etc. Let's tweak it a little bit:\n\n```javascript\ndataPackage.descriptor.resources[1].schema.fields[1].type = 'year'\ndataPackage.commit()\ndataPackage.valid // true\n```\n\nBecause our resources are tabular we could read it as a tabular data:\n\n```javascript\nawait dataPackage.getResource('population').read({keyed: true})\n\n//[ { city: 'london', year: 2017, population: 8780000 },\n//  { city: 'paris', year: 2017, population: 2240000 },\n//  { city: 'rome', year: 2017, population: 2860000 } ]\n```\n\nLet's save our descriptor on the disk. After it we could update our `datapackage.json` as we want, make some changes etc:\n\n```javascript\nawait dataPackage.save('datapackage.json')\n```\n\nTo continue the work with the data package we just load it again but this time using local `datapackage.json`:\n\n```javascript\nconst dataPackage = await Package.load('datapackage.json')\n// Continue the work\n```\n\nIt was onle basic introduction to the `Package` class. To learn more let's take a look on `Package` class API reference.\n\n### Working with Resource\n\nA class for working with data resources. You can read or iterate tabular resources using the `iter/read` methods and all resource as bytes using `rowIter/rowRead` methods.\n\nConsider we have some local csv file. It could be inline data or remote link - all supported by `Resource` class (except local files for in-brower usage of course). But say it's `data.csv` for now:\n\n```csv\ncity,location\nlondon,\"51.50,-0.11\"\nparis,\"48.85,2.30\"\nrome,N/A\n```\n\nLet's create and read a resource. We use static `Resource.load` method instantiate a resource. Because resource is tabular we could use `resource.read` method with a `keyed` option to get an array of keyed rows:\n\n```javascript\nconst resource = await Resource.load({path: 'data.csv'})\nresource.tabular // true\nresource.headers // ['city', 'location']\nawait resource.read({keyed: true})\n// [\n//   {city: 'london', location: '51.50,-0.11'},\n//   {city: 'paris', location: '48.85,2.30'},\n//   {city: 'rome', location: 'N/A'},\n// ]\n```\n\nAs we could see our locations are just a strings. But it should be geopoints. Also Rome's location is not available but it's also just a `N/A` string instead of JavaScript `null`. First we have to infer resource metadata:\n\n```javascript\nawait resource.infer()\nresource.descriptor\n//{ path: 'data.csv',\n//  profile: 'tabular-data-resource',\n//  encoding: 'utf-8',\n//  name: 'data',\n//  format: 'csv',\n//  mediatype: 'text/csv',\n// schema: { fields: [ [Object], [Object] ], missingValues: [ '' ] } }\nawait resource.read({keyed: true})\n// Fails with a data validation error\n```\n\nLet's fix not available location. There is a `missingValues` property in Table Schema specification. As a first try we set `missingValues` to `N/A` in `resource.descriptor.schema`. Resource descriptor could be changed in-place but all changes should be commited by `resource.commit()`:\n\n```javascript\nresource.descriptor.schema.missingValues = 'N/A'\nresource.commit()\nresource.valid // false\nresource.errors\n// Error: Descriptor validation error:\n//   Invalid type: string (expected array)\n//    at \"/missingValues\" in descriptor and\n//    at \"/properties/missingValues/type\" in profile\n```\n\nAs a good citiziens we've decided to check out recource descriptor validity. And it's not valid! We should use an array for `missingValues` property. Also don't forget to have an empty string as a missing value:\n\n```javascript\nresource.descriptor.schema['missingValues'] = ['', 'N/A']\nresource.commit()\nresource.valid // true\n```\n\nAll good. It looks like we're ready to read our data again:\n\n```javascript\nawait resource.read({keyed: true})\n// [\n//   {city: 'london', location: [51.50,-0.11]},\n//   {city: 'paris', location: [48.85,2.30]},\n//   {city: 'rome', location: null},\n// ]\n```\n\nNow we see that:\n- locations are arrays with numeric lattide and longitude\n- Rome's location is a native JavaScript `null`\n\nAnd because there are no errors on data reading we could be sure that our data is valid againt our schema. Let's save our resource descriptor:\n\n```javascript\nawait resource.save('dataresource.json')\n```\n\nLet's check newly-crated `dataresource.json`. It contains path to our data file, inferred metadata and our `missingValues` tweak:\n\n```json\n{\n    \"path\": \"data.csv\",\n    \"profile\": \"tabular-data-resource\",\n    \"encoding\": \"utf-8\",\n    \"name\": \"data\",\n    \"format\": \"csv\",\n    \"mediatype\": \"text/csv\",\n    \"schema\": {\n        \"fields\": [\n            {\n                \"name\": \"city\",\n                \"type\": \"string\",\n                \"format\": \"default\"\n            },\n            {\n                \"name\": \"location\",\n                \"type\": \"geopoint\",\n                \"format\": \"default\"\n            }\n        ],\n        \"missingValues\": [\n            \"\",\n            \"N/A\"\n        ]\n    }\n}\n```\n\nIf we decide to improve it even more we could update the `dataresource.json` file and then open it again. But this time let's read our resoure as a byte stream:\n\n```javascript\nconst resource = await Resource.load('dataresource.json')\nconst stream = await resource.rawIter({stream: true})\nstream.on('data', (data) =\u003e {\n  // handle data chunk as a Buffer\n})\n```\n\nIt was onle basic introduction to the `Resource` class. To learn more let's take a look on `Resource` class API reference.\n\n### Working with Profile\n\nA component to represent JSON Schema profile from [Profiles Registry]( https://specs.frictionlessdata.io/schemas/registry.json):\n\n```javascript\nawait profile = Profile.load('data-package')\n\nprofile.name // data-package\nprofile.jsonschema // JSON Schema contents\n\nconst {valid, errors} = profile.validate(descriptor)\nfor (const error of errors) {\n  // inspect Error objects\n}\n```\n\n### Working with validate/infer\n\nA standalone function to validate a data package descriptor:\n\n```javascript\nconst {valid, errors} = await validate({name: 'Invalid Datapackage'})\nfor (const error of errors) {\n  // inspect Error objects\n}\n```\n\n### Working with Foreign Keys\n\nThe library supports foreign keys described in the [Table Schema](http://specs.frictionlessdata.io/table-schema/#foreign-keys) specification. It means if your data package descriptor use `resources[].schema.foreignKeys` property for some resources a data integrity will be checked on reading operations.\n\nConsider we have a data package:\n\n```javascript\nconst DESCRIPTOR = {\n  'resources': [\n    {\n      'name': 'teams',\n      'data': [\n        ['id', 'name', 'city'],\n        ['1', 'Arsenal', 'London'],\n        ['2', 'Real', 'Madrid'],\n        ['3', 'Bayern', 'Munich'],\n      ],\n      'schema': {\n        'fields': [\n          {'name': 'id', 'type': 'integer'},\n          {'name': 'name', 'type': 'string'},\n          {'name': 'city', 'type': 'string'},\n        ],\n        'foreignKeys': [\n          {\n            'fields': 'city',\n            'reference': {'resource': 'cities', 'fields': 'name'},\n          },\n        ],\n      },\n    }, {\n      'name': 'cities',\n      'data': [\n        ['name', 'country'],\n        ['London', 'England'],\n        ['Madrid', 'Spain'],\n      ],\n    },\n  ],\n}\n```\n\nLet's check relations for a `teams` resource:\n\n```javascript\nconst {Package} = require('datapackage')\n\nconst package = await Package.load(DESCRIPTOR)\nteams = package.getResource('teams')\nawait teams.checkRelations()\n// tableschema.exceptions.RelationError: Foreign key \"['city']\" violation in row \"4\"\n```\n\nAs we could see there is a foreign key violation. That's because our lookup table `cities` doesn't have a city of `Munich` but we have a team from there. We need to fix it in `cities` resource:\n\n```javascript\npackage.descriptor['resources'][1]['data'].push(['Munich', 'Germany'])\npackage.commit()\nteams = package.getResource('teams')\nawait teams.checkRelations()\n// True\n```\n\nFixed! But not only a check operation is available. We could use `relations` argument for `resource.iter/read` methods to dereference a resource relations:\n\n```javascript\nawait teams.read({keyed: true, relations: true})\n//[{'id': 1, 'name': 'Arsenal', 'city': {'name': 'London', 'country': 'England}},\n// {'id': 2, 'name': 'Real', 'city': {'name': 'Madrid', 'country': 'Spain}},\n// {'id': 3, 'name': 'Bayern', 'city': {'name': 'Munich', 'country': 'Germany}}]\n```\n\nInstead of plain city name we've got a dictionary containing a city data. These `resource.iter/read` methods will fail with the same as `resource.check_relations` error if there is an integrity issue. But only if `relations: true` flag is passed.\nA standalone function to infer a data package descriptor.\n\n```javascript\nconst descriptor = await infer('**/*.csv')\n//{ profile: 'tabular-data-resource',\n//  resources:\n//   [ { path: 'data/cities.csv',\n//       profile: 'tabular-data-resource',\n//       encoding: 'utf-8',\n//       name: 'cities',\n//       format: 'csv',\n//       mediatype: 'text/csv',\n//       schema: [Object] },\n//     { path: 'data/population.csv',\n//       profile: 'tabular-data-resource',\n//       encoding: 'utf-8',\n//       name: 'population',\n//       format: 'csv',\n//       mediatype: 'text/csv',\n//       schema: [Object] } ] }\n```\n\n## API Referencer\n\n### Package\nPackage representation\n\n\n* [Package](#Package)\n    * _instance_\n        * [.valid](#Package+valid) ⇒ `Boolean`\n        * [.errors](#Package+errors) ⇒ `Array.\u0026lt;Error\u0026gt;`\n        * [.profile](#Package+profile) ⇒ `Profile`\n        * [.descriptor](#Package+descriptor) ⇒ `Object`\n        * [.resources](#Package+resources) ⇒ `Array.\u0026lt;Resoruce\u0026gt;`\n        * [.resourceNames](#Package+resourceNames) ⇒ `Array.\u0026lt;string\u0026gt;`\n        * [.getResource(name)](#Package+getResource) ⇒ `Resource` \\| `null`\n        * [.addResource(descriptor)](#Package+addResource) ⇒ `Resource`\n        * [.removeResource(name)](#Package+removeResource) ⇒ `Resource` \\| `null`\n        * [.infer(pattern)](#Package+infer) ⇒ `Object`\n        * [.commit(strict)](#Package+commit) ⇒ `Boolean`\n        * [.save(target, raises, returns)](#Package+save)\n    * _static_\n        * [.load(descriptor, basePath, strict)](#Package.load) ⇒ [`Package`](#Package)\n\n\n#### package.valid ⇒ `Boolean`\nValidation status\n\nIt always `true` in strict mode.\n\n**Returns**: `Boolean` - returns validation status\n\n#### package.errors ⇒ `Array.\u0026lt;Error\u0026gt;`\nValidation errors\n\nIt always empty in strict mode.\n\n**Returns**: `Array.\u0026lt;Error\u0026gt;` - returns validation errors\n\n#### package.profile ⇒ `Profile`\nProfile\n\n\n#### package.descriptor ⇒ `Object`\nDescriptor\n\n**Returns**: `Object` - schema descriptor\n\n#### package.resources ⇒ `Array.\u0026lt;Resoruce\u0026gt;`\nResources\n\n\n#### package.resourceNames ⇒ `Array.\u0026lt;string\u0026gt;`\nResource names\n\n\n#### package.getResource(name) ⇒ `Resource` \\| `null`\nReturn a resource\n\n**Returns**: `Resource` \\| `null` - resource instance if exists\n\n| Param | Type |\n| --- | --- |\n| name | `string` |\n\n\n#### package.addResource(descriptor) ⇒ `Resource`\nAdd a resource\n\n**Returns**: `Resource` - added resource instance\n\n| Param | Type |\n| --- | --- |\n| descriptor | `Object` |\n\n\n#### package.removeResource(name) ⇒ `Resource` \\| `null`\nRemove a resource\n\n**Returns**: `Resource` \\| `null` - removed resource instance if exists\n\n| Param | Type |\n| --- | --- |\n| name | `string` |\n\n\n#### package.infer(pattern) ⇒ `Object`\nInfer metadata\n\n\n| Param | Type | Default |\n| --- | --- | --- |\n| pattern | `string` | `false` |\n\n\n#### package.commit(strict) ⇒ `Boolean`\nUpdate package instance if there are in-place changes in the descriptor.\n\n**Returns**: `Boolean` - returns true on success and false if not modified\n**Throws**:\n\n- `DataPackageError` raises any error occurred in the process\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| strict | `boolean` | alter `strict` mode for further work |\n\n**Example**\n```javascript\nconst dataPackage = await Package.load({\n    name: 'package',\n    resources: [{name: 'resource', data: ['data']}]\n})\n\ndataPackage.name // package\ndataPackage.descriptor.name = 'renamed-package'\ndataPackage.name // package\ndataPackage.commit()\ndataPackage.name // renamed-package\n```\n\n#### package.save(target, raises, returns)\nSave data package to target destination.\n\nIf target path has a  zip file extension the package will be zipped and\nsaved entirely. If it has a json file extension only the descriptor will be saved.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| target | `string` | path where to save a data package |\n| raises | `DataPackageError` | error if something goes wrong |\n| returns | `boolean` | true on success |\n\n\n#### Package.load(descriptor, basePath, strict) ⇒ [`Package`](#Package)\nFactory method to instantiate `Package` class.\n\nThis method is async and it should be used with await keyword or as a `Promise`.\n\n**Returns**: [`Package`](#Package) - returns data package class instance\n**Throws**:\n\n- `DataPackageError` raises error if something goes wrong\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| descriptor | `string` \\| `Object` | package descriptor as local path, url or object.   If ththe path has a `zip` file extension it will be unzipped   to the temp directory first. |\n| basePath | `string` | base path for all relative paths |\n| strict | `boolean` | strict flag to alter validation behavior.   Setting it to `true` leads to throwing errors on any operation   with invalid descriptor |\n\n\n### Resource\nResource representation\n\n\n* [Resource](#Resource)\n    * _instance_\n        * [.valid](#Resource+valid) ⇒ `Boolean`\n        * [.errors](#Resource+errors) ⇒ `Array.\u0026lt;Error\u0026gt;`\n        * [.profile](#Resource+profile) ⇒ `Profile`\n        * [.descriptor](#Resource+descriptor) ⇒ `Object`\n        * [.name](#Resource+name) ⇒ `string`\n        * [.inline](#Resource+inline) ⇒ `boolean`\n        * [.local](#Resource+local) ⇒ `boolean`\n        * [.remote](#Resource+remote) ⇒ `boolean`\n        * [.multipart](#Resource+multipart) ⇒ `boolean`\n        * [.tabular](#Resource+tabular) ⇒ `boolean`\n        * [.source](#Resource+source) ⇒ `Array` \\| `string`\n        * [.headers](#Resource+headers) ⇒ `Array.\u0026lt;string\u0026gt;`\n        * [.schema](#Resource+schema) ⇒ `tableschema.Schema`\n        * [.iter(keyed, extended, cast, forceCast, relations, stream)](#Resource+iter) ⇒ `AsyncIterator` \\| `Stream`\n        * [.read(limit)](#Resource+read) ⇒ `Array.\u0026lt;Array\u0026gt;` \\| `Array.\u0026lt;Object\u0026gt;`\n        * [.checkRelations()](#Resource+checkRelations) ⇒ `boolean`\n        * [.rawIter(stream)](#Resource+rawIter) ⇒ `Iterator` \\| `Stream`\n        * [.rawRead()](#Resource+rawRead) ⇒ `Buffer`\n        * [.infer()](#Resource+infer) ⇒ `Object`\n        * [.commit(strict)](#Resource+commit) ⇒ `boolean`\n        * [.save(target)](#Resource+save) ⇒ `boolean`\n    * _static_\n        * [.load(descriptor, basePath, strict)](#Resource.load) ⇒ [`Resource`](#Resource)\n\n\n#### resource.valid ⇒ `Boolean`\nValidation status\n\nIt always `true` in strict mode.\n\n**Returns**: `Boolean` - returns validation status\n\n#### resource.errors ⇒ `Array.\u0026lt;Error\u0026gt;`\nValidation errors\n\nIt always empty in strict mode.\n\n**Returns**: `Array.\u0026lt;Error\u0026gt;` - returns validation errors\n\n#### resource.profile ⇒ `Profile`\nProfile\n\n\n#### resource.descriptor ⇒ `Object`\nDescriptor\n\n**Returns**: `Object` - schema descriptor\n\n#### resource.name ⇒ `string`\nName\n\n\n#### resource.inline ⇒ `boolean`\nWhether resource is inline\n\n\n#### resource.local ⇒ `boolean`\nWhether resource is local\n\n\n#### resource.remote ⇒ `boolean`\nWhether resource is remote\n\n\n#### resource.multipart ⇒ `boolean`\nWhether resource is multipart\n\n\n#### resource.tabular ⇒ `boolean`\nWhether resource is tabular\n\n\n#### resource.source ⇒ `Array` \\| `string`\nSource\n\nCombination of `resource.source` and `resource.inline/local/remote/multipart`\nprovides predictable interface to work with resource data.\n\n\n#### resource.headers ⇒ `Array.\u0026lt;string\u0026gt;`\nHeaders\n\n\u003e Only for tabular resources\n\n**Returns**: `Array.\u0026lt;string\u0026gt;` - data source headers\n\n#### resource.schema ⇒ `tableschema.Schema`\nSchema\n\n\u003e Only for tabular resources\n\n\n#### resource.iter(keyed, extended, cast, forceCast, relations, stream) ⇒ `AsyncIterator` \\| `Stream`\nIterate through the table data\n\n\u003e Only for tabular resources\n\nAnd emits rows cast based on table schema (async for loop).\nWith a `stream` flag instead of async iterator a Node stream will be returned.\nData casting can be disabled.\n\n**Returns**: `AsyncIterator` \\| `Stream` - async iterator/stream of rows:\n - `[value1, value2]` - base\n - `{header1: value1, header2: value2}` - keyed\n - `[rowNumber, [header1, header2], [value1, value2]]` - extended\n**Throws**:\n\n- `TableSchemaError` raises any error occurred in this process\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| keyed | `boolean` | iter keyed rows |\n| extended | `boolean` | iter extended rows |\n| cast | `boolean` | disable data casting if false |\n| forceCast | `boolean` | instead of raising on the first row with cast error   return an error object to replace failed row. It will allow   to iterate over the whole data file even if it's not compliant to the schema.   Example of output stream:     `[['val1', 'val2'], TableSchemaError, ['val3', 'val4'], ...]` |\n| relations | `boolean` | if true foreign key fields will be   checked and resolved to its references |\n| stream | `boolean` | return Node Readable Stream of table rows |\n\n\n#### resource.read(limit) ⇒ `Array.\u0026lt;Array\u0026gt;` \\| `Array.\u0026lt;Object\u0026gt;`\nRead the table data into memory\n\n\u003e Only for tabular resources; the API is the same as `resource.iter` has except for:\n\n**Returns**: `Array.\u0026lt;Array\u0026gt;` \\| `Array.\u0026lt;Object\u0026gt;` - list of rows:\n - `[value1, value2]` - base\n - `{header1: value1, header2: value2}` - keyed\n - `[rowNumber, [header1, header2], [value1, value2]]` - extended\n\n| Param | Type | Description |\n| --- | --- | --- |\n| limit | `integer` | limit of rows to read |\n\n\n#### resource.checkRelations() ⇒ `boolean`\nIt checks foreign keys and raises an exception if there are integrity issues.\n\n\u003e Only for tabular resources\n\n**Returns**: `boolean` - returns True if no issues\n**Throws**:\n\n- `DataPackageError` raises if there are integrity issues\n\n\n#### resource.rawIter(stream) ⇒ `Iterator` \\| `Stream`\nIterate over data chunks as bytes. If `stream` is true Node Stream will be returned.\n\n**Returns**: `Iterator` \\| `Stream` - returns Iterator/Stream\n\n| Param | Type | Description |\n| --- | --- | --- |\n| stream | `boolean` | Node Stream will be returned |\n\n\n#### resource.rawRead() ⇒ `Buffer`\nReturns resource data as bytes.\n\n**Returns**: `Buffer` - returns Buffer with resource data\n\n#### resource.infer() ⇒ `Object`\nInfer resource metadata like name, format, mediatype, encoding, schema and profile.\n\nIt commits this changes into resource instance.\n\n**Returns**: `Object` - returns resource descriptor\n\n#### resource.commit(strict) ⇒ `boolean`\nUpdate resource instance if there are in-place changes in the descriptor.\n\n**Returns**: `boolean` - returns true on success and false if not modified\n**Throws**:\n\n- DataPackageError raises error if something goes wrong\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| strict | `boolean` | alter `strict` mode for further work |\n\n\n#### resource.save(target) ⇒ `boolean`\nSave resource to target destination.\n\n\u003e For now only descriptor will be saved.\n\n**Returns**: `boolean` - returns true on success\n**Throws**:\n\n- `DataPackageError` raises error if something goes wrong\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| target | `string` | path where to save a resource |\n\n\n#### Resource.load(descriptor, basePath, strict) ⇒ [`Resource`](#Resource)\nFactory method to instantiate `Resource` class.\n\nThis method is async and it should be used with await keyword or as a `Promise`.\n\n**Returns**: [`Resource`](#Resource) - returns resource class instance\n**Throws**:\n\n- `DataPackageError` raises error if something goes wrong\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| descriptor | `string` \\| `Object` | resource descriptor as local path, url or object |\n| basePath | `string` | base path for all relative paths |\n| strict | `boolean` | strict flag to alter validation behavior.   Setting it to `true` leads to throwing errors on   any operation with invalid descriptor |\n\n\n### Profile\nProfile representation\n\n\n* [Profile](#Profile)\n    * _instance_\n        * [.name](#Profile+name) ⇒ `string`\n        * [.jsonschema](#Profile+jsonschema) ⇒ `Object`\n        * [.validate(descriptor)](#Profile+validate) ⇒ `Object`\n    * _static_\n        * [.load(profile)](#Profile.load) ⇒ [`Profile`](#Profile)\n\n\n#### profile.name ⇒ `string`\nName\n\n\n#### profile.jsonschema ⇒ `Object`\nJsonSchema\n\n\n#### profile.validate(descriptor) ⇒ `Object`\nValidate a data package `descriptor` against the profile.\n\n**Returns**: `Object` - returns a `{valid, errors}` object\n\n| Param | Type | Description |\n| --- | --- | --- |\n| descriptor | `Object` | retrieved and dereferenced data package descriptor |\n\n\n#### Profile.load(profile) ⇒ [`Profile`](#Profile)\nFactory method to instantiate `Profile` class.\n\nThis method is async and it should be used with await keyword or as a `Promise`.\n\n**Returns**: [`Profile`](#Profile) - returns profile class instance\n**Throws**:\n\n- `DataPackageError` raises error if something goes wrong\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| profile | `string` | profile name in registry or URL to JSON Schema |\n\n\n### validate(descriptor) ⇒ `Object`\nThis function is async so it has to be used with `await` keyword or as a `Promise`.\n\n**Returns**: `Object` - returns a `{valid, errors}` object\n\n| Param | Type | Description |\n| --- | --- | --- |\n| descriptor | `string` \\| `Object` | data package descriptor (local/remote path or object) |\n\n\n### infer(pattern) ⇒ `Object`\nThis function is async so it has to be used with `await` keyword or as a `Promise`.\n\n**Returns**: `Object` - returns data package descriptor\n\n| Param | Type | Description |\n| --- | --- | --- |\n| pattern | `string` | glob file pattern |\n\n\n### DataPackageError\nBase class for the all DataPackage errors.\n\n\n### TableSchemaError\nBase class for the all TableSchema errors.\n\n\n## Contributing\n\n\u003e The project follows the [Open Knowledge International coding standards](https://github.com/okfn/coding-standards). There are common commands to work with the project:\n\n```\n$ npm install\n$ npm run test\n$ npm run build\n```\n\n## Changelog\n\nHere described only breaking and the most important changes. The full changelog and documentation for all released versions could be found in nicely formatted [commit history](https://github.com/frictionlessdata/datapackage-js/commits/master).\n\n#### v1.1\n\nUpdated behaviour:\n\n- Resource's `escapeChar` and `quoteChar` are mutually exclusive now\n\nNew API added:\n\n- Added support of `zip` files for data packages\n- Added support of `format/encoding/dialect` for resources\n\n#### v1.0\n\nThis version includes various big changes. A migration guide is under development and will be published here.\n\n#### v0.8\n\nFirst stable version of the library.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrictionlessdata%2Fdatapackage-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrictionlessdata%2Fdatapackage-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrictionlessdata%2Fdatapackage-js/lists"}