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

najax

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

najax - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

9

lib/najax.js

@@ -12,2 +12,3 @@ /* najax

var $ = require('jquery-deferred')
var defaultsDeep = require('lodash.defaultsdeep')
var parseOptions = require('./parse-options')

@@ -34,3 +35,3 @@ var defaults = {

var dfd = new $.Deferred()
var o = Object.assign({}, defaults, parseOptions(uri, options, callback))
var o = defaultsDeep({}, parseOptions(uri, options, callback), defaults)
var l = url.parse(o.url)

@@ -70,3 +71,3 @@ var ssl = l.protocol.indexOf('https') === 0

o.headers = Object.assign({
'Content-Type': o.contentType + ';charset=utf-8',
'Content-Type': o.contentType,
'Content-Length': Buffer.byteLength(o.data)

@@ -237,3 +238,3 @@ }, o.headers)

najax.defaults = function mergeDefaults (opts) {
return Object.assign({}, defaults, opts)
return defaultsDeep(defaults, opts)
}

@@ -246,3 +247,3 @@

najax[method.toLowerCase()] = function methodHandler (uri, options, callback) {
return najax(Object.assign(parseOptions(uri, options, callback), { method: method }))
return najax(defaultsDeep(parseOptions(uri, options, callback), { method: method }))
}

@@ -249,0 +250,0 @@ }

{
"name": "najax",
"description": "jquery ajax-stye http requests in node",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com/najaxjs/najax",

@@ -45,2 +45,3 @@ "author": "Alan Clarke <self@alz.so> (alz.so)",

"jquery-deferred": "^0.3.0",
"lodash.defaultsdeep": "^4.6.0",
"qs": "^6.2.0"

@@ -47,0 +48,0 @@ },

@@ -219,3 +219,3 @@ /* globals describe beforeEach it */

.post('/', 'a=1')
.matchHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8')
.matchHeader('Content-Type', 'application/x-www-form-urlencoded')
.matchHeader('Content-Length', 3)

@@ -230,3 +230,3 @@ .reply(200, 'ok')

.post('/', 'a=1&b%5Bc%5D=1')
.matchHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8')
.matchHeader('Content-Type', 'application/x-www-form-urlencoded')
.reply(200, 'ok')

@@ -239,3 +239,3 @@ najax.post('http://www.example.com', { data: { a: 1, b: { c: 1 } } }, createSuccess(done))

.post('/', data)
.matchHeader('Content-Type', 'application/json;charset=utf-8')
.matchHeader('Content-Type', 'application/json')
.matchHeader('Content-Length', 7)

@@ -253,3 +253,3 @@ .reply(200, 'ok')

.post('/', data)
.matchHeader('Content-Type', 'application/xml;charset=utf-8')
.matchHeader('Content-Type', 'application/xml')
.matchHeader('Content-Length', 7)

@@ -269,3 +269,3 @@ .reply(200, 'ok')

.post('/', data)
.matchHeader('Content-Type', 'application/xml;charset=utf-8')
.matchHeader('Content-Type', 'application/xml')
.matchHeader('Content-Length', 7)

@@ -287,3 +287,3 @@ .matchHeader('Cookie', cookie)

.post('/', data)
.matchHeader('Content-Type', 'application/xml;charset=utf-8')
.matchHeader('Content-Type', 'application/xml')
.matchHeader('Content-Length', 7)

@@ -357,2 +357,38 @@ .matchHeader('Accepts', 'application/vnd.json+api')

describe('defaults', function () {
function mockResponse () {
nock('http://www.example.com')
.get('/')
.reply(function (uri, requestBody) {
if (this.req.headers.accessible) {
return [200, 'ok', {}]
} else {
return [401, 'Unauthorized', {}]
}
})
}
it('should dispose of request headers after each request', function (done) {
mockResponse()
najax.get('http://www.example.com', {
beforeSend: function (xhr) {
xhr.setRequestHeader('accessible', 'true')
},
complete: function (data, statusText, jqXHR) {
expect(jqXHR.status).to.equal(200)
}
})
mockResponse()
najax.get('http://www.example.com', {
error: null,
complete: function (jqXHR, statusText, error) {
expect(jqXHR, 'request should not succeed').to.be.an('object')
expect(jqXHR.status).to.equal(401)
done()
}
})
})
})
function createSuccess (done) {

@@ -359,0 +395,0 @@ return function (data, statusText) {

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