From 5e6aee6f38bbc05ef2a4961d03c57660b38a1707 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 16 Aug 2014 19:42:20 +0200 Subject: [PATCH] add support for supplying cookies as an object in the API --- index.js | 6 +++++- readme.md | 4 ++-- test/serverForCookieTests.js | 4 ++-- test/test.js | 20 ++++++++++++++------ 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 08456f9..f1c2db4 100644 --- a/index.js +++ b/index.js @@ -30,7 +30,11 @@ function Pageres(options) { } this.options = assign({}, options); - this.options.cookies = (this.options.cookies || []).map(parseCookiePhantomjs); + + this.options.cookies = (this.options.cookies || []).map(function (el) { + return typeof el === 'string' ? parseCookiePhantomjs(el) : el; + }); + this.options.name = this.options.name || '<%= url %>-<%= size %><%= crop %>'; this.stats = {}; diff --git a/readme.md b/readme.md index 9406556..36ae4d1 100644 --- a/readme.md +++ b/readme.md @@ -115,9 +115,9 @@ Crop to the set height. ##### cookies -Type: `array` +Type: `array` of `string`, `object` -Same format as a [browser cookie](http://en.wikipedia.org/wiki/HTTP_cookie). +A string with the same format as a [browser cookie](http://en.wikipedia.org/wiki/HTTP_cookie) or an object of what [`phantomjs.addCookie`](http://phantomjs.org/api/phantom/method/add-cookie.html) accepts. ###### Tip diff --git a/test/serverForCookieTests.js b/test/serverForCookieTests.js index 03121f3..f8ebbbd 100644 --- a/test/serverForCookieTests.js +++ b/test/serverForCookieTests.js @@ -11,8 +11,8 @@ app.get('/', function(request, response) { response.send('