Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #51 from uncovertruth/fix/interface
Browse files Browse the repository at this point in the history
fix(src) remove unnesessary vars
  • Loading branch information
shoota authored Nov 21, 2017
2 parents 8da611e + f14956f commit c6d34e8
Show file tree
Hide file tree
Showing 9 changed files with 425 additions and 281 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
language: node_js
dist: precise
sudo: false
node_js:
- stable
- 6
jdk:
- oraclejdk8
node_js: stable
matrix:
allow_failures:
- node_js: stable
- env: CMD=test:sauce
addon:
firefox: latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ npm install auto-cookie js-cookie --save
```js
import { find, save } from 'auto-cookie'

find(cookieName, expires) // read
find(cookieName) // read
save(cookieName, data, options) // write
```

Expand Down
2 changes: 1 addition & 1 deletion example/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { save, find } from '../src'
import { save } from '../src'
const expires = 1 / 48
save('auto-cookie', 'data', { expires })
save('object-cookie', { s: 'string', n: 99, b: true }, { expires })
Expand Down
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@
"devDependencies": {
"@types/finalhandler": "^0.0.32",
"@types/js-cookie": "^2.1.0",
"@types/mocha": "^2.2.43",
"@types/node": "^8.0.44",
"@types/mocha": "^2.2.44",
"@types/node": "^8.0.53",
"@types/power-assert": "^1.4.29",
"@types/serve-static": "^1.7.32",
"@uncovertruth/tslint-config": "^1.2.0",
"cross-env": "^5.1.0",
"espower-typescript": "^8.1.1",
"@types/serve-static": "^1.13.1",
"@uncovertruth/tslint-config": "^1.3.0",
"cross-env": "^5.1.1",
"espower-typescript": "^8.1.2",
"finalhandler": "^1.1.0",
"gh-pages": "^1.0.0",
"gh-pages": "^1.1.0",
"husky": "^0.14.3",
"js-cookie": "^2.1.4",
"js-cookie": "^2.2.0",
"lint-staged": "^5.0.0",
"mocha": "^3.5.3",
"mocha": "^4.0.1",
"power-assert": "^1.4.4",
"prettier": "^1.7.4",
"prettier": "^1.8.2",
"rimraf": "^2.6.2",
"serve-static": "^1.13.1",
"ts-loader": "^3.0.3",
"ts-loader": "^3.1.1",
"ts-node": "^3.3.0",
"tslint": "^5.8.0",
"typescript": "^2.5.3",
"typescript": "^2.6.1",
"wdio-mocha-framework": "^0.5.11",
"wdio-sauce-service": "^0.4.0",
"wdio-selenium-standalone-service": "0.0.7",
"wdio-sauce-service": "^0.4.4",
"wdio-selenium-standalone-service": "^0.0.9",
"wdio-spec-reporter": "^0.1.2",
"webdriverio": "^4.8.0",
"webdriverio": "^4.9.9",
"webpack": "^3.8.1"
},
"files": [
Expand All @@ -58,7 +58,6 @@
]
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"peerDependencies": {
"js-cookie": "2.x"
},
Expand All @@ -67,10 +66,10 @@
"url": "git+ssh://[email protected]/uncovertruth/auto-cookie.git"
},
"scripts": {
"build": "cross-env NODE_ENV=production tsc && webpack",
"build": "tsc && webpack --env=production",
"clean": "rimraf lib",
"deploy": "gh-pages -d example",
"lint": "tslint \"src/*.ts\" \"test/*.ts\"",
"lint": "tslint '{src,test}/*.ts'",
"prebuild": "npm run clean",
"precommit": "lint-staged",
"prepublish": "npm run build",
Expand All @@ -79,5 +78,6 @@
"start": "ts-node server.ts",
"test": "wdio wdio.conf.js",
"test:sauce": "cross-env CI_MODE=sauce wdio wdio.conf.js"
}
},
"types": "lib/index.d.ts"
}
17 changes: 6 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ function setCookie (

function findOrCreate (
name: string,
options: cookies.CookieAttributes,
data?: string | object
data?: string | object,
options?: cookies.CookieAttributes
): string | undefined {
const value = cookies.get(name)
if (value) {
Expand All @@ -42,24 +42,19 @@ function findOrCreate (
}

if (data) {
setCookie(domainParts, name, options, data)
setCookie(domainParts, name, options || {}, data)
}
return cookies.get(name)
}

export function find (
name: string,
options: cookies.CookieAttributes
): string | undefined {
options = options || {}
return findOrCreate(name, options)
export function find (name: string): string | undefined {
return findOrCreate(name)
}

export function save (
name: string,
value: string | object,
options: cookies.CookieAttributes
): string | undefined {
options = options || {}
return findOrCreate(name, options, value)
return findOrCreate(name, value, options)
}
6 changes: 3 additions & 3 deletions test/helpers/server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as finalhandler from 'finalhandler'
import * as http from 'http'
import * as path from 'path'
import * as finalhandler from 'finalhandler'
import * as serveStatic from 'serve-static'

export default function start (): any {
export default function start (callback: Function) {
const serve = serveStatic(path.join(__dirname, '../../example'))
const server = http.createServer((req: any, res: any) => {
serve(req, res, finalhandler(req, res))
})
return server.listen(8000)
return server.listen(8000, callback)
}
8 changes: 4 additions & 4 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'mocha'
import * as assert from 'assert'
import 'mocha'
import start from './helpers/server'

declare var browser: any
Expand All @@ -8,9 +8,8 @@ describe('auto-cookie', () => {
let server
const COOKIE_NAME = 'auto-cookie'

before(() => {
server = start()
return server
before(done => {
server = start(done)
})

after(() => server.close())
Expand Down Expand Up @@ -40,6 +39,7 @@ describe('auto-cookie', () => {
.then((cookie: any) => {
assert(cookie.value === 'setPath')
assert(cookie.domain === '.xip.io')
assert(cookie.path === '/path')
}))

it('should get cookie has object value', () =>
Expand Down
9 changes: 8 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noEmit": false,
"declaration": true,
"removeComments": true,
"alwaysStrict": true,
"noImplicitThis": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"sourceMap": true,
"baseUrl": "./",
"paths": {},
Expand Down
Loading

0 comments on commit c6d34e8

Please sign in to comment.