Skip to content

Commit

Permalink
Merge branch '0.1.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
freearhey committed Dec 1, 2016
2 parents 932713e + bbbf118 commit 8d34f47
Show file tree
Hide file tree
Showing 13 changed files with 367 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules
npm-debug.log
example.html
npm-debug.log
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- 6.1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Simply include `vue2-filters` after Vue and it will install itself automatically

```html
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/vue2-filters/0.1.3/vue2-filters.min.js"></script>
<script src="https://cdn.jsdelivr.net/vue2-filters/0.1.4/vue2-filters.min.js"></script>
```

### NPM
Expand Down
38 changes: 25 additions & 13 deletions dist/vue2-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ util.convertArray = function (value) {
}
}

function multiIndex(obj,is) { // obj,['1','2','3'] -> ((obj['1'])['2'])['3']
return is.length ? multiIndex(obj[is[0]],is.slice(1)) : obj
}

util.getPath = function(obj,is) { // obj,'1.2.3' -> multiIndex(obj,['1','2','3'])
return multiIndex(obj,is.split('.'))
}

/**
* Strict object type check. Only returns true
* for plain JavaScript objects.
Expand Down Expand Up @@ -283,7 +291,7 @@ function filterBy (arr, search) {
while (j--) {
key = keys[j]
if ((key === '$key' && contains(item.$key, search)) ||
contains(item[key], search)) {
contains(__WEBPACK_IMPORTED_MODULE_0__util_index__["a" /* default */].getPath(val, key), search)) {
res.push(item)
break
}
Expand Down Expand Up @@ -361,7 +369,7 @@ function limitBy (arr, n, offset) {

function orderBy (arr) {
var comparator = null
var sortKey
var sortKeys
arr = __WEBPACK_IMPORTED_MODULE_0__util_index__["a" /* default */].convertArray(arr)

// determine order (last argument)
Expand All @@ -375,7 +383,7 @@ function orderBy (arr) {
}

// determine sortKeys & comparator
var firstArg = sortKey = args[0]
var firstArg = args[0]
if (!firstArg) {
return arr
} else if (typeof firstArg === 'function') {
Expand All @@ -384,20 +392,25 @@ function orderBy (arr) {
return firstArg(a, b) * order
}
} else {
comparator = function (a, b) {
return baseCompare(a, b)
// string keys. flatten first
sortKeys = Array.prototype.concat.apply([], args)
comparator = function (a, b, i) {
i = i || 0
return i >= sortKeys.length - 1
? baseCompare(a, b, i)
: baseCompare(a, b, i) || comparator(a, b, i + 1)
}
}

function baseCompare(a, b) {
function baseCompare (a, b, sortKeyIndex) {
const sortKey = sortKeys[sortKeyIndex]
if (sortKey) {
if (a[sortKey] > b[sortKey]) {
return order
}
if (a[sortKey] < b[sortKey]) {
return -order
if (sortKey !== '$key') {
if (__WEBPACK_IMPORTED_MODULE_0__util_index__["a" /* default */].isObject(a) && '$value' in a) a = a.$value
if (__WEBPACK_IMPORTED_MODULE_0__util_index__["a" /* default */].isObject(b) && '$value' in b) b = b.$value
}
return 0
a = __WEBPACK_IMPORTED_MODULE_0__util_index__["a" /* default */].isObject(a) ? __WEBPACK_IMPORTED_MODULE_0__util_index__["a" /* default */].getPath(a, sortKey) : a
b = __WEBPACK_IMPORTED_MODULE_0__util_index__["a" /* default */].isObject(b) ? __WEBPACK_IMPORTED_MODULE_0__util_index__["a" /* default */].getPath(b, sortKey) : b
}
return a === b ? 0 : a > b ? order : -order
}
Expand Down Expand Up @@ -469,7 +482,6 @@ function currency (value, currency, decimals) {

function pluralize (value) {
var args = __WEBPACK_IMPORTED_MODULE_0__util_index__["a" /* default */].toArray(arguments, 1)
args.shift()
return args.length > 1
? (args[value % 10 - 1] || args[args.length - 1])
: (args[0] + (value === 1 ? '' : 's'))
Expand Down
2 changes: 1 addition & 1 deletion dist/vue2-filters.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "vue2-filters",
"version": "0.1.3",
"version": "0.1.4",
"description": "The list of standard filters Vue.js 1.* adapted for use in Vue.js 2.*",
"main": "dist/vue2-filters.js",
"scripts": {
"build": "webpack src/index.js dist/vue2-filters.min.js --output-library-target umd --optimize-minimize",
"dev": "webpack src/index.js dist/vue2-filters.js --output-library-target umd --watch",
"test": "echo \"Error: no test specified\" && exit 1"
"build": "node_modules/.bin/webpack src/index.js dist/vue2-filters.min.js --output-library-target umd --optimize-minimize",
"dev": "node_modules/.bin/webpack src/index.js dist/vue2-filters.js --output-library-target umd --watch",
"test": "node_modules/.bin/karma start test/karma.conf.js --single-run --no-auto-watch"
},
"keywords": [
"vuejs",
Expand All @@ -17,6 +17,14 @@
"author": "Arhey",
"license": "MIT",
"devDependencies": {
"babel-core": "^6.18.2",
"babel-loader": "^6.2.8",
"babel-preset-es2015": "^6.18.0",
"jasmine": "^2.5.2",
"karma": "^1.3.0",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.2",
"karma-webpack": "^1.8.0",
"webpack": "^2.1.0-beta.27"
},
"dependencies": {}
Expand Down
2 changes: 1 addition & 1 deletion src/array/filterBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function filterBy (arr, search) {
while (j--) {
key = keys[j]
if ((key === '$key' && contains(item.$key, search)) ||
contains(item[key], search)) {
contains(util.getPath(val, key), search)) {
res.push(item)
break
}
Expand Down
27 changes: 16 additions & 11 deletions src/array/orderBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import util from '../util/index'

function orderBy (arr) {
var comparator = null
var sortKey
var sortKeys
arr = util.convertArray(arr)

// determine order (last argument)
Expand All @@ -23,7 +23,7 @@ function orderBy (arr) {
}

// determine sortKeys & comparator
var firstArg = sortKey = args[0]
var firstArg = args[0]
if (!firstArg) {
return arr
} else if (typeof firstArg === 'function') {
Expand All @@ -32,20 +32,25 @@ function orderBy (arr) {
return firstArg(a, b) * order
}
} else {
comparator = function (a, b) {
return baseCompare(a, b)
// string keys. flatten first
sortKeys = Array.prototype.concat.apply([], args)
comparator = function (a, b, i) {
i = i || 0
return i >= sortKeys.length - 1
? baseCompare(a, b, i)
: baseCompare(a, b, i) || comparator(a, b, i + 1)
}
}

function baseCompare(a, b) {
function baseCompare (a, b, sortKeyIndex) {
const sortKey = sortKeys[sortKeyIndex]
if (sortKey) {
if (a[sortKey] > b[sortKey]) {
return order
}
if (a[sortKey] < b[sortKey]) {
return -order
if (sortKey !== '$key') {
if (util.isObject(a) && '$value' in a) a = a.$value
if (util.isObject(b) && '$value' in b) b = b.$value
}
return 0
a = util.isObject(a) ? util.getPath(a, sortKey) : a
b = util.isObject(b) ? util.getPath(b, sortKey) : b
}
return a === b ? 0 : a > b ? order : -order
}
Expand Down
1 change: 0 additions & 1 deletion src/other/pluralize.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import util from '../util/index'

function pluralize (value) {
var args = util.toArray(arguments, 1)
args.shift()
return args.length > 1
? (args[value % 10 - 1] || args[args.length - 1])
: (args[0] + (value === 1 ? '' : 's'))
Expand Down
8 changes: 8 additions & 0 deletions src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ util.convertArray = function (value) {
}
}

function multiIndex(obj,is) { // obj,['1','2','3'] -> ((obj['1'])['2'])['3']
return is.length ? multiIndex(obj[is[0]],is.slice(1)) : obj
}

util.getPath = function(obj,is) { // obj,'1.2.3' -> multiIndex(obj,['1','2','3'])
return multiIndex(obj,is.split('.'))
}

/**
* Strict object type check. Only returns true
* for plain JavaScript objects.
Expand Down
Loading

0 comments on commit 8d34f47

Please sign in to comment.