Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .babelrc

This file was deleted.

5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ jobs:
uses: Brightspace/setup-node@main
with:
node-version-file: .nvmrc
cache: 'npm'
- name: Install dependencies
run: npm ci --ignore-scripts
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now set in the .npmrc file.

- name: Build
run: npm run build
run: npm ci
- name: Semantic Release
uses: BrightspaceUI/actions/semantic-release@main
with:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ jobs:
uses: Brightspace/setup-node@main
with:
node-version-file: .nvmrc
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run test
- name: Build
run: npm run build
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
node_modules
coverage
dist
.nyc_output
*.log
*.swo
*.swp
56 changes: 6 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,16 @@ npm install siren-parser

## Usage

There are three ways to use `siren-parser`'s functionality.

1. In Node.js, `require` it as you would any other NPM package:
```javascript
const SirenParse = require('siren-parser').default;
var parsedEntity = SirenParse('{"class":["foo","bar"]}');
```

2. An ES6 module is available as well for import:
```javascript
import SirenParse from 'siren-parser';
var parsedEntity = SirenParse('{"class":["foo","bar"]}');
```
You can also import `Action`, `Entity`, and `Link` by name if you need to add custom functionality to parsed entities.
```javascript
import SirenParse, { Action, Entity, Link } from 'siren-parser';
Entity.prototype.printEntity = function() { console.log(this) };
var parsedEntity = SirenParse('{"class":["foo","bar"]}'); // parsedEntity will have printEntity()
```

3. An ES6 module installed on the window as a global:
```html
<script type="module" src="siren-parser/global.js"></script>
<script>
var parsedEntity = D2L.Hypermedia.Siren.Parse('{"class":["foo","bar"]}');
</script>
```
Note that this is a `deumdify`'d browser bundle, which should prevent collisions with other modules on the page that are exposed by browserify's standalone UMD bundle.
```javascript
import SirenParse from 'siren-parser';
var parsedEntity = SirenParse('{"class":["foo","bar"]}');
```

## API

```js
const sirenParser = require('siren-parser');
const sirenParserChai = require('siren-parser/chai');
const sirenSuperagent = require('siren-parser/superagent');
import sirenParser from 'siren-parser';
import sirenChai from 'siren-parser/src/chaiPlugin.js';
const sirenJson = {
title: 'My title',
class: ['outer'],
Expand Down Expand Up @@ -86,18 +61,6 @@ const resource = sirenParser(sirenJson);

// ... assuming you've got all your chai stuff set up
expect(resource).to.have.sirenAction('fancy-action');

const request = require('superagent');
sirenSuperagent.perform(request, resource.getAction('fancy-action'))
.submit({key: 'value'}) // overrides default field(s) specified in action
.parse(sirenSuperagent.parse)
.end(function(err, res) {
const resource = res.body; // parsed siren resource
expect(resource).to.have.sirenProperty('some-field');
});

// Alternatively, add the parser to the global superagent parser
request.parse['application/vnd.siren+json'] = sirenSuperagent.parse;
```

## API
Expand Down Expand Up @@ -338,13 +301,6 @@ expect(resource).to.have.sirenLinks.all.with.classes('foo', 'bar'); // Passes on
expect(resource).to.have.a.sirenEntity.with.a.sirenEntity.with.title('foo'); // Check a sub-sub-entity's title
```

## `superagent` interface

There are two helper `superagent` methods included with this module, under `./superagent`.

* `.parse(sirenSuperagent.parse)` - To be used with `superagent`'s `.parse()` method
* `sirenSuperagent.perform(request, action)` - Returns unended `superagent` request object

## Testing

```js
Expand Down
5 changes: 0 additions & 5 deletions global.js

This file was deleted.

Loading