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

req-ajax

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

req-ajax - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

ajax.js

21

gulpfile.js

@@ -1,11 +0,11 @@

const fs = require('fs')
const fs = require('fs')
const path = require('path')
const gulp = require('gulp')
const babel = require('gulp-babel')
const gulp = require('gulp')
const babel = require('gulp-babel')
const uglyfly = require('gulp-uglyfly')
const dest = require('gulp-dest')
const dest = require('gulp-dest')
gulp.task('babel', function () {
gulp.src('./src/ajax.js')
gulp.task('babel', function() {
gulp.src('./Ajax.js')
.pipe(babel())

@@ -18,7 +18,8 @@ .pipe(gulp.dest('./dist'))

gulp.task('removeCommonJS', function () {
['js', 'min.js'].forEach(function (ext) {
const pathFile = path.join(__dirname, `dist/ajax.${ext}`)
gulp.task('removeCommonJS', function() {
['js', 'min.js'].forEach(function(ext) {
const pathFile = path.join(__dirname, `dist/Ajax.${ext}`)
let src = fs.readFileSync(pathFile).toString()
src = src.replace(/module\.exports(\W=\W|=)ajax;/, '')
src = src.replace(/module\.exports(\W=\W|=)Ajax;/, '')
fs.writeFileSync(pathFile, src)

@@ -25,0 +26,0 @@ })

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

module.exports = require('./src/ajax')
module.exports = require('./Ajax')
{
"name": "req-ajax",
"version": "2.0.0",
"version": "3.0.0",
"description": "Standalone library for ajax requests",

@@ -26,8 +26,11 @@ "main": "index.js",

"babel-preset-env": "^1.2.1",
"chai": "^4.1.2",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-dest": "^0.2.3",
"gulp-uglyfly": "^1.4.2"
"gulp-uglyfly": "^1.4.2",
"mocha": "^5.0.0",
"sinon": "^4.1.6"
},
"dependencies": {}
}

@@ -22,92 +22,27 @@ # req-ajax

This can be used with `webpack` just requiring the module `req-ajax`.
Also this can be used with `webpack` just require the module `req-ajax`.
## API documentation
> All methods return a `Promise` object.
### Ajax constructor
## Methods
`new Ajax(config)`
### Method `query`
the **config** object:
Declaratation: `ajax.query(config)`
#### Properties
the **Object** is the config of that request, this object can have 3 properties:
- `url` - **{String}** is required.
- `method` - **{String}** is required.
- `params` - **{Object}** is optional, this property is for specific queries. The queries like this `foo=bar&bar=foo` can be transformed to `{ foo: 'bar', bar: 'foo' }` in the JavaScript object notation, so is much better for make queries and easy.
- `fragment` - **{String}** is optional, without the `#` character.
1. `url` **{String}** is required.
2. `method` **{String}** is required.
3. `params` **{Object}** is optional, this property is for specific queries. The queries like this `foo=bar&bar=foo` can be transformed to `{ foo: 'bar', bar: 'foo' }` in the JavaScript object notation, so is much better for make queries and easy.
4. `fragment` **{String}** is optional.
#### Methods
Example:
- `success(response)` - **{Function}** is optional.
- `error(status, headers)` - **{Funcion}** is optional.
```javascript
ajax.query({
url: '/somepath',
method: 'GET',
params: {
foo: 'bar'
},
fragment: '123'
// the uri should be '/somepath?foo=bar#123'.
}).then(function (res) {
// Do something with the response...
}).catch(function (err) {
// Manage the error of the request (if appear).
})
```
### Method `get`
Declaratation: `ajax.get(url [, json])`
This method is an shorthand for **GET** requests.
Params:
1. `url` **{String|Object}** is required, `url` can be an object like in `ajax.query` but without the property `method`.
2. `json` **{Boolean}** is optional, default `false`. This param is for when the response is json string, if `json` is `true` the response is parser for convert it to a object normal.
Per Example the file `somefile.json` contain `{ "foo": "bar" }`:
```javascript
ajax.get('/somefile.json', true)
.then(function (res) {
if (res.foo === 'bar') {
// Do something...
}
}).catch(function (err) {
// Trap the error.
})
```
### Method `post`
Declaratation: `ajax.post(url [, json])`
This method is an shorthand for **POST** requests.
Params:
1. `url` **{String|Object}** is required, `url` can be an object like in `ajax.query` but without the property `method`.
2. `data` **{String|Any}** is required, if the paramater json is true, `data` can be anything.
3. `json` **{Boolean}** is optional, default `false`. This param is for when the data is object normal and will send it as a json string.
Example:
```javascript
const data = { foo: 'bar' }
// The data is transformed to '{ "foo": "bar"}'
ajax.post('/somepath', data, true)
.then(function ()
// The post request was complete.
}).catch(function (err) {
// Something it's wrong.
})
```
## Test
For more examples and test execute `npm run test` and open your browser in the url `http://localhost:8080`.
For the unit-test execute `npm run test`.

@@ -114,0 +49,0 @@ ## License

Sorry, the diff of this file is not supported yet

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