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

vuex-alt

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vuex-alt - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

rollup.config.js

269

dist/index.js
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
Object.defineProperty(exports, '__esModule', {
value: true
});
var mapState = normalizeNamespace(function (namespace, states) {
var res = {};
normalizeMap(states).forEach(function (_ref) {
var key = _ref.key,
val = _ref.val;
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
res[key] = function mappedState() {
var state = this.$store.state;
var getters = this.$store.getters;
var camelCase = _interopDefault(require('camelcase'));
if (namespace) {
var module = getModuleByNamespace(this.$store, 'mapState', namespace);
const mapState = normalizeNamespace((namespace, states) => {
const res = {};
normalizeMap(states).forEach(({ key, val }) => {
res[key] = function mappedState() {
let state = this.$store.state;
let getters = this.$store.getters;
if (namespace) {
const module = getModuleByNamespace(this.$store, 'mapState', namespace);
if (!module) {
return
return;
}
state = module.context.state;
getters = module.context.getters;
}
return typeof val === 'function'
? val.call(this, state, getters)
: state[val]
};
// mark vuex getter for devtools
return typeof val === 'function' ? val.call(this, state, getters) : state[val];
}; // mark vuex getter for devtools
res[key].vuex = true;
});
return res
return res;
});
const mapGetters = function (gettersMap) {
const res = {};
const keys = Object.keys(gettersMap);
for (let i = 0; i < keys.length; i++) {
const thisGetterKey = keys[i];
const thisGetterMappingFn = gettersMap[thisGetterKey];
res[thisGetterKey] = function (...args) {
var mapGetters = function mapGetters(gettersMap) {
var res = {};
var keys = Object.keys(gettersMap);
var _loop = function _loop(i) {
var thisGetterKey = keys[i];
var thisGetterMappingFn = gettersMap[thisGetterKey];
res[thisGetterKey] = function () {
return thisGetterMappingFn(this._gettersNestedObject)();
};
};
for (var i = 0; i < keys.length; i++) {
_loop(i);
}
return res;
};
const mapActions = function (actionsMap) {
const res = {};
const keys = Object.keys(actionsMap);
for (let i = 0; i < keys.length; i++) {
const thisActionKey = keys[i];
const thisActionMappingFn = actionsMap[thisActionKey];
res[thisActionKey] = function (...args) {
return thisActionMappingFn(this._actionsNestedObject)(...args);
var mapActions = function mapActions(actionsMap) {
var res = {};
var keys = Object.keys(actionsMap);
var _loop2 = function _loop2(i) {
var thisActionKey = keys[i];
var thisActionMappingFn = actionsMap[thisActionKey];
res[thisActionKey] = function () {
return thisActionMappingFn(this._actionsNestedObject).apply(void 0, arguments);
};
};
for (var i = 0; i < keys.length; i++) {
_loop2(i);
}
return res;

@@ -60,9 +77,17 @@ };

function normalizeMap(map) {
return Array.isArray(map)
? map.map(key => ({ key, val: key }))
: Object.keys(map).map(key => ({ key, val: map[key] }))
return Array.isArray(map) ? map.map(function (key) {
return {
key: key,
val: key
};
}) : Object.keys(map).map(function (key) {
return {
key: key,
val: map[key]
};
});
}
function normalizeNamespace(fn) {
return (namespace, map) => {
return function (namespace, map) {
if (typeof namespace !== 'string') {

@@ -74,92 +99,163 @@ map = namespace;

}
return fn(namespace, map)
}
return fn(namespace, map);
};
}
function getModuleByNamespace(store, helper, namespace) {
const module = store._modulesNamespaceMap[namespace];
var module = store._modulesNamespaceMap[namespace];
if (process.env.NODE_ENV !== 'production' && !module) {
console.error(`[vuex] module namespace not found in ${helper}(): ${namespace}`);
console.error("[vuex] module namespace not found in ".concat(helper, "(): ").concat(namespace));
}
return module
return module;
}
const isNamespaced = (actionName) => actionName.indexOf('/') !== -1;
function preserveCamelCase(str) {
var isLastCharLower = false;
var isLastCharUpper = false;
var isLastLastCharUpper = false;
const splitNamespacedName = (actionName) => {
const splitActionName = actionName.split('/');
const namespaces = splitActionName.slice(0, splitActionName.length -1);
const name = splitActionName.slice(-1)[0];
return {
name,
namespaces
for (var i = 0; i < str.length; i++) {
var c = str[i];
if (isLastCharLower && /[a-zA-Z]/.test(c) && c.toUpperCase() === c) {
str = str.substr(0, i) + '-' + str.substr(i);
isLastCharLower = false;
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = true;
i++;
} else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(c) && c.toLowerCase() === c) {
str = str.substr(0, i - 1) + '-' + str.substr(i - 1);
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = false;
isLastCharLower = true;
} else {
isLastCharLower = c.toLowerCase() === c;
isLastLastCharUpper = isLastCharUpper;
isLastCharUpper = c.toUpperCase() === c;
}
}
return str;
}
var camelcase = function camelcase(str) {
if (arguments.length > 1) {
str = Array.from(arguments).map(function (x) {
return x.trim();
}).filter(function (x) {
return x.length;
}).join('-');
} else {
str = str.trim();
}
if (str.length === 0) {
return '';
}
if (str.length === 1) {
return str.toLowerCase();
}
if (/^[a-z0-9]+$/.test(str)) {
return str;
}
var hasUpperCase = str !== str.toLowerCase();
if (hasUpperCase) {
str = preserveCamelCase(str);
}
return str.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, function (m, p1) {
return p1.toUpperCase();
});
};
const VuexAltPlugin = {
install: (Vue, options) => {
const actions = options.store && options.store._actions;
const actionsNestedObject = {};
var isNamespaced = function isNamespaced(actionName) {
return actionName.indexOf('/') !== -1;
};
Object.keys(actions).forEach((thisActionName) => {
const thisActionFunctions = actions[thisActionName];
const thisActionFunction = thisActionFunctions[0];
var splitNamespacedName = function splitNamespacedName(actionName) {
var splitActionName = actionName.split('/');
var namespaces = splitActionName.slice(0, splitActionName.length - 1);
var name = splitActionName.slice(-1)[0];
return {
name: name,
namespaces: namespaces
};
};
const actionFn = function(...args) {
var VuexAltPlugin = {
install: function install(Vue, options) {
var actions = options.store && options.store._actions;
var actionsNestedObject = {};
Object.keys(actions).forEach(function (thisActionName) {
var thisActionFunctions = actions[thisActionName];
var thisActionFunction = thisActionFunctions[0];
var actionFn = function actionFn() {
if (!thisActionFunction) {
return;
}
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return thisActionFunction.apply(this, args);
};
if (isNamespaced(thisActionName)) {
const { name, namespaces } = splitNamespacedName(thisActionName);
var _splitNamespacedName = splitNamespacedName(thisActionName),
name = _splitNamespacedName.name,
namespaces = _splitNamespacedName.namespaces; // ensure each nested namespace exists as an object nested properly
// ensure each nested namespace exists as an object nested properly
let currentParent = actionsNestedObject;
namespaces.forEach((thisNamespace) => {
var currentParent = actionsNestedObject;
namespaces.forEach(function (thisNamespace) {
currentParent[thisNamespace] = currentParent[thisNamespace] || {};
currentParent = currentParent[thisNamespace];
});
// store this action on proper parent obj, and convert to camelCase as well
}); // store this action on proper parent obj, and convert to camelCase as well
currentParent[name] = actionFn;
currentParent[camelCase(name)] = actionFn;
currentParent[camelcase(name)] = actionFn;
} else {
// store action on root scope, and convert to camelCase as well
actionsNestedObject[thisActionName] = actionFn;
actionsNestedObject[camelCase(thisActionName)] = actionFn;
actionsNestedObject[camelcase(thisActionName)] = actionFn;
}
});
var getters = options.store && options.store.getters;
var gettersNestedObject = {};
Object.keys(getters).forEach(function (thisGetterName) {
var thisGetter = getters[thisGetterName];
const getters = options.store && options.store.getters;
const gettersNestedObject = {};
Object.keys(getters).forEach((thisGetterName) => {
const thisGetter = getters[thisGetterName];
const thisGetterFn = function() {
var thisGetterFn = function thisGetterFn() {
return getters[thisGetterName];
};
if (isNamespaced(thisGetterName)) {
const { name, namespaces } = splitNamespacedName(thisGetterName);
var _splitNamespacedName2 = splitNamespacedName(thisGetterName),
name = _splitNamespacedName2.name,
namespaces = _splitNamespacedName2.namespaces; // ensure each nested namespace exists as an object nested properly
// ensure each nested namespace exists as an object nested properly
let currentParent = gettersNestedObject;
namespaces.forEach((thisNamespace) => {
var currentParent = gettersNestedObject;
namespaces.forEach(function (thisNamespace) {
currentParent[thisNamespace] = currentParent[thisNamespace] || {};
currentParent = currentParent[thisNamespace];
});
// store this action on proper parent obj, and convert to camelCase as well
}); // store this action on proper parent obj, and convert to camelCase as well
currentParent[name] = thisGetterFn;
currentParent[camelCase(name)] = thisGetterFn;
currentParent[camelcase(name)] = thisGetterFn;
} else {
// store action on root scope, and convert to camelCase as well
gettersNestedObject[thisGetterName] = thisGetterFn;
gettersNestedObject[camelCase(thisGetterName)] = thisGetterFn;
gettersNestedObject[camelcase(thisGetterName)] = thisGetterFn;
}
});
Vue.prototype._actionsNestedObject = actionsNestedObject;

@@ -169,3 +265,2 @@ Vue.prototype._gettersNestedObject = gettersNestedObject;

};
exports.mapState = mapState;

@@ -172,0 +267,0 @@ exports.mapGetters = mapGetters;

{
"name": "vuex-alt",
"version": "0.0.7",
"version": "0.0.8",
"description": "An alternative approach to Vuex helpers for accessing state, getters and actions that doesn't rely on string constants.",

@@ -12,4 +12,5 @@ "main": "dist/index.js",

"test": "jest",
"build": "npm run test && rimraf dist/ && rollup src/index.js --format cjs --output dist/index.js",
"prepush": "npm run test"
"build": "npm run test && npm run bundle",
"bundle": "rimraf dist/ && rollup --config rollup.config.js && babel dist/index-not-transpiled.js --out-file dist/index.js && rimraf dist/index-not-transpiled.js",
"prepush": "npm run test && npm run build"
},

@@ -26,7 +27,13 @@ "keywords": [

"devDependencies": {
"babel-preset-es2015": "^6.24.1",
"husky": "^0.14.3",
"jest": "^20.0.4",
"@babel/cli": "^7.1.5",
"@babel/core": "^7.1.6",
"@babel/preset-env": "^7.1.6",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"husky": "^1.1.4",
"jest": "^23.6.0",
"rimraf": "^2.6.1",
"rollup": "^0.41.6"
"rollup": "^0.67.1",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-node-resolve": "^3.4.0"
},

@@ -33,0 +40,0 @@ "dependencies": {

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