# @har-sdk/core

> The base package can be used to import specification files (i.e. HAR, OAS and Postman Collection) and detect their type.

Latest version **1.5.0** (published 2025-03-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @har-sdk/core
pnpm add @har-sdk/core
yarn add @har-sdk/core
bun add @har-sdk/core
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.5.0 |
| Published | 2025-03-25 |
| First published | 2021-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 106.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Artem Derevnjuk |
| Maintainers | derevnjuk, pmstss |
| Keywords | postman, oas, openapi, swagger, har, api |

## Links

- npm: https://www.npmjs.com/package/@har-sdk/core
- Repository: https://github.com/NeuraLegion/har-sdk
- Homepage: https://github.com/NeuraLegion/har-sdk/tree/master/packages/core#readme
- Issues: https://github.com/NeuraLegion/har-sdk/issues
- npm.io page: https://npm.io/package/@har-sdk/core

## Dependencies (3)

- [tslib](https://npm.io/package/tslib.md) ^2.3.1
- [js-yaml](https://npm.io/package/js-yaml.md) ^4.1.0
- [openapi-types](https://npm.io/package/openapi-types.md) ^10.0.0

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 1.5.0 (latest) — 2025-03-25
- 1.4.5 — 2023-02-23
- 1.4.4 — 2022-07-12
- 1.4.3 — 2022-04-08
- 1.4.2 — 2022-02-15
- 1.4.1 — 2022-02-07
- 1.4.0 — 2022-01-31
- 1.3.0 — 2022-01-25
- 1.2.0 — 2022-01-13
- 1.1.0 — 2022-01-12
- 1.0.0 — 2021-11-17

## README

# @har-sdk/core

The base package can be used to import specification files (i.e. HAR, OAS and Postman Collection) and detect their type.

## Setup

```bash
npm i --save @har-sdk/core
```

## Usage

To import a specification you just need to create an instance of `SpecImporter` and call its `import` method passing the data file. The importer performs syntactic analysis and parses a provided file.

```ts
import { SpecImporter } from '@har-sdk/core';

const result = await new SpecImporter().import(sourceAsString);
console.log(result);
// {
//   type: 'postman',
//   format: 'json',
//   doc: {
//     info: {
//       name: 'Postman Sample',
//       schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
//     },
//     item: [
//       // ...
//     ]
//   },
//   name: 'Postman Sample.json'
// }
```

To configure the list of importers, you can pass them as an array to the constructor.

```ts
import { SpecImporter, HarImporter } from '@har-sdk/core';

const explorer = new SpecImporter([new HarImporter()]);
```

To extend an explorer by adding a new custom importer, you can easily implement an `Importer` interface.

```ts
import { Importer, Doc, Spec, Importer } from '@har-sdk/core';

class RamlImporter implements Importer<'raml'> {
  get type(): 'raml' {
    return 'raml';
  }

  async import(content: string): Promise<Spec<'raml'>> {
    // your code

    return {
      // other fields
      type: this.type,
      format: 'yaml'
    };
  }
}
```

The package also contains a set of useful utilities like `normalizeUrl`:

```ts
import { normalizeUrl } from '@har-sdk/core';

normalizeUrl('HTTP://example.COM////foo////dummy/../bar/?'); // http://example.com/foo/bar
```

---
_Source: https://npm.io/package/@har-sdk/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
