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

vue-i18n

Package Overview
Dependencies
Maintainers
1
Versions
355
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-i18n - npm Package Compare versions

Comparing version 4.1.0 to 4.2.0

src/observer.js

15

CHANGELOG.md

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

<a name="4.2.0"></a>
# [4.2.0](https://github.com/kazupon/vue-i18n/compare/v4.1.0...v4.2.0) (2016-08-12)
### :chart_with_upwards_trend: Performance Fixes
* **format:** use hasOwn function of Vue.util ([a8a19a0](https://github.com/kazupon/vue-i18n/commit/a8a19a0))
### :star: New Features
* **fallback:** add fallback translation feature ([1d1f0f2](https://github.com/kazupon/vue-i18n/commit/1d1f0f2)), closes [#36](https://github.com/kazupon/vue-i18n/issues/36)
<a name="4.1.0"></a>

@@ -2,0 +17,0 @@ # [4.1.0](https://github.com/kazupon/vue-i18n/compare/v4.0.1...v4.1.0) (2016-07-25)

571

dist/vue-i18n.common.js
/*!
* vue-i18n v4.1.0
* vue-i18n v4.2.0
* (c) 2016 kazuya kawaguchi

@@ -17,8 +17,2 @@ * Released under the MIT License.

/**
* Utilties
*/
// export default for holding the Vue reference
var exports$1 = {};
/**
* warn

@@ -40,47 +34,143 @@ *

var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Check whether the object has the property.
*
* @param {Object} obj
* @param {String} key
* @return {Boolean}
*/
var locales = Object.create(null); // locales store
function hasOwn(obj, key) {
return hasOwnProperty.call(obj, key);
function Asset (Vue) {
/**
* Register or retrieve a global locale definition.
*
* @param {String} id
* @param {Object | Function | Promise} definition
* @param {Function} cb
*/
Vue.locale = function (id, definition, cb) {
if (definition === undefined) {
// gettter
return locales[id];
} else {
// setter
if (definition === null) {
locales[id] = undefined;
delete locales[id];
} else {
setLocale(id, definition, function (locale) {
if (locale) {
locales[id] = locale;
cb && cb();
} else {
warn('failed set `' + id + '` locale');
}
});
}
}
};
}
function setLocale(id, definition, cb) {
var _this = this;
if ((typeof definition === 'undefined' ? 'undefined' : babelHelpers.typeof(definition)) === 'object') {
// sync
cb(definition);
} else {
(function () {
var future = definition.call(_this);
if (typeof future === 'function') {
if (future.resolved) {
// cached
cb(future.resolved);
} else if (future.requested) {
// pool callbacks
future.pendingCallbacks.push(cb);
} else {
(function () {
future.requested = true;
var cbs = future.pendingCallbacks = [cb];
future(function (locale) {
// resolve
future.resolved = locale;
for (var i = 0, l = cbs.length; i < l; i++) {
cbs[i](locale);
}
}, function () {
// reject
cb();
});
})();
}
} else if (isPromise(future)) {
// promise
future.then(function (locale) {
// resolve
cb(locale);
}, function () {
// reject
cb();
}).catch(function (err) {
console.error(err);
cb();
});
}
})();
}
}
/**
* empty
* Forgiving check for a promise
*
* @param {Array|Object} target
* @param {Object} p
* @return {Boolean}
*/
function empty(target) {
if (target === null || target === undefined) {
return true;
}
function isPromise(p) {
return p && typeof p.then === 'function';
}
if (Array.isArray(target)) {
if (target.length > 0) {
return false;
function Override (Vue, langVM) {
// override _init
var init = Vue.prototype._init;
Vue.prototype._init = function (options) {
var _this = this;
options = options || {};
var root = options._parent || options.parent || this;
var lang = root.$lang;
if (lang) {
this.$lang = lang;
} else {
this.$lang = langVM;
}
if (target.length === 0) {
return true;
this._langUnwatch = this.$lang.$watch('lang', function (a, b) {
update(_this);
});
init.call(this, options);
};
// override _destroy
var destroy = Vue.prototype._destroy;
Vue.prototype._destroy = function () {
if (this._langUnwatch) {
this._langUnwatch();
this._langUnwatch = null;
}
} else if (exports$1.Vue.util.isPlainObject(target)) {
/* eslint-disable prefer-const */
for (var key in target) {
if (hasOwn(target, key)) {
return false;
}
}
/* eslint-enable prefer-const */
}
return true;
this.$lang = null;
destroy.apply(this, arguments);
};
}
function update(vm) {
var i = vm._watchers.length;
while (i--) {
vm._watchers[i].update(true); // shallow updates
}
}
/**
* Observer
*/
var Watcher = void 0;

@@ -118,15 +208,109 @@ /**

var fallback = void 0; // fallback lang
function Config (Vue, langVM, lang) {
var bind = Vue.util.bind;
var Watcher = getWatcher(langVM);
var Dep = getDep(langVM);
function makeComputedGetter(getter, owner) {
var watcher = new Watcher(owner, getter, null, {
lazy: true
});
return function computedGetter() {
if (watcher.dirty) {
watcher.evaluate();
}
if (Dep.target) {
watcher.depend();
}
return watcher.value;
};
}
// define Vue.config.lang configration
Object.defineProperty(Vue.config, 'lang', {
enumerable: true,
configurable: true,
get: makeComputedGetter(function () {
return langVM.lang;
}, langVM),
set: bind(function (val) {
langVM.lang = val;
}, langVM)
});
// define Vue.config.fallbackLang configration
fallback = lang;
Object.defineProperty(Vue.config, 'fallbackLang', {
enumerable: true,
configurable: true,
get: function get() {
return fallback;
},
set: function set(val) {
fallback = val;
}
});
}
/**
* Forgiving check for a promise
*
* @param {Object} p
* @return {Boolean}
* String format template
* - Inspired:
* https://github.com/Matt-Esch/string-template/index.js
*/
function isPromise(p) {
return p && typeof p.then === 'function';
var RE_NARGS = /(%|)\{([0-9a-zA-Z_]+)\}/g;
function Format (Vue) {
var hasOwn = Vue.util.hasOwn;
/**
* template
*
* @param {String} string
* @param {Array} ...args
* @return {String}
*/
function template(string) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
if (args.length === 1 && babelHelpers.typeof(args[0]) === 'object') {
args = args[0];
}
if (!args || !args.hasOwnProperty) {
args = {};
}
return string.replace(RE_NARGS, function (match, prefix, i, index) {
var result = void 0;
if (string[index - 1] === '{' && string[index + match.length] === '}') {
return i;
} else {
result = hasOwn(args, i) ? args[i] : null;
if (result === null || result === undefined) {
return '';
}
return result;
}
});
}
return template;
}
// export default for holding the Vue reference
var exports$2 = {};
/**
* Path paerser
* - Inspired:
* Vue.js Path parser
*/
// cache

@@ -268,3 +452,3 @@ var pathCache = Object.create(null);

function formatSubPath(path) {
var _exports$Vue$util = exports$2.Vue.util;
var _exports$Vue$util = exports.Vue.util;
var isLiteral = _exports$Vue$util.isLiteral;

@@ -402,246 +586,74 @@ var stripQuotes = _exports$Vue$util.stripQuotes;

/**
* Get value from path string
*
* @param {Object} obj
* @param {String} path
* @return value
*/
function Path (Vue) {
var _Vue$util = Vue.util;
var isObject = _Vue$util.isObject;
var isPlainObject = _Vue$util.isPlainObject;
var hasOwn = _Vue$util.hasOwn;
function getValue(obj, path) {
var isObject = exports$2.Vue.util.isObject;
function empty(target) {
if (target === null || target === undefined) {
return true;
}
if (!isObject(obj)) {
return null;
}
if (Array.isArray(target)) {
if (target.length > 0) {
return false;
}
if (target.length === 0) {
return true;
}
} else if (isPlainObject(target)) {
/* eslint-disable prefer-const */
for (var key in target) {
if (hasOwn(target, key)) {
return false;
}
}
/* eslint-enable prefer-const */
}
var paths = parsePath(path);
if (empty(paths)) {
return null;
return true;
}
var length = paths.length;
var ret = null;
var last = obj;
var i = 0;
while (i < length) {
var value = last[paths[i]];
if (value === undefined) {
last = null;
break;
}
last = value;
i++;
}
ret = last;
return ret;
}
var locales = Object.create(null); // locales store
function Asset (Vue) {
/**
* Register or retrieve a global locale definition.
* Get value from path string
*
* @param {String} id
* @param {Object | Function | Promise} definition
* @param {Function} cb
* @param {Object} obj
* @param {String} path
* @return value
*/
Vue.locale = function (id, definition, cb) {
if (definition === undefined) {
// gettter
return locales[id];
} else {
// setter
if (definition === null) {
locales[id] = undefined;
delete locales[id];
} else {
setLocale(id, definition, function (locale) {
if (locale) {
locales[id] = locale;
cb && cb();
} else {
warn('failed set `' + id + '` locale');
}
});
}
function getValue(obj, path) {
if (!isObject(obj)) {
return null;
}
};
}
function setLocale(id, definition, cb) {
var _this = this;
var paths = parsePath(path);
if (empty(paths)) {
return null;
}
if ((typeof definition === 'undefined' ? 'undefined' : babelHelpers.typeof(definition)) === 'object') {
// sync
cb(definition);
} else {
(function () {
var future = definition.call(_this);
if (typeof future === 'function') {
if (future.resolved) {
// cached
cb(future.resolved);
} else if (future.requested) {
// pool callbacks
future.pendingCallbacks.push(cb);
} else {
(function () {
future.requested = true;
var cbs = future.pendingCallbacks = [cb];
future(function (locale) {
// resolve
future.resolved = locale;
for (var i = 0, l = cbs.length; i < l; i++) {
cbs[i](locale);
}
}, function () {
// reject
cb();
});
})();
}
} else if (isPromise(future)) {
// promise
future.then(function (locale) {
// resolve
cb(locale);
}, function () {
// reject
cb();
}).catch(function (err) {
console.error(err);
cb();
});
var length = paths.length;
var ret = null;
var last = obj;
var i = 0;
while (i < length) {
var value = last[paths[i]];
if (value === undefined) {
last = null;
break;
}
})();
}
}
function Override (Vue, langVM) {
// override _init
var init = Vue.prototype._init;
Vue.prototype._init = function (options) {
var _this = this;
options = options || {};
var root = options._parent || options.parent || this;
var lang = root.$lang;
if (lang) {
this.$lang = lang;
} else {
this.$lang = langVM;
last = value;
i++;
}
this._langUnwatch = this.$lang.$watch('lang', function (a, b) {
update(_this);
});
init.call(this, options);
};
// override _destroy
var destroy = Vue.prototype._destroy;
Vue.prototype._destroy = function () {
if (this._langUnwatch) {
this._langUnwatch();
this._langUnwatch = null;
}
this.$lang = null;
destroy.apply(this, arguments);
};
}
function update(vm) {
var i = vm._watchers.length;
while (i--) {
vm._watchers[i].update(true); // shallow updates
ret = last;
return ret;
}
}
function Config (Vue, langVM) {
var Watcher = getWatcher(langVM);
var Dep = getDep(langVM);
function makeComputedGetter(getter, owner) {
var watcher = new Watcher(owner, getter, null, {
lazy: true
});
return function computedGetter() {
if (watcher.dirty) {
watcher.evaluate();
}
if (Dep.target) {
watcher.depend();
}
return watcher.value;
};
}
// define Vue.config.lang configration
Object.defineProperty(Vue.config, 'lang', {
enumerable: true,
configurable: true,
get: makeComputedGetter(function () {
return langVM.lang;
}, langVM),
set: Vue.util.bind(function (val) {
langVM.lang = val;
}, langVM)
});
return getValue;
}
/**
* String format template
* - Inspired:
* https://github.com/Matt-Esch/string-template/index.js
*/
var RE_NARGS = /(%|)\{([0-9a-zA-Z_]+)\}/g;
/**
* template
*
* @param {String} string
* @param {Array} ...args
* @return {String}
*/
function format (string) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
if (args.length === 1 && babelHelpers.typeof(args[0]) === 'object') {
args = args[0];
}
if (!args || !args.hasOwnProperty) {
args = {};
}
return string.replace(RE_NARGS, function (match, prefix, i, index) {
var result = void 0;
if (string[index - 1] === '{' && string[index + match.length] === '}') {
return i;
} else {
result = args.hasOwnProperty(i) ? args[i] : null;
if (result === null || result === undefined) {
return '';
}
return result;
}
});
}
/**
* extend

@@ -656,2 +668,4 @@ *

var format = Format(Vue);
var getValue = Path(Vue);

@@ -664,2 +678,4 @@ function parseArgs() {

var lang = Vue.config.lang;
var fallback = Vue.config.fallbackLang;
if (args.length === 1) {

@@ -680,3 +696,3 @@ if (isObject(args[0]) || Array.isArray(args[0])) {

return { lang: lang, params: args };
return { lang: lang, fallback: fallback, params: args };
}

@@ -724,5 +740,6 @@

var lang = _parseArgs.lang;
var fallback = _parseArgs.fallback;
var params = _parseArgs.params;
return translate(Vue.locale(lang), key, params) || warnDefault(key);
return translate(Vue.locale(lang), key, params) || translate(Vue.locale(fallback), key, params) || warnDefault(key);
};

@@ -750,5 +767,6 @@

var lang = _parseArgs2.lang;
var fallback = _parseArgs2.fallback;
var params = _parseArgs2.params;
return translate(this.$options.locales && this.$options.locales[lang], key, params) || translate(Vue.locale(lang), key, params) || warnDefault(key);
return translate(this.$options.locales && this.$options.locales[lang], key, params) || translate(this.$options.locales && this.$options.locales[fallback], key, params) || translate(Vue.locale(lang), key, params) || translate(Vue.locale(fallback), key, params) || warnDefault(key);
};

@@ -785,9 +803,6 @@

exports$2.Vue = exports$1.Vue = Vue;
setupLangVM(Vue, lang);
Asset(Vue);
Override(Vue, langVM);
Config(Vue, langVM);
Config(Vue, langVM, lang);
Extend(Vue);

@@ -805,3 +820,3 @@ }

plugin.version = '4.1.0';
plugin.version = '4.2.0';

@@ -808,0 +823,0 @@ if (typeof window !== 'undefined' && window.Vue) {

/*!
* vue-i18n v4.1.0
* vue-i18n v4.2.0
* (c) 2016 kazuya kawaguchi

@@ -21,8 +21,2 @@ * Released under the MIT License.

/**
* Utilties
*/
// export default for holding the Vue reference
var exports$1 = {};
/**
* warn

@@ -44,47 +38,143 @@ *

var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Check whether the object has the property.
*
* @param {Object} obj
* @param {String} key
* @return {Boolean}
*/
var locales = Object.create(null); // locales store
function hasOwn(obj, key) {
return hasOwnProperty.call(obj, key);
function Asset (Vue) {
/**
* Register or retrieve a global locale definition.
*
* @param {String} id
* @param {Object | Function | Promise} definition
* @param {Function} cb
*/
Vue.locale = function (id, definition, cb) {
if (definition === undefined) {
// gettter
return locales[id];
} else {
// setter
if (definition === null) {
locales[id] = undefined;
delete locales[id];
} else {
setLocale(id, definition, function (locale) {
if (locale) {
locales[id] = locale;
cb && cb();
} else {
warn('failed set `' + id + '` locale');
}
});
}
}
};
}
function setLocale(id, definition, cb) {
var _this = this;
if ((typeof definition === 'undefined' ? 'undefined' : babelHelpers.typeof(definition)) === 'object') {
// sync
cb(definition);
} else {
(function () {
var future = definition.call(_this);
if (typeof future === 'function') {
if (future.resolved) {
// cached
cb(future.resolved);
} else if (future.requested) {
// pool callbacks
future.pendingCallbacks.push(cb);
} else {
(function () {
future.requested = true;
var cbs = future.pendingCallbacks = [cb];
future(function (locale) {
// resolve
future.resolved = locale;
for (var i = 0, l = cbs.length; i < l; i++) {
cbs[i](locale);
}
}, function () {
// reject
cb();
});
})();
}
} else if (isPromise(future)) {
// promise
future.then(function (locale) {
// resolve
cb(locale);
}, function () {
// reject
cb();
}).catch(function (err) {
console.error(err);
cb();
});
}
})();
}
}
/**
* empty
* Forgiving check for a promise
*
* @param {Array|Object} target
* @param {Object} p
* @return {Boolean}
*/
function empty(target) {
if (target === null || target === undefined) {
return true;
}
function isPromise(p) {
return p && typeof p.then === 'function';
}
if (Array.isArray(target)) {
if (target.length > 0) {
return false;
function Override (Vue, langVM) {
// override _init
var init = Vue.prototype._init;
Vue.prototype._init = function (options) {
var _this = this;
options = options || {};
var root = options._parent || options.parent || this;
var lang = root.$lang;
if (lang) {
this.$lang = lang;
} else {
this.$lang = langVM;
}
if (target.length === 0) {
return true;
this._langUnwatch = this.$lang.$watch('lang', function (a, b) {
update(_this);
});
init.call(this, options);
};
// override _destroy
var destroy = Vue.prototype._destroy;
Vue.prototype._destroy = function () {
if (this._langUnwatch) {
this._langUnwatch();
this._langUnwatch = null;
}
} else if (exports$1.Vue.util.isPlainObject(target)) {
/* eslint-disable prefer-const */
for (var key in target) {
if (hasOwn(target, key)) {
return false;
}
}
/* eslint-enable prefer-const */
}
return true;
this.$lang = null;
destroy.apply(this, arguments);
};
}
function update(vm) {
var i = vm._watchers.length;
while (i--) {
vm._watchers[i].update(true); // shallow updates
}
}
/**
* Observer
*/
var Watcher = void 0;

@@ -122,15 +212,109 @@ /**

var fallback = void 0; // fallback lang
function Config (Vue, langVM, lang) {
var bind = Vue.util.bind;
var Watcher = getWatcher(langVM);
var Dep = getDep(langVM);
function makeComputedGetter(getter, owner) {
var watcher = new Watcher(owner, getter, null, {
lazy: true
});
return function computedGetter() {
if (watcher.dirty) {
watcher.evaluate();
}
if (Dep.target) {
watcher.depend();
}
return watcher.value;
};
}
// define Vue.config.lang configration
Object.defineProperty(Vue.config, 'lang', {
enumerable: true,
configurable: true,
get: makeComputedGetter(function () {
return langVM.lang;
}, langVM),
set: bind(function (val) {
langVM.lang = val;
}, langVM)
});
// define Vue.config.fallbackLang configration
fallback = lang;
Object.defineProperty(Vue.config, 'fallbackLang', {
enumerable: true,
configurable: true,
get: function get() {
return fallback;
},
set: function set(val) {
fallback = val;
}
});
}
/**
* Forgiving check for a promise
*
* @param {Object} p
* @return {Boolean}
* String format template
* - Inspired:
* https://github.com/Matt-Esch/string-template/index.js
*/
function isPromise(p) {
return p && typeof p.then === 'function';
var RE_NARGS = /(%|)\{([0-9a-zA-Z_]+)\}/g;
function Format (Vue) {
var hasOwn = Vue.util.hasOwn;
/**
* template
*
* @param {String} string
* @param {Array} ...args
* @return {String}
*/
function template(string) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
if (args.length === 1 && babelHelpers.typeof(args[0]) === 'object') {
args = args[0];
}
if (!args || !args.hasOwnProperty) {
args = {};
}
return string.replace(RE_NARGS, function (match, prefix, i, index) {
var result = void 0;
if (string[index - 1] === '{' && string[index + match.length] === '}') {
return i;
} else {
result = hasOwn(args, i) ? args[i] : null;
if (result === null || result === undefined) {
return '';
}
return result;
}
});
}
return template;
}
// export default for holding the Vue reference
var exports$2 = {};
/**
* Path paerser
* - Inspired:
* Vue.js Path parser
*/
// cache

@@ -272,3 +456,3 @@ var pathCache = Object.create(null);

function formatSubPath(path) {
var _exports$Vue$util = exports$2.Vue.util;
var _exports$Vue$util = exports.Vue.util;
var isLiteral = _exports$Vue$util.isLiteral;

@@ -406,246 +590,74 @@ var stripQuotes = _exports$Vue$util.stripQuotes;

/**
* Get value from path string
*
* @param {Object} obj
* @param {String} path
* @return value
*/
function Path (Vue) {
var _Vue$util = Vue.util;
var isObject = _Vue$util.isObject;
var isPlainObject = _Vue$util.isPlainObject;
var hasOwn = _Vue$util.hasOwn;
function getValue(obj, path) {
var isObject = exports$2.Vue.util.isObject;
function empty(target) {
if (target === null || target === undefined) {
return true;
}
if (!isObject(obj)) {
return null;
}
if (Array.isArray(target)) {
if (target.length > 0) {
return false;
}
if (target.length === 0) {
return true;
}
} else if (isPlainObject(target)) {
/* eslint-disable prefer-const */
for (var key in target) {
if (hasOwn(target, key)) {
return false;
}
}
/* eslint-enable prefer-const */
}
var paths = parsePath(path);
if (empty(paths)) {
return null;
return true;
}
var length = paths.length;
var ret = null;
var last = obj;
var i = 0;
while (i < length) {
var value = last[paths[i]];
if (value === undefined) {
last = null;
break;
}
last = value;
i++;
}
ret = last;
return ret;
}
var locales = Object.create(null); // locales store
function Asset (Vue) {
/**
* Register or retrieve a global locale definition.
* Get value from path string
*
* @param {String} id
* @param {Object | Function | Promise} definition
* @param {Function} cb
* @param {Object} obj
* @param {String} path
* @return value
*/
Vue.locale = function (id, definition, cb) {
if (definition === undefined) {
// gettter
return locales[id];
} else {
// setter
if (definition === null) {
locales[id] = undefined;
delete locales[id];
} else {
setLocale(id, definition, function (locale) {
if (locale) {
locales[id] = locale;
cb && cb();
} else {
warn('failed set `' + id + '` locale');
}
});
}
function getValue(obj, path) {
if (!isObject(obj)) {
return null;
}
};
}
function setLocale(id, definition, cb) {
var _this = this;
var paths = parsePath(path);
if (empty(paths)) {
return null;
}
if ((typeof definition === 'undefined' ? 'undefined' : babelHelpers.typeof(definition)) === 'object') {
// sync
cb(definition);
} else {
(function () {
var future = definition.call(_this);
if (typeof future === 'function') {
if (future.resolved) {
// cached
cb(future.resolved);
} else if (future.requested) {
// pool callbacks
future.pendingCallbacks.push(cb);
} else {
(function () {
future.requested = true;
var cbs = future.pendingCallbacks = [cb];
future(function (locale) {
// resolve
future.resolved = locale;
for (var i = 0, l = cbs.length; i < l; i++) {
cbs[i](locale);
}
}, function () {
// reject
cb();
});
})();
}
} else if (isPromise(future)) {
// promise
future.then(function (locale) {
// resolve
cb(locale);
}, function () {
// reject
cb();
}).catch(function (err) {
console.error(err);
cb();
});
var length = paths.length;
var ret = null;
var last = obj;
var i = 0;
while (i < length) {
var value = last[paths[i]];
if (value === undefined) {
last = null;
break;
}
})();
}
}
function Override (Vue, langVM) {
// override _init
var init = Vue.prototype._init;
Vue.prototype._init = function (options) {
var _this = this;
options = options || {};
var root = options._parent || options.parent || this;
var lang = root.$lang;
if (lang) {
this.$lang = lang;
} else {
this.$lang = langVM;
last = value;
i++;
}
this._langUnwatch = this.$lang.$watch('lang', function (a, b) {
update(_this);
});
init.call(this, options);
};
// override _destroy
var destroy = Vue.prototype._destroy;
Vue.prototype._destroy = function () {
if (this._langUnwatch) {
this._langUnwatch();
this._langUnwatch = null;
}
this.$lang = null;
destroy.apply(this, arguments);
};
}
function update(vm) {
var i = vm._watchers.length;
while (i--) {
vm._watchers[i].update(true); // shallow updates
ret = last;
return ret;
}
}
function Config (Vue, langVM) {
var Watcher = getWatcher(langVM);
var Dep = getDep(langVM);
function makeComputedGetter(getter, owner) {
var watcher = new Watcher(owner, getter, null, {
lazy: true
});
return function computedGetter() {
if (watcher.dirty) {
watcher.evaluate();
}
if (Dep.target) {
watcher.depend();
}
return watcher.value;
};
}
// define Vue.config.lang configration
Object.defineProperty(Vue.config, 'lang', {
enumerable: true,
configurable: true,
get: makeComputedGetter(function () {
return langVM.lang;
}, langVM),
set: Vue.util.bind(function (val) {
langVM.lang = val;
}, langVM)
});
return getValue;
}
/**
* String format template
* - Inspired:
* https://github.com/Matt-Esch/string-template/index.js
*/
var RE_NARGS = /(%|)\{([0-9a-zA-Z_]+)\}/g;
/**
* template
*
* @param {String} string
* @param {Array} ...args
* @return {String}
*/
function format (string) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
if (args.length === 1 && babelHelpers.typeof(args[0]) === 'object') {
args = args[0];
}
if (!args || !args.hasOwnProperty) {
args = {};
}
return string.replace(RE_NARGS, function (match, prefix, i, index) {
var result = void 0;
if (string[index - 1] === '{' && string[index + match.length] === '}') {
return i;
} else {
result = args.hasOwnProperty(i) ? args[i] : null;
if (result === null || result === undefined) {
return '';
}
return result;
}
});
}
/**
* extend

@@ -660,2 +672,4 @@ *

var format = Format(Vue);
var getValue = Path(Vue);

@@ -668,2 +682,4 @@ function parseArgs() {

var lang = Vue.config.lang;
var fallback = Vue.config.fallbackLang;
if (args.length === 1) {

@@ -684,3 +700,3 @@ if (isObject(args[0]) || Array.isArray(args[0])) {

return { lang: lang, params: args };
return { lang: lang, fallback: fallback, params: args };
}

@@ -728,5 +744,6 @@

var lang = _parseArgs.lang;
var fallback = _parseArgs.fallback;
var params = _parseArgs.params;
return translate(Vue.locale(lang), key, params) || warnDefault(key);
return translate(Vue.locale(lang), key, params) || translate(Vue.locale(fallback), key, params) || warnDefault(key);
};

@@ -754,5 +771,6 @@

var lang = _parseArgs2.lang;
var fallback = _parseArgs2.fallback;
var params = _parseArgs2.params;
return translate(this.$options.locales && this.$options.locales[lang], key, params) || translate(Vue.locale(lang), key, params) || warnDefault(key);
return translate(this.$options.locales && this.$options.locales[lang], key, params) || translate(this.$options.locales && this.$options.locales[fallback], key, params) || translate(Vue.locale(lang), key, params) || translate(Vue.locale(fallback), key, params) || warnDefault(key);
};

@@ -789,9 +807,6 @@

exports$2.Vue = exports$1.Vue = Vue;
setupLangVM(Vue, lang);
Asset(Vue);
Override(Vue, langVM);
Config(Vue, langVM);
Config(Vue, langVM, lang);
Extend(Vue);

@@ -809,3 +824,3 @@ }

plugin.version = '4.1.0';
plugin.version = '4.2.0';

@@ -812,0 +827,0 @@ if (typeof window !== 'undefined' && window.Vue) {

/*!
* vue-i18n v4.1.0
* vue-i18n v4.2.0
* (c) 2016 kazuya kawaguchi
* Released under the MIT License.
*/
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.VueI18n=t()}(this,function(){"use strict";function n(n,t){window.console&&(console.warn("[vue-i18n] "+n),t&&console.warn(t.stack))}function t(n,t){return A.call(n,t)}function e(n){if(null===n||void 0===n)return!0;if(Array.isArray(n)){if(n.length>0)return!1;if(0===n.length)return!0}else if(m.Vue.util.isPlainObject(n))for(var e in n)if(t(n,e))return!1;return!0}function r(n){if(!j){var t=n.$watch("__watcher__",function(n){});j=n._watchers[0].constructor,t()}return j}function o(n){return O||(O=n._data.__ob__.dep.constructor),O}function i(n){return n&&"function"==typeof n.then}function u(n){if(void 0===n)return"eof";var t=n.charCodeAt(0);switch(t){case 91:case 93:case 46:case 34:case 39:case 48:return n;case 95:case 36:return"ident";case 32:case 9:case 10:case 13:case 160:case 65279:case 8232:case 8233:return"ws"}return t>=97&&122>=t||t>=65&&90>=t?"ident":t>=49&&57>=t?"number":"else"}function a(n){var t=$.Vue.util,e=t.isLiteral,r=t.stripQuotes,o=n.trim();return"0"===n.charAt(0)&&isNaN(n)?!1:e(o)?r(o):"*"+o}function c(n){function t(){var t=n[r+1];return o===I&&"'"===t||o===L&&'"'===t?(r++,l="\\"+t,h[P](),!0):void 0}var e=[],r=-1,o=C,i=0,c=void 0,l=void 0,f=void 0,s=void 0,v=void 0,d=void 0,p=void 0,h=[];for(h[k]=function(){void 0!==f&&(e.push(f),f=void 0)},h[P]=function(){void 0===f?f=l:f+=l},h[S]=function(){h[P](),i++},h[U]=function(){if(i>0)i--,o=z,h[P]();else{if(i=0,f=a(f),f===!1)return!1;h[k]()}};null!=o;)if(r++,c=n[r],"\\"!==c||!t()){if(s=u(c),p=B[o],v=p[s]||p["else"]||Z,v===Z)return;if(o=v[0],d=h[v[1]],d&&(l=v[2],l=void 0===l?c:l,d()===!1))return;if(o===Q)return e.raw=n,e}}function l(n){var t=V[n];return t||(t=c(n),t&&(V[n]=t)),t}function f(n,t){var r=$.Vue.util.isObject;if(!r(n))return null;var o=l(t);if(e(o))return null;for(var i=o.length,u=null,a=n,c=0;i>c;){var f=a[o[c]];if(void 0===f){a=null;break}a=f,c++}return u=a}function s(t){t.locale=function(t,e,r){return void 0===e?D[t]:void(null===e?(D[t]=void 0,delete D[t]):v(t,e,function(e){e?(D[t]=e,r&&r()):n("failed set `"+t+"` locale")}))}}function v(n,t,e){var r=this;"object"===("undefined"==typeof t?"undefined":_["typeof"](t))?e(t):!function(){var n=t.call(r);"function"==typeof n?n.resolved?e(n.resolved):n.requested?n.pendingCallbacks.push(e):!function(){n.requested=!0;var t=n.pendingCallbacks=[e];n(function(e){n.resolved=e;for(var r=0,o=t.length;o>r;r++)t[r](e)},function(){e()})}():i(n)&&n.then(function(n){e(n)},function(){e()})["catch"](function(n){console.error(n),e()})}()}function d(n,t){var e=n.prototype._init;n.prototype._init=function(n){var r=this;n=n||{};var o=n._parent||n.parent||this,i=o.$lang;i?this.$lang=i:this.$lang=t,this._langUnwatch=this.$lang.$watch("lang",function(n,t){p(r)}),e.call(this,n)};var r=n.prototype._destroy;n.prototype._destroy=function(){this._langUnwatch&&(this._langUnwatch(),this._langUnwatch=null),this.$lang=null,r.apply(this,arguments)}}function p(n){for(var t=n._watchers.length;t--;)n._watchers[t].update(!0)}function h(n,t){function e(n,t){var e=new i(t,n,null,{lazy:!0});return function(){return e.dirty&&e.evaluate(),u.target&&e.depend(),e.value}}var i=r(t),u=o(t);Object.defineProperty(n.config,"lang",{enumerable:!0,configurable:!0,get:e(function(){return t.lang},t),set:n.util.bind(function(n){t.lang=n},t)})}function y(n){for(var t=arguments.length,e=Array(t>1?t-1:0),r=1;t>r;r++)e[r-1]=arguments[r];return 1===e.length&&"object"===_["typeof"](e[0])&&(e=e[0]),e&&e.hasOwnProperty||(e={}),n.replace(E,function(t,r,o,i){var u=void 0;return"{"===n[i-1]&&"}"===n[i+t.length]?o:(u=e.hasOwnProperty(o)?e[o]:null,null===u||void 0===u?"":u)})}function g(n){function t(){for(var t=arguments.length,e=Array(t),r=0;t>r;r++)e[r]=arguments[r];var i=n.config.lang;return 1===e.length?o(e[0])||Array.isArray(e[0])?e=e[0]:"string"==typeof e[0]&&(i=e[0]):2===e.length&&("string"==typeof e[0]&&(i=e[0]),(o(e[1])||Array.isArray(e[1]))&&(e=e[1])),{lang:i,params:e}}function e(n,t,e){if(!n)return null;var r=f(n,t)||n[t];return r?e?y(r,e):r:null}function r(n){return n}var o=n.util.isObject;return n.t=function(o){for(var i=arguments.length,u=Array(i>1?i-1:0),a=1;i>a;a++)u[a-1]=arguments[a];if(!o)return"";var c=t.apply(void 0,u),l=c.lang,f=c.params;return e(n.locale(l),o,f)||r(o)},n.prototype.$t=function(o){if(!o)return"";for(var i=arguments.length,u=Array(i>1?i-1:0),a=1;i>a;a++)u[a-1]=arguments[a];var c=t.apply(void 0,u),l=c.lang,f=c.params;return e(this.$options.locales&&this.$options.locales[l],o,f)||e(n.locale(l),o,f)||r(o)},n}function w(n){var t=(arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n.version&&Number(n.version.split(".")[0])||-1,"en");$.Vue=m.Vue=n,b(n,t),s(n),d(n,F),h(n,F),g(n)}function b(n,t){var e=n.config.silent;n.config.silent=!0,F||(F=new n({data:{lang:t}})),n.config.silent=e}var _={};_["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol?"symbol":typeof n};var m={},A=Object.prototype.hasOwnProperty,j=void 0,O=void 0,$={},V=Object.create(null),P=0,k=1,S=2,U=3,C=0,N=1,q=2,x=3,z=4,I=5,L=6,Q=7,Z=8,B=[];B[C]={ws:[C],ident:[x,P],"[":[z],eof:[Q]},B[N]={ws:[N],".":[q],"[":[z],eof:[Q]},B[q]={ws:[q],ident:[x,P]},B[x]={ident:[x,P],0:[x,P],number:[x,P],ws:[N,k],".":[q,k],"[":[z,k],eof:[Q,k]},B[z]={"'":[I,P],'"':[L,P],"[":[z,S],"]":[N,U],eof:Z,"else":[z,P]},B[I]={"'":[z,P],eof:Z,"else":[I,P]},B[L]={'"':[z,P],eof:Z,"else":[L,P]};var D=Object.create(null),E=/(%|)\{([0-9a-zA-Z_]+)\}/g,F=void 0;return w.version="4.1.0","undefined"!=typeof window&&window.Vue&&window.Vue.use(w),w});
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.VueI18n=t()}(this,function(){"use strict";function n(n,t){window.console&&(console.warn("[vue-i18n] "+n),t&&console.warn(t.stack))}function t(t){t.locale=function(t,r,o){return void 0===r?w[t]:void(null===r?(w[t]=void 0,delete w[t]):e(t,r,function(e){e?(w[t]=e,o&&o()):n("failed set `"+t+"` locale")}))}}function e(n,t,e){var o=this;"object"===("undefined"==typeof t?"undefined":b["typeof"](t))?e(t):!function(){var n=t.call(o);"function"==typeof n?n.resolved?e(n.resolved):n.requested?n.pendingCallbacks.push(e):!function(){n.requested=!0;var t=n.pendingCallbacks=[e];n(function(e){n.resolved=e;for(var r=0,o=t.length;o>r;r++)t[r](e)},function(){e()})}():r(n)&&n.then(function(n){e(n)},function(){e()})["catch"](function(n){console.error(n),e()})}()}function r(n){return n&&"function"==typeof n.then}function o(n,t){var e=n.prototype._init;n.prototype._init=function(n){var r=this;n=n||{};var o=n._parent||n.parent||this,a=o.$lang;a?this.$lang=a:this.$lang=t,this._langUnwatch=this.$lang.$watch("lang",function(n,t){i(r)}),e.call(this,n)};var r=n.prototype._destroy;n.prototype._destroy=function(){this._langUnwatch&&(this._langUnwatch(),this._langUnwatch=null),this.$lang=null,r.apply(this,arguments)}}function i(n){for(var t=n._watchers.length;t--;)n._watchers[t].update(!0)}function a(n){if(!_){var t=n.$watch("__watcher__",function(n){});_=n._watchers[0].constructor,t()}return _}function u(n){return m||(m=n._data.__ob__.dep.constructor),m}function l(n,t,e){function r(n,t){var e=new i(t,n,null,{lazy:!0});return function(){return e.dirty&&e.evaluate(),l.target&&e.depend(),e.value}}var o=n.util.bind,i=a(t),l=u(t);Object.defineProperty(n.config,"lang",{enumerable:!0,configurable:!0,get:r(function(){return t.lang},t),set:o(function(n){t.lang=n},t)}),A=e,Object.defineProperty(n.config,"fallbackLang",{enumerable:!0,configurable:!0,get:function(){return A},set:function(n){A=n}})}function c(n){function t(n){for(var t=arguments.length,r=Array(t>1?t-1:0),o=1;t>o;o++)r[o-1]=arguments[o];return 1===r.length&&"object"===b["typeof"](r[0])&&(r=r[0]),r&&r.hasOwnProperty||(r={}),n.replace($,function(t,o,i,a){var u=void 0;return"{"===n[a-1]&&"}"===n[a+t.length]?i:(u=e(r,i)?r[i]:null,null===u||void 0===u?"":u)})}var e=n.util.hasOwn;return t}function f(n){if(void 0===n)return"eof";var t=n.charCodeAt(0);switch(t){case 91:case 93:case 46:case 34:case 39:case 48:return n;case 95:case 36:return"ident";case 32:case 9:case 10:case 13:case 160:case 65279:case 8232:case 8233:return"ws"}return t>=97&&122>=t||t>=65&&90>=t?"ident":t>=49&&57>=t?"number":"else"}function s(n){var t=exports.Vue.util,e=t.isLiteral,r=t.stripQuotes,o=n.trim();return"0"===n.charAt(0)&&isNaN(n)?!1:e(o)?r(o):"*"+o}function v(n){function t(){var t=n[r+1];return o===N&&"'"===t||o===q&&'"'===t?(r++,u="\\"+t,h[O](),!0):void 0}var e=[],r=-1,o=U,i=0,a=void 0,u=void 0,l=void 0,c=void 0,v=void 0,d=void 0,p=void 0,h=[];for(h[k]=function(){void 0!==l&&(e.push(l),l=void 0)},h[O]=function(){void 0===l?l=u:l+=u},h[P]=function(){h[O](),i++},h[S]=function(){if(i>0)i--,o=L,h[O]();else{if(i=0,l=s(l),l===!1)return!1;h[k]()}};null!=o;)if(r++,a=n[r],"\\"!==a||!t()){if(c=f(a),p=Q[o],v=p[c]||p["else"]||I,v===I)return;if(o=v[0],d=h[v[1]],d&&(u=v[2],u=void 0===u?a:u,d()===!1))return;if(o===z)return e.raw=n,e}}function d(n){var t=j[n];return t||(t=v(n),t&&(j[n]=t)),t}function p(n){function t(n){if(null===n||void 0===n)return!0;if(Array.isArray(n)){if(n.length>0)return!1;if(0===n.length)return!0}else if(i(n))for(var t in n)if(a(n,t))return!1;return!0}function e(n,e){if(!o(n))return null;var r=d(e);if(t(r))return null;for(var i=r.length,a=null,u=n,l=0;i>l;){var c=u[r[l]];if(void 0===c){u=null;break}u=c,l++}return a=u}var r=n.util,o=r.isObject,i=r.isPlainObject,a=r.hasOwn;return e}function h(n){function t(){for(var t=arguments.length,e=Array(t),r=0;t>r;r++)e[r]=arguments[r];var i=n.config.lang,a=n.config.fallbackLang;return 1===e.length?o(e[0])||Array.isArray(e[0])?e=e[0]:"string"==typeof e[0]&&(i=e[0]):2===e.length&&("string"==typeof e[0]&&(i=e[0]),(o(e[1])||Array.isArray(e[1]))&&(e=e[1])),{lang:i,fallback:a,params:e}}function e(n,t,e){if(!n)return null;var r=a(n,t)||n[t];return r?e?i(r,e):r:null}function r(n){return n}var o=n.util.isObject,i=c(n),a=p(n);return n.t=function(o){for(var i=arguments.length,a=Array(i>1?i-1:0),u=1;i>u;u++)a[u-1]=arguments[u];if(!o)return"";var l=t.apply(void 0,a),c=l.lang,f=l.fallback,s=l.params;return e(n.locale(c),o,s)||e(n.locale(f),o,s)||r(o)},n.prototype.$t=function(o){if(!o)return"";for(var i=arguments.length,a=Array(i>1?i-1:0),u=1;i>u;u++)a[u-1]=arguments[u];var l=t.apply(void 0,a),c=l.lang,f=l.fallback,s=l.params;return e(this.$options.locales&&this.$options.locales[c],o,s)||e(this.$options.locales&&this.$options.locales[f],o,s)||e(n.locale(c),o,s)||e(n.locale(f),o,s)||r(o)},n}function g(n){var e=(arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n.version&&Number(n.version.split(".")[0])||-1,"en");y(n,e),t(n),o(n,Z),l(n,Z,e),h(n)}function y(n,t){var e=n.config.silent;n.config.silent=!0,Z||(Z=new n({data:{lang:t}})),n.config.silent=e}var b={};b["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol?"symbol":typeof n};var w=Object.create(null),_=void 0,m=void 0,A=void 0,$=/(%|)\{([0-9a-zA-Z_]+)\}/g,j=Object.create(null),O=0,k=1,P=2,S=3,U=0,V=1,x=2,C=3,L=4,N=5,q=6,z=7,I=8,Q=[];Q[U]={ws:[U],ident:[C,O],"[":[L],eof:[z]},Q[V]={ws:[V],".":[x],"[":[L],eof:[z]},Q[x]={ws:[x],ident:[C,O]},Q[C]={ident:[C,O],0:[C,O],number:[C,O],ws:[V,k],".":[x,k],"[":[L,k],eof:[z,k]},Q[L]={"'":[N,O],'"':[q,O],"[":[L,P],"]":[V,S],eof:I,"else":[L,O]},Q[N]={"'":[L,O],eof:I,"else":[N,O]},Q[q]={'"':[L,O],eof:I,"else":[q,O]};var Z=void 0;return g.version="4.2.0","undefined"!=typeof window&&window.Vue&&window.Vue.use(g),g});
{
"name": "vue-i18n",
"description": "Internationalization plugin for Vue.js",
"version": "4.1.0",
"version": "4.2.0",
"author": {

@@ -6,0 +6,0 @@ "name": "kazuya kawaguchi",

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

import { warn, isPromise } from './util'
import warn from './warn'

@@ -73,1 +73,12 @@ const locales = Object.create(null) // locales store

}
/**
* Forgiving check for a promise
*
* @param {Object} p
* @return {Boolean}
*/
function isPromise (p) {
return p && typeof p.then === 'function'
}

@@ -1,4 +0,7 @@

import { getWatcher, getDep } from './util'
import { getWatcher, getDep } from './observer'
export default function (Vue, langVM) {
let fallback // fallback lang
export default function (Vue, langVM, lang) {
const { bind } = Vue.util
const Watcher = getWatcher(langVM)

@@ -28,4 +31,13 @@ const Dep = getDep(langVM)

get: makeComputedGetter(() => { return langVM.lang }, langVM),
set: Vue.util.bind(val => { langVM.lang = val }, langVM)
set: bind(val => { langVM.lang = val }, langVM)
})
// define Vue.config.fallbackLang configration
fallback = lang
Object.defineProperty(Vue.config, 'fallbackLang', {
enumerable: true,
configurable: true,
get: () => { return fallback },
set: val => { fallback = val }
})
}

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

import { warn } from './util'
import format from './format'
import { getValue } from './path'
import warn from './warn'
import Format from './format'
import Path from './path'

@@ -15,5 +15,9 @@

const { isObject } = Vue.util
const format = Format(Vue)
const getValue = Path(Vue)
function parseArgs (...args) {
let lang = Vue.config.lang
const fallback = Vue.config.fallbackLang
if (args.length === 1) {

@@ -34,3 +38,3 @@ if (isObject(args[0]) || Array.isArray(args[0])) {

return { lang, params: args }
return { lang, fallback, params: args }
}

@@ -67,4 +71,6 @@

const { lang, params } = parseArgs(...args)
return translate(Vue.locale(lang), key, params) || warnDefault(key)
const { lang, fallback, params } = parseArgs(...args)
return translate(Vue.locale(lang), key, params)
|| translate(Vue.locale(fallback), key, params)
|| warnDefault(key)
}

@@ -84,5 +90,7 @@

const { lang, params } = parseArgs(...args)
const { lang, fallback, params } = parseArgs(...args)
return translate(this.$options.locales && this.$options.locales[lang], key, params)
|| translate(this.$options.locales && this.$options.locales[fallback], key, params)
|| translate(Vue.locale(lang), key, params)
|| translate(Vue.locale(fallback), key, params)
|| warnDefault(key)

@@ -89,0 +97,0 @@ }

@@ -10,34 +10,40 @@ /**

/**
* template
*
* @param {String} string
* @param {Array} ...args
* @return {String}
*/
export default function (Vue) {
const { hasOwn } = Vue.util
export default function (string, ...args) {
if (args.length === 1 && typeof args[0] === 'object') {
args = args[0]
}
/**
* template
*
* @param {String} string
* @param {Array} ...args
* @return {String}
*/
if (!args || !args.hasOwnProperty) {
args = {}
}
function template (string, ...args) {
if (args.length === 1 && typeof args[0] === 'object') {
args = args[0]
}
return string.replace(RE_NARGS, (match, prefix, i, index) => {
let result
if (!args || !args.hasOwnProperty) {
args = {}
}
if (string[index - 1] === '{'
&& string[index + match.length] === '}') {
return i
} else {
result = args.hasOwnProperty(i) ? args[i] : null
if (result === null || result === undefined) {
return ''
return string.replace(RE_NARGS, (match, prefix, i, index) => {
let result
if (string[index - 1] === '{'
&& string[index + match.length] === '}') {
return i
} else {
result = hasOwn(args, i) ? args[i] : null
if (result === null || result === undefined) {
return ''
}
return result
}
})
}
return result
}
})
return template
}

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

import util, { warn } from './util'
import path from './path'
import warn from './warn'
import Asset from './asset'

@@ -35,9 +34,6 @@ import Override from './override'

path.Vue = util.Vue = Vue
setupLangVM(Vue, lang)
Asset(Vue)
Override(Vue, langVM)
Config(Vue, langVM)
Config(Vue, langVM, lang)
Extend(Vue)

@@ -55,3 +51,3 @@ }

plugin.version = '4.1.0'
plugin.version = '4.2.0'

@@ -58,0 +54,0 @@ export default plugin

@@ -7,9 +7,2 @@ /**

import { empty } from './util'
// export default for holding the Vue reference
const exports = {}
export default exports
// cache

@@ -269,34 +262,56 @@ const pathCache = Object.create(null)

/**
* Get value from path string
*
* @param {Object} obj
* @param {String} path
* @return value
*/
export default function (Vue) {
const { isObject, isPlainObject, hasOwn } = Vue.util
export function getValue (obj, path) {
const { isObject } = exports.Vue.util
function empty (target) {
if (target === null || target === undefined) { return true }
if (!isObject(obj)) { return null }
if (Array.isArray(target)) {
if (target.length > 0) { return false }
if (target.length === 0) { return true }
} else if (isPlainObject(target)) {
/* eslint-disable prefer-const */
for (let key in target) {
if (hasOwn(target, key)) { return false }
}
/* eslint-enable prefer-const */
}
const paths = parsePath(path)
if (empty(paths)) { return null }
return true
}
const length = paths.length
let ret = null
let last = obj
let i = 0
while (i < length) {
const value = last[paths[i]]
if (value === undefined) {
last = null
break
/**
* Get value from path string
*
* @param {Object} obj
* @param {String} path
* @return value
*/
function getValue (obj, path) {
if (!isObject(obj)) { return null }
const paths = parsePath(path)
if (empty(paths)) { return null }
const length = paths.length
let ret = null
let last = obj
let i = 0
while (i < length) {
const value = last[paths[i]]
if (value === undefined) {
last = null
break
}
last = value
i++
}
last = value
i++
ret = last
return ret
}
ret = last
return ret
return getValue
}
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