Comparing version 0.3.0 to 0.4.0
21
index.js
@@ -10,3 +10,3 @@ 'use strict'; | ||
const dotProp = require('dot-prop'); | ||
const CacheConf = require('./lib/cache-conf'); | ||
const CacheConf = require('cache-conf'); | ||
@@ -100,3 +100,3 @@ const alfy = module.exports; | ||
if (process.env.AVA) { | ||
alfy.alfred.data = alfy.alfred.cache = os.tmpdir(); | ||
alfy.alfred.data = alfy.alfred.cache = os.tmpdir() + '/' + Date.now(); | ||
} | ||
@@ -114,2 +114,6 @@ | ||
alfy.fetch = (url, opts) => { | ||
opts = Object.assign({ | ||
json: true | ||
}, opts); | ||
if (typeof url !== 'string') { | ||
@@ -119,5 +123,5 @@ return Promise.reject(new TypeError(`Expected \`url\` to be a \`string\`, got \`${typeof url}\``)); | ||
opts = Object.assign({ | ||
json: true | ||
}, opts); | ||
if (opts.transform && typeof opts.transform !== 'function') { | ||
return Promise.reject(new TypeError(`Expected \`transform\` to be a \`function\`, got \`${typeof opts.transform}\``)); | ||
} | ||
@@ -133,8 +137,9 @@ const rawKey = url + JSON.stringify(opts); | ||
return got(url, opts) | ||
.then(res => { | ||
.then(res => opts.transform ? opts.transform(res.body) : res.body) | ||
.then(data => { | ||
if (opts.maxAge) { | ||
alfy.cache.set(key, res.body, {maxAge: opts.maxAge}); | ||
alfy.cache.set(key, data, {maxAge: opts.maxAge}); | ||
} | ||
return res.body; | ||
return data; | ||
}) | ||
@@ -141,0 +146,0 @@ .catch(err => { |
{ | ||
"name": "alfy", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Create Alfred workflows with ease", | ||
@@ -23,4 +23,3 @@ "license": "MIT", | ||
"index.js", | ||
"run-node.sh", | ||
"lib" | ||
"run-node.sh" | ||
], | ||
@@ -40,5 +39,6 @@ "keywords": [ | ||
"dependencies": { | ||
"clean-stack": "^0.1.0", | ||
"cache-conf": "^0.2.0", | ||
"clean-stack": "^1.0.0", | ||
"conf": "^0.11.0", | ||
"dot-prop": "^3.0.0", | ||
"dot-prop": "^4.0.0", | ||
"got": "^6.3.0", | ||
@@ -45,0 +45,0 @@ "hook-std": "^0.2.0", |
@@ -71,2 +71,39 @@ # ![Alfy](https://cdn.rawgit.com/sindresorhus/alfy/4b50f0323dd99eafdd34523dc8de0680be04e049/media/header.svg) | ||
## Publish to npm | ||
Instead of publishing your packages to [Packal](http://www.packal.org), you can also publish them to [npm](https://npmjs.org). This way, your packages are only one simple `npm install` command away. | ||
Add [alfred-link](https://github.com/samverschueren/alfred-link) as dependency to your package and add it as `postinstall` script. | ||
```json | ||
{ | ||
"name": "alfred-unicorn", | ||
"version": "1.0.0", | ||
"description": "My awesome unicorn workflow", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"scripts": { | ||
"postinstall": "alfred-link" | ||
}, | ||
"dependencies": { | ||
"alfy": "*", | ||
"alfred-link": "*" | ||
} | ||
} | ||
``` | ||
> Tip: Prefix your workflow with `alfred-` to make them easy searchable through npm. | ||
You can remove [these](https://github.com/samverschueren/alfred-link#infoplist) properties from your `info.plist` file as they are being added automatically at install time. | ||
After publishing your workflow to npm, your users can easily install the workflow. | ||
``` | ||
$ npm install --global alfred-unicorn | ||
``` | ||
## API | ||
@@ -229,2 +266,30 @@ | ||
###### transform | ||
Type: `Function` | ||
Transform the response before it gets cached. | ||
```js | ||
alfy.fetch('https://api.foo.com', { | ||
transform: body => { | ||
body.foo = 'bar'; | ||
return body; | ||
} | ||
}) | ||
``` | ||
You can also return a Promise. | ||
```js | ||
const xml2js = require('xmls2js'); | ||
const pify = require('pify'); | ||
const parseString = pify(xml2js.parseString); | ||
alfy.fetch('https://api.foo.com', { | ||
transform: body => parseString(body) | ||
}) | ||
``` | ||
#### config | ||
@@ -231,0 +296,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17339
472
7
5
133
+ Addedcache-conf@^0.2.0
+ Addedcache-conf@0.2.0(transitive)
+ Addedclean-stack@1.3.0(transitive)
+ Addeddot-prop@4.2.1(transitive)
- Removedclean-stack@0.1.1(transitive)
Updatedclean-stack@^1.0.0
Updateddot-prop@^4.0.0