New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

neuron-pkg

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

neuron-pkg - npm Package Compare versions

Comparing version 0.1.5 to 1.0.0

64

index.js

@@ -1,9 +0,7 @@

'use strict';
'use strict'
module.exports = parse;
parse.format = format;
module.exports = parse
parse.format = format
var semver = require('semver');
var REGEX_PARSE_ID = /^((?:[^\/])+?)(?:@([^\/]+))?(\/.*)?$/;
var REGEX_PARSE_ID = /^((?:[^\/])+?)(?:@([^\/]+))?(\/.*)?$/
// On android 2.2,

@@ -16,41 +14,45 @@ // `[^\/]+?` will fail to do the lazy match, but `(?:[^\/]+?)` works.

if (!id) {
throw new TypeError('`id` must be a string.');
throw new TypeError('`id` must be a string.')
}
var match = id.match(REGEX_PARSE_ID);
var name = match[1];
var match = id.match(REGEX_PARSE_ID)
var name = match[1]
// 'a/inner' -> 'a@latest/inner'
var version = match[2]
var path = match[3] || '';
var range;
var path = match[3] || ''
if (version) {
if (!semver.valid(version)) {
range = version;
version = undefined;
}
}
// There always be matches
return {
name: name,
version: version,
range: range,
path: path
};
};
return new Pkg(name, version, path)
}
function Pkg (name, version, path) {
this.name = name
this.version = version
this.path = path
}
Pkg.prototype.format = function (){
return format(this)
}
Pkg.prototype.normalize_url = function () {
return this.name + '/'
+ (this.version || '*')
+ (this.path || '/' + this.name + '.js')
}
function format (obj) {
if (Object(obj) !== obj) {
throw new TypeError('`obj` must be an object.');
throw new TypeError('`obj` must be an object.')
}
var version = obj.version || obj.range;
var version_slice = version
? '@' + version
: '';
var version_slice = obj.version
? '@' + obj.version
: ''
return obj.name + version_slice + (obj.path || '');
return obj.name + version_slice + (obj.path || '')
}
{
"name": "neuron-pkg",
"version": "0.1.5",
"version": "1.0.0",
"description": "Parses neuron package id into name, version and path.",

@@ -14,2 +14,3 @@ "main": "index.js",

"keywords": [
"commonjs",
"neuron",

@@ -37,4 +38,3 @@ "module",

"dependencies": {
"semver": "^5.0.0"
}
}
[![NPM version](https://badge.fury.io/js/neuron-pkg.svg)](http://badge.fury.io/js/neuron-pkg)
[![Build Status](https://travis-ci.org/kaelzhang/neuron-pkg.svg?branch=master)](https://travis-ci.org/kaelzhang/neuron-pkg)
[![Dependency Status](https://gemnasium.com/kaelzhang/neuron-pkg.svg)](https://gemnasium.com/kaelzhang/neuron-pkg)

@@ -45,3 +44,3 @@ # neuron-pkg

- obj `Object`
- obj `Object`

@@ -48,0 +47,0 @@ The reverse method of `pkg(id)`

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

'use strict';
'use strict'
var expect = require('chai').expect;
var pkg = require('../');
var expect = require('chai').expect
var pkg = require('../')

@@ -9,79 +9,82 @@ var cases = [

id: 'a',
obj: {
name: 'a',
version: undefined,
range: undefined,
path: ''
}
name: 'a',
version: undefined,
path: '',
url: 'a/*/a.js'
},
{
id: 'a@1.1.0',
obj: {
name: 'a',
version: '1.1.0',
range: undefined,
path: ''
}
name: 'a',
version: '1.1.0',
path: '',
url: 'a/1.1.0/a.js'
},
{
id: 'a@1.1.0/a',
obj: {
name: 'a',
version: '1.1.0',
range: undefined,
path: '/a'
}
name: 'a',
version: '1.1.0',
path: '/a',
url: 'a/1.1.0/a'
},
{
id: 'a@~1.1.0/a',
obj: {
name: 'a',
range: '~1.1.0',
version: undefined,
path: '/a'
}
name: 'a',
version: '~1.1.0',
path: '/a',
url: 'a/~1.1.0/a'
},
{
id: 'a/a',
obj: {
name: 'a',
range: undefined,
version: undefined,
path: '/a'
}
name: 'a',
version: undefined,
path: '/a',
url: 'a/*/a'
},
{
id: 'a@hahah/a',
obj: {
name: 'a',
range: 'hahah',
version: undefined,
path: '/a'
}
name: 'a',
version: 'hahah',
path: '/a',
url: 'a/hahah/a'
},
{
id: 'a/a.css',
name: 'a',
version: undefined,
path: '/a.css',
url: 'a/*/a.css'
}
];
]
function expect_type (type, actual, expected) {
expect(type + ':' + actual).to.equal(type + ':' + expected)
}
cases.forEach(function (c) {
describe(c.id, function(){
it("pkg(id)", function(){
expect(pkg(c.id)).to.deep.equal(c.obj);
});
var p = pkg(c.id)
expect_type('name', p.name, c.name)
expect_type('version', p.version, c.version)
expect_type('path', p.path, c.path)
expect_type('.format()', p.format(), c.id)
expect_type('format(pkg)', pkg.format(p), c.id)
expect_type('.normalize_url()', p.normalize_url(p), c.url)
})
})
})
it("pkg.format(obj)", function(){
expect(pkg.format(c.obj)).to.equal(c.id);
});
});
});
describe("error", function(){
describe("error", function () {
it("should throw error if id is not a string", function(){
var error;
var error
try {
pkg();
pkg()
} catch(e) {
error = e;
error = e
}
expect(error).not.to.equal();
});
});
expect(error).not.to.equal()
})
})

Sorry, the diff of this file is not supported yet

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