├── docs
├── _config.yml
├── 404.html
└── README.md
├── .gitignore
├── .travis.yml
├── .eslintrc
├── rollup.config.js
├── index.js
├── __tests__
└── test.js
├── README.md
├── LICENSE
├── package.json
└── dist
├── vueo.min.js
└── vueo.js
/docs/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | *.log
3 | yarn.lock
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: node_js
3 | node_js: stable
4 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "vue",
3 | "globals": {
4 | "test": true,
5 | "expect": true
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import buble from 'rollup-plugin-buble'
2 | import nodeResolve from 'rollup-plugin-node-resolve'
3 | import commonjs from 'rollup-plugin-commonjs'
4 |
5 | export default {
6 | entry: 'index.js',
7 | dest: 'dist/vueo.js',
8 | format: 'umd',
9 | moduleName: 'Vueo',
10 | plugins: [buble(), nodeResolve(), commonjs()]
11 | }
12 |
--------------------------------------------------------------------------------
/docs/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Vueo - Easy to get value from vue instance via object paths
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import get from 'get-value'
2 | import has from 'has-value'
3 |
4 | export default function install (Vue) {
5 | Vue.at = get
6 | Vue.has = has
7 | Vue.prototype.$at = function (...args) {
8 | return args.length === 1
9 | ? get(this._self, args[0])
10 | : get.apply(this, args)
11 | }
12 | Vue.prototype.$has = function (...args) {
13 | return args.length === 1
14 | ? has(this._self, args[0])
15 | : has.apply(this, args)
16 | }
17 | }
18 |
19 | if (typeof window !== 'undefined' && window.Vue) {
20 | window.Vue.use(install)
21 | }
22 |
--------------------------------------------------------------------------------
/__tests__/test.js:
--------------------------------------------------------------------------------
1 | var Vue = require('vue')
2 | var Vueo = require('../dist/vueo')
3 |
4 | Vue.use(Vueo)
5 | var vm = new Vue({
6 | data () {
7 | return { a: { b: { c: [{ d: 1, e: { f: 'g' }}] }}}
8 | }
9 | })
10 |
11 | test('installed', () => {
12 | expect(Vue.has).toBeDefined()
13 | expect(Vue.at).toBeDefined()
14 | expect(Vue.prototype.$at).toBeDefined()
15 | expect(Vue.prototype.$has).toBeDefined()
16 | })
17 |
18 | test('`at` is work', () => {
19 | expect(vm.$at('a.b.c.0.d')).toBe(1)
20 | expect(vm.$at('a.b.c.0.e.f')).toBe('g')
21 | expect(vm.$at('a.b.c.1')).toBe(undefined)
22 |
23 | expect(vm.$at(vm.a, 'b.c[0].d'), 1)
24 | })
25 |
26 | test('`has` is work', () => {
27 | expect(vm.$has('a.b.c.0.d')).toBe(true)
28 | expect(vm.$has('a.b.c.0.e.f')).toBe(true)
29 | expect(vm.$has('a.b.c.1')).toBe(false)
30 |
31 | expect(vm.$has(vm.a, 'b.c.0.e.f')).toBe(true)
32 | })
33 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vueo
2 | [](https://travis-ci.org/QingWei-Li/vueo)
3 | [](https://www.npmjs.com/package/vueo)
4 |
5 | > 🍟 Easy to get value from vue instance via object paths.
6 |
7 | ## Documentation
8 | https://qingwei-li.github.io/vueo
9 |
10 | ## Installation
11 | ```shell
12 | npm i vueo -S
13 | ```
14 |
15 | ## Usage
16 | ```javascript
17 | import Vue from 'vue'
18 | import Vueo from 'vueo'
19 |
20 | Vue.use(Vueo)
21 |
22 | new Vue({
23 | data () {
24 | return { a: { b: [ {c: 1} ] } }
25 | },
26 |
27 | created () {
28 | this.$has('a.b.0') // true
29 | this.$has('a.b.1') // false
30 | this.$at('a.b.0.c') // 1
31 | this.$at('a.b.1.c') // undefined
32 | }
33 | })
34 | ```
35 |
36 | ## API
37 | - vm#$at(path)
38 | - vm#$at(obj, path)
39 | - vm#$has(path)
40 | - vm#$has(obj, path)
41 |
42 | ## Read more
43 | - https://github.com/jonschlinkert/get-value
44 | - https://github.com/jonschlinkert/has-value
45 |
46 | ## License
47 | MIT
48 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 cinwell.li
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | # Vueo
2 |
3 | > 🍟 Easy to get value from vue instance via object paths.
4 |
5 | ## Installation
6 | ```shell
7 | npm i vueo -S
8 | ```
9 |
10 | ## Import
11 |
12 | ```javascript
13 | import Vue from 'vue'
14 | import Vueo from 'vueo'
15 |
16 | Vue.use(Vueo)
17 | ```
18 |
19 | Or import via script tag
20 |
21 | ```html
22 |
23 |
24 | ```
25 |
26 | ## Usage
27 |
28 | [Live demo](https://jsfiddle.net/cinwell_li/20v7ehtg/)
29 |
30 | ```javascript
31 | new Vue({
32 | data () {
33 | return {
34 | a: [ { key: 'value' } ],
35 | b: { c: 1 }
36 | }
37 | },
38 |
39 | created() {
40 | this.$at('a.0.key') // 'value'
41 | this.$at('a.1.key') // undefined
42 |
43 | this.$at(this.a, '0.key') // 'value'
44 |
45 | this.$has('b') // true
46 | this.$has('a.1') // false
47 | }
48 | })
49 | ```
50 |
51 | ## API
52 | - vm#$at(path)
53 | - vm#$at(obj, path)
54 | - vm#$has(path)
55 | - vm#$has(obj, path)
56 |
57 | ## Read more
58 | - https://github.com/jonschlinkert/get-value
59 | - https://github.com/jonschlinkert/has-value
60 |
61 | ## License
62 | MIT
63 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vueo",
3 | "version": "0.3.2",
4 | "description": "Easy to get value from vue instance via object paths.",
5 | "main": "dist/vueo.js",
6 | "jsnext:main": "index.js",
7 | "scripts": {
8 | "build": "rollup -c && uglifyjs dist/vueo.js > dist/vueo.min.js",
9 | "test": "npm run build && eslint index.js __tests__ && jest"
10 | },
11 | "files": [
12 | "dist",
13 | "index.js"
14 | ],
15 | "keywords": [
16 | "vue",
17 | "plugin",
18 | "object",
19 | "path",
20 | "value"
21 | ],
22 | "author": "qingwei-li (https://github.com/QingWei-Li)",
23 | "repository": {
24 | "type": "git",
25 | "url": "git+https://github.com/QingWei-Li/vueo.git"
26 | },
27 | "license": "MIT",
28 | "dependencies": {
29 | "get-value": "^2.0.6",
30 | "has-value": "^0.3.1"
31 | },
32 | "devDependencies": {
33 | "eslint": "^3.10.2",
34 | "eslint-config-vue": "^2.0.1",
35 | "eslint-plugin-vue": "^1.0.0",
36 | "jest": "^17.0.3",
37 | "rollup": "^0.36.3",
38 | "rollup-plugin-buble": "^0.14.0",
39 | "rollup-plugin-commonjs": "^5.0.5",
40 | "rollup-plugin-node-resolve": "^2.0.0",
41 | "uglify-js": "^2.7.4",
42 | "vue": "^2.1.0"
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/dist/vueo.min.js:
--------------------------------------------------------------------------------
1 | (function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?module.exports=factory():typeof define==="function"&&define.amd?define(factory):global.Vueo=factory()})(this,function(){"use strict";var index=function(obj,prop,a,b,c){if(!isObject$1(obj)||!prop){return obj}prop=toString(prop);if(a){prop+="."+toString(a)}if(b){prop+="."+toString(b)}if(c){prop+="."+toString(c)}if(prop in obj){return obj[prop]}var segs=prop.split(".");var len=segs.length;var i=-1;while(obj&&++i
9 | *
10 | * Copyright (c) 2014-2015, Jon Schlinkert.
11 | * Licensed under the MIT License.
12 | */
13 |
14 | var index = function(obj, prop, a, b, c) {
15 | if (!isObject$1(obj) || !prop) {
16 | return obj;
17 | }
18 |
19 | prop = toString(prop);
20 |
21 | // allowing for multiple properties to be passed as
22 | // a string or array, but much faster (3-4x) than doing
23 | // `[].slice.call(arguments)`
24 | if (a) { prop += '.' + toString(a); }
25 | if (b) { prop += '.' + toString(b); }
26 | if (c) { prop += '.' + toString(c); }
27 |
28 | if (prop in obj) {
29 | return obj[prop];
30 | }
31 |
32 | var segs = prop.split('.');
33 | var len = segs.length;
34 | var i = -1;
35 |
36 | while (obj && (++i < len)) {
37 | var key = segs[i];
38 | while (key[key.length - 1] === '\\') {
39 | key = key.slice(0, -1) + '.' + segs[++i];
40 | }
41 | obj = obj[key];
42 | }
43 | return obj;
44 | };
45 |
46 | function isObject$1(val) {
47 | return val !== null && (typeof val === 'object' || typeof val === 'function');
48 | }
49 |
50 | function toString(val) {
51 | if (!val) { return ''; }
52 | if (Array.isArray(val)) {
53 | return val.join('.');
54 | }
55 | return val;
56 | }
57 |
58 | var toString$1 = {}.toString;
59 |
60 | var index$4 = Array.isArray || function (arr) {
61 | return toString$1.call(arr) == '[object Array]';
62 | };
63 |
64 | var isArray = index$4;
65 |
66 | var index$2 = function isObject(val) {
67 | return val != null && typeof val === 'object' && isArray(val) === false;
68 | };
69 |
70 | /*!
71 | * has-values
72 | *
73 | * Copyright (c) 2014-2015, Jon Schlinkert.
74 | * Licensed under the MIT License.
75 | */
76 |
77 | var index$6 = function hasValue(o, noZero) {
78 | if (o === null || o === undefined) {
79 | return false;
80 | }
81 |
82 | if (typeof o === 'boolean') {
83 | return true;
84 | }
85 |
86 | if (typeof o === 'number') {
87 | if (o === 0 && noZero === true) {
88 | return false;
89 | }
90 | return true;
91 | }
92 |
93 | if (o.length !== undefined) {
94 | return o.length !== 0;
95 | }
96 |
97 | for (var key in o) {
98 | if (o.hasOwnProperty(key)) {
99 | return true;
100 | }
101 | }
102 | return false;
103 | };
104 |
105 | var isObject$2 = index$2;
106 | var hasValues = index$6;
107 | var get$1 = index;
108 |
109 | var index$1 = function(obj, prop, noZero) {
110 | if (isObject$2(obj)) {
111 | return hasValues(get$1(obj, prop), noZero);
112 | }
113 | return hasValues(obj, prop);
114 | };
115 |
116 | function install (Vue) {
117 | Vue.at = index;
118 | Vue.has = index$1;
119 | Vue.prototype.$at = function () {
120 | var args = [], len = arguments.length;
121 | while ( len-- ) args[ len ] = arguments[ len ];
122 |
123 | return args.length === 1
124 | ? index(this._self, args[0])
125 | : index.apply(this, args)
126 | };
127 | Vue.prototype.$has = function () {
128 | var args = [], len = arguments.length;
129 | while ( len-- ) args[ len ] = arguments[ len ];
130 |
131 | return args.length === 1
132 | ? index$1(this._self, args[0])
133 | : index$1.apply(this, args)
134 | };
135 | }
136 |
137 | if (typeof window !== 'undefined' && window.Vue) {
138 | window.Vue.use(install);
139 | }
140 |
141 | return install;
142 |
143 | })));
144 |
--------------------------------------------------------------------------------