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

npm-update

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-update - npm Package Compare versions

Comparing version 1.0.2 to 1.0.4

85

lib/logger.js

@@ -1,86 +0,7 @@

/* ================================================================
* npm-update by xdf(xudafeng[at]126.com)
*
* first created at : Tue Aug 04 2015 11:20:24 GMT+0800 (CST)
*
* ================================================================
* Copyright xdf
*
* Licensed under the MIT License
* You may not use this file except in compliance with the License.
*
* ================================================================ */
'use strict';
var util = require('util');
var path = require('path');
var logger = require('xlogger');
var TYPES = ['log', 'info', 'debug', 'warn', 'error'];
var COLORS = ['\u001b[32m', '\u001b[36m', '\u001b[37m', '\u001b[33m', '\u001b[31m'];
var logger = {};
function format(msg, data, type) {
var res = msg[0];
if (msg.length === 1) {
return '>> ' + data.file + ':' + data.line + ':' + data.pos + ' ' + res;
}
var match = res.match(new RegExp('%s|%d|%j', 'g'));
if (match) {
match.forEach(function(type, index) {
var content = msg[index + 1];
if (!content) {
res += type;
} else if (type === '%s') {
res = res.replace(new RegExp('%s', 'i'), String(content));
} else if (type === '%d') {
res = res.replace(new RegExp('%d', 'i'), Number(content));
} else if (type === '%j') {
res = res.replace(new RegExp('%j', 'i'), util.inspect(content, {showHidden: true, depth: null}));
}
});
var num = msg.length - match.length - 1;
if (num > 0) {
while (num --) {
res += ' ' + msg[msg.length - num - 1];
}
}
}
if (type !== 'info') {
res = data.file + ':' + data.line + ':' + data.pos + ' ' + res;
}
res = '>> ' + res;
return res;
}
TYPES.forEach(function(type, k) {
logger[type] = function() {
var debug = type === 'debug';
if (!debug) {
return;
}
var stack = (new Error()).stack.split('\n');
var reg = new RegExp('at\\s+(.*)\\s+\\((.*):(\\d*):(\\d*)\\)', 'g');
var reg2 = new RegExp('at\\s+()(.*):(\\d*):(\\d*)', 'g');
var arr = reg.exec(stack[2]) || reg2.exec(stack[2]);
var data = {};
data.path = arr[2];
data.line = arr[3];
data.pos = arr[4];
data.file = path.basename(data.path);
data.stack = stack.join('\n');
console.info(COLORS[k] + TYPES[k].toUpperCase() + ' ' + format(arguments, data, type) + '\u001b[0m');
if (type === 'error') {
throw new Error(data);
}
};
module.exports = logger.Logger({
closeFile: true
});
module.exports = logger;

5

lib/npm-update.js

@@ -19,8 +19,9 @@ /* ================================================================

module.exports = function *(options) {
var pkg = options.pkg;
var pkg = options.pkg || {};
var callback = options.callback;
var name = pkg.name || options.name;
var protocol = options.protocol || 'http';
var opt = {
uri: protocol + '://registry.npmjs.org/' + pkg.name + '/latest',
uri: protocol + '://registry.npmjs.org/' + name + '/latest',
method: 'get',

@@ -27,0 +28,0 @@ timeout: options.timeout || 1000

{
"name": "npm-update",
"version": "1.0.2",
"version": "1.0.4",
"description": "npm-update",
"keywords": ["npm-update"],
"keywords": [
"npm-update"
],
"bin": {

@@ -15,10 +17,13 @@ "npm-update": "./bin/npm-update"

"dependencies": {
"co-request": "~0.2.0"
"co-request": "~0.2.0",
"xlogger": "~1.0.0"
},
"devDependencies": {
"co": "^4.6.0",
"co-mocha": "^1.1.3",
"istanbul": "*",
"jshint": "*",
"mocha": "*",
"should": "*",
"jshint": "*",
"istanbul": "*",
"pre-commit": "1.1.1"
"pre-commit": "1.1.1",
"should": "*"
},

@@ -25,0 +30,0 @@ "scripts": {

@@ -1,3 +0,2 @@

npm-update
====
# npm-update

@@ -21,7 +20,7 @@ [![NPM version][npm-image]][npm-url]

> npm-update
> npm update
## Installment
```bash
```shell
$ npm i npm-update --save

@@ -32,3 +31,3 @@ ```

```js
```javascript
var update = require('npm-update');

@@ -35,0 +34,0 @@ var pkg = require('../package');

@@ -16,5 +16,53 @@ /* ================================================================

var npm-update = require('../');
var update = require('../lib/npm-update');
var co = require('co');
describe('test', function(){
var pkg = {
name: 'npm-update'
};
describe('#npm-update', function() {
this.timeout(50000);
it('only pkg', function(done) {
co(update, {
pkg: pkg,
callback: function(err, data) {
data.name.should.be.eql(pkg.name);
done();
}
});
});
it('only name', function(done) {
co(update, {
name: pkg.name,
callback: function(err, data) {
data.name.should.be.eql(pkg.name);
done();
}
});
});
it('pkg.name and name are same', function(done) {
co(update, {
pkg: pkg,
name: pkg.name,
callback: function(err, data) {
data.name.should.be.eql(pkg.name);
done();
}
});
});
it('pkg.name and name are different', function(done) {
co(update, {
pkg: 'express',
name: 'koa',
callback: function(err, data) {
data.name.should.be.eql('koa');
done();
}
});
});
});

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