Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/krmax44/normalize-repo
Normalizes the repository value of package.json.
https://github.com/krmax44/normalize-repo
package-json
Last synced: about 2 months ago
JSON representation
Normalizes the repository value of package.json.
- Host: GitHub
- URL: https://github.com/krmax44/normalize-repo
- Owner: krmax44
- License: mit
- Created: 2019-08-08T16:26:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-02-12T11:37:18.000Z (almost 3 years ago)
- Last Synced: 2024-04-14T02:21:54.308Z (9 months ago)
- Topics: package-json
- Language: TypeScript
- Homepage:
- Size: 1.92 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Normalize Repo
[![Build Status](https://travis-ci.com/krmax44/normalize-repo.svg?branch=master)](https://travis-ci.com/krmax44/normalize-repo)
![npm bundle size](https://img.shields.io/bundlephobia/min/normalize-repo?label=size)
![npm version](https://img.shields.io/npm/v/normalize-repo)Normalizes the `repository` object or string you typically find in `package.json`. It adheres to the [specification](https://docs.npmjs.com/files/package.json#repository) and can parse everything you can also use as a value for `repository`.
## Installation
```bash
yarn add normalize-repo
```## Examples
All values that `repository`
```js
const normalizeRepo = require('normalize-repo');normalizeRepo('github:krmax44/normalize-repo')
// output:
{
url: 'https://github.com/krmax44/normalize-repo.git',
shortcut: 'github:krmax44/normalize-repo',
provider: 'github',
owner: 'krmax44',
name: 'normalize-repo'
}
```You can also pass an object:
```js
normalizeRepo({ url: 'https://github.com/krmax44/normalize-repo.git' });
```A malformatted and incompliant input will throw an error:
```js
try {
// will throw an error, as only shortcut strings are allowed
normalizeRepo('https://github.com/krmax44/normalize-repo.git');
} catch (error) {
console.log(error);
}
```**Note**: Only Github, Gitlab, Github Gist and Bitbucket repositories will return `shortcut`, `provider`, `owner` and `name` values.