Skip to content

Typescript #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.DS_Store
26 changes: 16 additions & 10 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
AFL-2.0
MIT License

Copyright 2017 Yu-An Lin

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

http://www.apache.org/licenses/LICENSE-2.0
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
89 changes: 51 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,74 @@
# vue-lodash
A small wrapper for integrating lodash to Vuejs
(Inspired by vue-axios plugin by imcvampire)
> A small wrapper for integrating lodash to Vuejs

## When to use it and when not to:
Use it when using lodash extensively in lots of file.
(Inspired by [vue-axios](https://github.com/imcvampire/vue-axios) plugin)

Don't use it if just want some simple functions from lodash. (My recommendation is to install individual small function from lodash.)
## Install

## For vue-lodash 2.x
```
npm install --save vue-lodash
npm install --save vue-lodash lodash
```

And in your entry file:
```
## Usage

```javascript
import Vue from 'vue'
import VueLodash from 'vue-lodash'
import lodash from 'lodash'

const options = { name: 'lodash' } // customize the way you want to call it
// name is optional
Vue.use(VueLodash, { name: 'custom' , lodash: { map, random } })

Vue.use(VueLodash, options) // options is optional
new Vue({
el: '#app',
methods: {
test() {
console.log(this.lodash.random(20))
console.log(this._.random(20))
console.log(this.custom.random(20))
},
}
})
console.log(Vue.lodash.random(20))
console.log(Vue._.random(20))
console.log(Vue.custom.random(20))
```

#### Usage:
This wrapper bind `lodash` to `Vue` or `this` if you're using single file component.
## Typescript

You can use `lodash` like this:
```
// with name option
Vue.myCustomName.random(20)
this.myCustomName.random(20)
Using __custom name__ with typescript is currently unsupported without casting.

// default (it works even with custom name)
Vue._.random(20)
this._.random(20)
```
```typescript
import Vue from 'vue'
import VueLodash from 'vue-lodash'
import lodash from 'lodash'

Vue.use(VueLodash, { name: 'custom', lodash: { map, random } })

## For vue-lodash 1.x
```
npm install --save lodash vue-lodash
new Vue({
el: '#app',
methods: {
testLodash() {
console.log(this.lodash.random(20))
console.log(this._.random(20))
console.log((this as any).custom.random(20))
},
}
})
console.log(Vue.lodash.random(20))
console.log(Vue._.random(20))
console.log((Vue as any).custom.random(20))
```

And in your entry file:
```
import Vue from 'vue'
import lodash from 'lodash'
import VueLodash from 'vue-lodash'
## Tree shaking with lodash

Vue.use(VueLodash, lodash)
```
Only import the packages you need, note that lodash tree shaking has to do import with path to module.

### Usage:
This wrapper bind `lodash` to `Vue` or `this` if you're using single file component.
```typescript
import Vue from 'vue'
import VueLodash from 'vue-lodash'
import random from 'lodash/random'
import map from 'lodash/map'

You can `lodash` like this:
```
Vue._.random(20)
this._.random(20)
Vue.use(VueLodash, { name: 'custom', lodash: { map, random } })
```
1 change: 1 addition & 0 deletions dist/bundle.js

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

49 changes: 0 additions & 49 deletions dist/vue-lodash.es5.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/vue-lodash.min.js

This file was deleted.

16 changes: 0 additions & 16 deletions gulpfile.js

This file was deleted.

21 changes: 21 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Vue, { PluginFunction, PluginObject } from "vue"
import { LoDashStatic } from "lodash"

declare module "vue/types/vue" {

interface Vue {
lodash: LoDashStatic
_: LoDashStatic
}

interface VueConstructor {
lodash: LoDashStatic
_: LoDashStatic
}
}

declare class VueLodash {
static install: PluginFunction<LoDashStatic>
}

export default VueLodash
Loading