Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

siren-parser

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

siren-parser - npm Package Compare versions

Comparing version 7.1.0 to 8.0.0

.babelrc

94

package.json
{
"name": "siren-parser",
"version": "7.1.0",
"version": "8.0.0",
"description": "Pretty much the opposite of dominicbarnes/node-siren-writer",
"main": "src/Entity.js",
"main": "dist/index.js",
"module": "src/index.js",
"scripts": {
"prebrowserify": "rimraf dist && mkdir dist",
"browserify": "browserify -g uglifyify -p deumdify -s 'D2L.Hypermedia.Siren.Parse' src/Entity.js > ./dist/siren-parser.js",
"lint": "eslint --ignore-path .gitignore .",
"test": "npm run lint && npm run test-no-style",
"test-no-style": "cross-env NODE_ENV=test istanbul cover --source-map --dir ./coverage/unit --root src/ node_modules/mocha/bin/_mocha -- --recursive ./test",
"posttest": "istanbul report text-summary lcov",
"report-cov": "istanbul report lcovonly && coveralls < ./coverage/lcov.info",
"publish:cdn": "frau-publisher"
"build": "babel src --out-dir ./dist --source-maps --plugins=add-module-exports",
"lint": "eslint src test --ext .js",
"test": "npm run lint && npm run test:unit",
"test:unit": "cross-env NODE_ENV=test nyc mocha",
"report-cov": "istanbul report lcovonly && coveralls < ./coverage/lcov.info"
},
"config": {
"frauPublisher": {
"files": "./dist/*.js",
"moduleType": "lib",
"targetDirectory": "siren-parser",
"creds": {
"key": "AKIAIX7THWM4IO4CULRA",
"secretVar": "CDN_SECRET"
},
"versionVar": "TRAVIS_TAG"
}
},
"author": "D2L Corporation",

@@ -39,41 +25,31 @@ "license": "Apache-2.0",

"devDependencies": {
"babel-preset-latest": "^6.24.0",
"babelify": "^7.3.0",
"browserify": "^14.1.0",
"chai": "^3.3.0",
"coveralls": "^2.11.4",
"cross-env": "^5.0.5",
"deumdify": "^1.2.4",
"eslint": "^3.18.0",
"eslint-config-brightspace": "0.2.4",
"frau-publisher": "^2.6.2",
"istanbul": "0.4.5",
"mocha": "^3.2.0",
"nock": "^9.0.10",
"peanut-gallery": "^1.1.1",
"rimraf": "^2.6.1",
"sinon": "^2.1.0",
"sinon-chai": "^2.8.0",
"supertest": "^3.0.0",
"uglifyify": "^3.0.4"
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/node": "^7.0.0",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"babel-plugin-add-module-exports": "^1.0.0",
"babel-plugin-istanbul": "^5.1.0",
"chai": "^4.2.0",
"cross-env": "^5.2.0",
"eslint": "^5.8.0",
"eslint-config-brightspace": "^0.4.1",
"mocha": "^5.2.0",
"nock": "^10.0.2",
"nyc": "^13.1.0",
"sinon": "^7.1.1",
"sinon-chai": "^3.2.0",
"supertest": "^3.3.0"
},
"eslintConfig": {
"extends": "brightspace",
"env": {
"es6": true,
"node": true
}
},
"browserify": {
"transform": [
[
"babelify",
{
"presets": [
"latest"
]
}
]
]
"nyc": {
"require": [
"@babel/register"
],
"reporter": [
"lcov",
"text"
],
"sourceMap": false,
"instrument": false
}
}

@@ -7,20 +7,30 @@ # node-siren-parser

## Installation
Install from NPM:
```shell
npm install siren-parser
```
## Usage
There are three ways to use `node-siren-parser`'s functionality.
There are three ways to use `siren-parser`'s functionality.
1. You can install it from npm using
```bash
npm install siren-parser
1. In Node.js, `require` it as you would any other NPM package:
```javascript
const SirenParse = require('siren-parser');
var parsedEntity = SirenParse('{"class":["foo","bar"]}');
```
and then `require` it as you would any other npm package.
2. An HTML import version of the parser is available via [`siren-parser-import`](https://github.com/Brightspace/siren-parser-import) (recommended approach for client-side usage).
2. An ES6 module is available as well for import:
```javascript
import SirenParse from 'siren-parser';
var parsedEntity = SirenParse('{"class":["foo","bar"]}');
```
3. Alternatively, the parser is browserified and stored on the Brightspace CDN for client-side usage
3. An ES6 module installed on the window as a global:
```html
<script src="https://s.brightspace.com/lib/siren-parser/{version}/siren-parser.js"></script>
<script type="module" src="siren-parser/global.js"></script>
<script>
var parsedEntity = window.D2L.Hypermedia.Siren.Parse('{"class":["foo","bar"]}');
var parsedEntity = D2L.Hypermedia.Siren.Parse('{"class":["foo","bar"]}');
</script>

@@ -27,0 +37,0 @@ ```

@@ -1,9 +0,6 @@

'use strict';
import assert from './assert';
import {contains, getMatchingValue, getMatchingValuesByAll, hasProperty} from './util.js';
import Field from './Field';
const
assert = require('./assert'),
Field = require('./Field'),
util = require('./util');
function Action(action) {
export default function Action(action) {
if (action instanceof Action) {

@@ -85,3 +82,3 @@ return action;

Action.prototype.hasClass = function(cls) {
return this.class instanceof Array && util.contains(this.class, cls);
return this.class instanceof Array && contains(this.class, cls);
};

@@ -94,11 +91,11 @@

Action.prototype.hasFieldByName = function(fieldName) {
return util.hasProperty(this._fieldsByName, fieldName);
return hasProperty(this._fieldsByName, fieldName);
};
Action.prototype.hasFieldByClass = function(fieldClass) {
return util.hasProperty(this._fieldsByClass, fieldClass);
return hasProperty(this._fieldsByClass, fieldClass);
};
Action.prototype.hasFieldByType = function(fieldType) {
return util.hasProperty(this._fieldsByType, fieldType);
return hasProperty(this._fieldsByType, fieldType);
};

@@ -111,7 +108,7 @@

Action.prototype.getFieldByName = function(fieldName) {
return util.getMatchingValue(this._fieldsByName, fieldName);
return getMatchingValue(this._fieldsByName, fieldName);
};
Action.prototype.getFieldByClass = function(fieldClass) {
const vals = util.getMatchingValue(this._fieldsByClass, fieldClass);
const vals = getMatchingValue(this._fieldsByClass, fieldClass);
return vals ? vals[0] : undefined;

@@ -121,3 +118,3 @@ };

Action.prototype.getFieldsByClass = function(fieldClass) {
const vals = util.getMatchingValue(this._fieldsByClass, fieldClass);
const vals = getMatchingValue(this._fieldsByClass, fieldClass);
return vals ? vals.slice() : [];

@@ -127,3 +124,3 @@ };

Action.prototype.getFieldByClasses = function(fieldClasses) {
const vals = util.getMatchingValuesByAll(this.fields, fieldClasses, 'class');
const vals = getMatchingValuesByAll(this.fields, fieldClasses, 'class');
return vals && vals.length > 0 ? vals[0] : undefined;

@@ -133,3 +130,3 @@ };

Action.prototype.getFieldsByClasses = function(fieldClasses) {
const vals = util.getMatchingValuesByAll(this.fields, fieldClasses, 'class');
const vals = getMatchingValuesByAll(this.fields, fieldClasses, 'class');
return vals && vals.length > 0 ? vals.slice() : [];

@@ -139,3 +136,3 @@ };

Action.prototype.getFieldByType = function(fieldType) {
const vals = util.getMatchingValue(this._fieldsByType, fieldType);
const vals = getMatchingValue(this._fieldsByType, fieldType);
return vals ? vals[0] : undefined;

@@ -145,6 +142,4 @@ };

Action.prototype.getFieldsByType = function(fieldType) {
const vals = util.getMatchingValue(this._fieldsByType, fieldType);
const vals = getMatchingValue(this._fieldsByType, fieldType);
return vals ? vals.slice() : [];
};
module.exports = Action;

@@ -1,7 +0,5 @@

'use strict';
module.exports = function(expectation, msg) {
export default function(expectation, msg) {
if (!expectation) {
throw new Error(msg);
}
};
}

@@ -1,10 +0,7 @@

'use strict';
import Action from './Action';
import Entity from './index';
import Field from './Field';
import Link from './Link';
const
Action = require('./Action'),
Entity = require('./Entity'),
Field = require('./Field'),
Link = require('./Link');
module.exports = function(chai, utils) {
export default function(chai, utils) {
const Assertion = chai.Assertion;

@@ -138,2 +135,2 @@

objectProperty('sirenProperties', 'properties', Entity);
};
}

@@ -1,7 +0,4 @@

'use strict';
import assert from './assert';
import {contains} from './util';
const
assert = require('./assert'),
util = require('./util');
const VALID_TYPES = [

@@ -29,3 +26,3 @@ 'hidden',

function Field(field) {
export default function Field(field) {
if (field instanceof Field) {

@@ -42,4 +39,3 @@ return field;

'field.class must be an array or undefined, got ' + JSON.stringify(field.class));
assert('undefined' === typeof field.type
|| ('string' === typeof field.type && VALID_TYPES.indexOf(field.type.toLowerCase()) > -1),
assert('undefined' === typeof field.type || ('string' === typeof field.type && VALID_TYPES.indexOf(field.type.toLowerCase()) > -1),
'field.type must be a valid field type string or undefined, got ' + JSON.stringify(field.type));

@@ -79,5 +75,3 @@ assert('undefined' === typeof field.title || 'string' === typeof field.title,

Field.prototype.hasClass = function(cls) {
return this.class instanceof Array && util.contains(this.class, cls);
return this.class instanceof Array && contains(this.class, cls);
};
module.exports = Field;

@@ -1,8 +0,5 @@

'use strict';
import assert from './assert';
import {contains} from './util';
const
assert = require('./assert'),
util = require('./util');
function Link(link) {
export default function Link(link) {
if (link instanceof Link) {

@@ -52,5 +49,3 @@ return link;

Link.prototype.hasClass = function(cls) {
return this.class instanceof Array && util.contains(this.class, cls);
return this.class instanceof Array && contains(this.class, cls);
};
module.exports = Link;

@@ -1,9 +0,6 @@

'use strict';
import assert from './assert';
import Action from './Action';
import Entity from './index';
const
assert = require('assert'),
Action = require('./Action'),
Entity = require('./Entity');
function parseSiren(res, fn) {
export function parse(res, fn) {
if ('string' === typeof res) {

@@ -57,3 +54,3 @@ return new Entity(res);

function performAction(request, action) {
export function perform(request, action) {
assert(request);

@@ -66,6 +63,1 @@ assert(action instanceof Action);

}
module.exports = {
parse: parseSiren,
perform: performAction
};

@@ -1,4 +0,2 @@

'use strict';
function contains(arrayLike, stringOrRegex) {
export function contains(arrayLike, stringOrRegex) {
if ('string' === typeof stringOrRegex) {

@@ -15,3 +13,3 @@ return arrayLike.indexOf(stringOrRegex) > -1;

function hasProperty(objectLike, stringOrRegex) {
export function hasProperty(objectLike, stringOrRegex) {
if ('string' === typeof stringOrRegex) {

@@ -24,3 +22,3 @@ return objectLike.hasOwnProperty(stringOrRegex);

function getMatchingValue(objectLike, stringOrRegex) {
export function getMatchingValue(objectLike, stringOrRegex) {
if ('string' === typeof stringOrRegex) {

@@ -40,3 +38,3 @@ return objectLike[stringOrRegex];

function getMatchingValuesByAll(arrayLike, arrayOfStringOrRegex, propertyToMatch) {
export function getMatchingValuesByAll(arrayLike, arrayOfStringOrRegex, propertyToMatch) {
if (!Array.isArray(arrayOfStringOrRegex) || !propertyToMatch) {

@@ -62,8 +60,1 @@ return [];

}
module.exports = {
contains: contains,
hasProperty: hasProperty,
getMatchingValue: getMatchingValue,
getMatchingValuesByAll: getMatchingValuesByAll
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc