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

vue-resource-case-converter

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-resource-case-converter - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

src/vue-resource-case-converter.js

27

dist/vue-resource-case-converter.js
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

@@ -10,5 +12,18 @@

var snakeCase = require('snake-case');
var camelCase = require('camel-case');
function snakeCase(string) {
var find = /(\_\w)/g;
var convert = function convert(matches) {
return matches[1].toUpperCase();
};
return string.replace(find, convert);
}
function camelCase(string) {
var find = /([A-Z])/g;
var convert = function convert(matches) {
return '_' + matches.toLowerCase();
};
return string.replace(find, convert);
}
function getClass(obj) {

@@ -41,3 +56,3 @@ // Workaround for detecting native classes.

module.exports = {
var VueResourceCaseConverter = {

@@ -93,2 +108,6 @@ install: function install(Vue, options) {

}
};
};
if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object' && module.exports) {
module.exports = VueResourceCaseConverter;
}

2

dist/vue-resource-case-converter.min.js

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

"use strict";function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function getClass(e){var r=Object.prototype.toString.call(e);return r.match(/\[object (.+)\]/)[1]}function convertObjectKeys(e,r){return"Object"!==getClass(e)&&"Array"!==getClass(e)?e:Object.keys(e).reduce(function(t,n){return Object.assign(t,_defineProperty({},r(n),convertObjectKeys(e[n],r))),t},Array.isArray(e)?[]:{})}var snakeCase=require("snake-case"),camelCase=require("camel-case");module.exports={install:function(e,r){var t=function(){return!0},n=function(){return!0};return null!=r&&r.requestUrlFilter&&(t=r.requestUrlFilter),null!=r&&r.responseUrlFilter&&(n=r.responseUrlFilter),null==e.http?void(void 0).$log("Please add http-resource plugin to your Vue instance"):void e.http.interceptors.push(function(e,r){t(e.url)&&Object.assign(e,{params:convertObjectKeys(e.params,snakeCase),body:convertObjectKeys(e.body,snakeCase)}),r(function(e){if(!n(e.url))return e;var r=void 0;try{r=JSON.parse(e.body)}catch(r){return e}var t=convertObjectKeys(r,camelCase);return Object.assign(e,{body:JSON.stringify(t)}),e})})}};
"use strict";function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function snakeCase(e){var t=/(\_\w)/g,r=function(e){return e[1].toUpperCase()};return e.replace(t,r)}function camelCase(e){var t=/([A-Z])/g,r=function(e){return"_"+e.toLowerCase()};return e.replace(t,r)}function getClass(e){var t=Object.prototype.toString.call(e);return t.match(/\[object (.+)\]/)[1]}function convertObjectKeys(e,t){return"Object"!==getClass(e)&&"Array"!==getClass(e)?e:Object.keys(e).reduce(function(r,n){return Object.assign(r,_defineProperty({},t(n),convertObjectKeys(e[n],t))),r},Array.isArray(e)?[]:{})}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},VueResourceCaseConverter={install:function(e,t){var r=function(){return!0},n=function(){return!0};return null!=t&&t.requestUrlFilter&&(r=t.requestUrlFilter),null!=t&&t.responseUrlFilter&&(n=t.responseUrlFilter),null==e.http?void(void 0).$log("Please add http-resource plugin to your Vue instance"):void e.http.interceptors.push(function(e,t){r(e.url)&&Object.assign(e,{params:convertObjectKeys(e.params,snakeCase),body:convertObjectKeys(e.body,snakeCase)}),t(function(e){if(!n(e.url))return e;var t=void 0;try{t=JSON.parse(e.body)}catch(t){return e}var r=convertObjectKeys(t,camelCase);return Object.assign(e,{body:JSON.stringify(r)}),e})})}};"object"===("undefined"==typeof module?"undefined":_typeof(module))&&module.exports&&(module.exports=VueResourceCaseConverter);

@@ -7,3 +7,3 @@ const gulp = require('gulp');

gulp.task('default', () => {
return gulp.src('index.js')
return gulp.src('src/vue-resource-case-converter.js')
.pipe(babel({

@@ -10,0 +10,0 @@ presets: ['es2015']

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

//
// Plugin for vue-resource to convert request params to snake case
// and response params to camel case
//
const snakeCase = require('snake-case');
const camelCase = require('camel-case');
function getClass(obj) {
// Workaround for detecting native classes.
// Examples:
// getClass({}) === 'Object'
// getClass([]) === 'Array'
// getClass(function () {}) === 'Function'
// getClass(new Date) === 'Date'
// getClass(null) === 'Null'
// Here we get a string like '[object XYZ]'
const typeWithBrackets = Object.prototype.toString.call(obj);
// and we extract 'XYZ' from it
return typeWithBrackets.match(/\[object (.+)\]/)[1];
}
function convertObjectKeys(obj, keyConversionFun) {
// Creates a new object mimicking the old one with keys changed using the keyConversionFun.
// Does a deep conversion.
// Taken from https://github.com/ZupIT/angular-http-case-converter
if (getClass(obj) !== 'Object' && getClass(obj) !== 'Array') {
return obj; // Primitives are returned unchanged.
}
return Object.keys(obj).reduce((newObj, key) => {
Object.assign(newObj, {
[keyConversionFun(key)]: convertObjectKeys(obj[key], keyConversionFun),
});
return newObj;
}, Array.isArray(obj) ? [] : {}); // preserve "arrayness"
}
module.exports = {
install: (Vue, options) => {
let requestUrlFilter = function () {
return true;
};
let responseUrlFilter = function () {
return true;
};
if (options != null && options.requestUrlFilter) {
requestUrlFilter = options.requestUrlFilter;
}
if (options != null && options.responseUrlFilter) {
responseUrlFilter = options.responseUrlFilter;
}
if (Vue.http == null) {
this.$log('Please add http-resource plugin to your Vue instance');
return;
}
Vue.http.interceptors.push((request, next) => {
if (requestUrlFilter(request.url)) {
Object.assign(request, {
params: convertObjectKeys(request.params, snakeCase),
body: convertObjectKeys(request.body, snakeCase),
});
}
next((response) => {
if (!responseUrlFilter(response.url)) {
return response;
}
let parsedBody;
try {
parsedBody = JSON.parse(response.body);
}
catch (e) {
return response;
}
const convertedBody = convertObjectKeys(parsedBody, camelCase);
Object.assign(response, {
body: JSON.stringify(convertedBody),
});
return response;
});
});
},
};
module.exports = require('./src/vue-resource-case-converter.js');
{
"name": "vue-resource-case-converter",
"version": "1.0.3",
"version": "1.0.4",
"description": "Vue resource plugin to convert request json keys to snake_case and response json keys to camelCase",
"main": "dist/vue-resource-case-converter.js",
"main": "index.js",
"scripts": {

@@ -29,6 +29,3 @@ "test": "echo \"Error: no test specified\" && exit 1"

"homepage": "https://github.com/staskjs/vue-resource-case-converter#readme",
"dependencies": {
"camel-case": "^3.0.0",
"snake-case": "^2.1.0"
},
"dependencies": {},
"devDependencies": {

@@ -35,0 +32,0 @@ "babel-preset-es2015": "^6.13.2",

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