Skip to content

Commit

Permalink
setup typescript project
Browse files Browse the repository at this point in the history
refactor lib script to ts
refactor specs to ts
add tslint
add tsc build
update package
update License person info
  • Loading branch information
naxmefy committed Jun 5, 2017
1 parent 08160dc commit e20cd78
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 65 deletions.
24 changes: 3 additions & 21 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
# http://editorconfig.org

# A special property that should be specified at the top of the file outside of
# any sections. Set to true to stop .editor config file search on current file
root = true

[*]
# Indentation style
# Possible values - tab, space
indent_style = space

# Indentation size in single-spaced characters
# Possible values - an integer, tab
indent_size = 2

# Line ending file format
# Possible values - lf, crlf, cr
end_of_line = lf

# File character encoding
# Possible values - latin1, utf-8, utf-16be, utf-16le
charset = utf-8

# Denotes whether to trim whitespace at the end of lines
# Possible values - true, false
trim_trailing_whitespace = true

# Denotes whether file should end with a newline
# Possible values - true, false
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ jspm_packages
# Optional REPL history
.node_repl_history

# editors
# lib build
# /lib

# idea
.idea
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
.nyc_output
coverage
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
save=true
tag-version-prefix=
access=public
scope=naxmefy
30 changes: 19 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
language: node_js
node_js:
- '0.10'
- '0.12'
- '4'
- '5'
- '6'
env:
- NODE_ENV=test
before_script:
- npm i -g coveralls
after_script:
- cat ./coverage/lcov.info | coveralls
- 0.11
- 0.12
- 4
- 5
- 6
- 7
- 8
cache:
directories:
- node_modules
script:
- npm run test:coverage
after_success:
- npm install -g coveralls nyc
- nyc report --reporter=text-lcov | coveralls
notifications:
email:
on_success: never
on_failure: change
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016 Matt
Copyright (c) 2017 MRW Neundorf <m.neundorf@live.de>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
57 changes: 44 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,58 @@
"name": "@naxmefy/env",
"version": "1.0.1",
"description": "env vars util",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "git@github.com:naxmefy/node-env.git"
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"author": {
"name": "MRW Neundorf",
"email": "m.neundorf@live.de",
"url": "http://www.nax.me"
},
"homepage": "https://github.com/naxmefy/node-env",
"bugs": {
"email": "m.neundorf@live.de",
"url": "https://github.com/naxmefy/node-env/issues"
},
"homepage": "https://github.com/naxmefy/node-env#readme",
"scripts": {
"test": "istanbul cover _mocha test"
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/naxmefy/node-env.git"
},
"engines": {
"node": ">= 0.10"
},
"author": "MRW Neundorf <m.neundorf@live.de>",
"license": "MIT",
"dependencies": {},
"scripts": {
"build": "tsc",
"lint": "tslint src test",
"lint:fix": "npm run tslint -- --fix",
"prepublish": "npm run build",
"test": "mocha",
"test:coverage": "nyc npm test"
},
"nyc": {
"include": [
"src/**/*.ts"
],
"extension": [
".ts"
],
"require": [
"ts-node/register"
],
"reporter": [
"text-summary"
],
"sourceMap": true,
"instrument": true
},
"devDependencies": {
"istanbul": "^0.4.5",
"mocha": "^3.0.2",
"should": "11.1.0"
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.27",
"mocha": "^3.3.0",
"nyc": "^10.3.2",
"ts-node": "^3.0.4",
"tslint": "^5.2.0",
"tslint-config-standard": "^5.0.2",
"typescript": "^2.3.2"
}
}
2 changes: 1 addition & 1 deletion lib/index.js → src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
* @param {*} [defaultValue] A default value that will be returned if env var is undefined
* @returns {*}
*/
module.exports = function (envVarString, defaultValue) {
export default function (envVarString: string, defaultValue?: any): any {
return process.env[envVarString] || defaultValue
}
4 changes: 1 addition & 3 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
--ui bdd
--reporter spec
--recursive
--colors
--require should
--compilers ts:ts-node/register
14 changes: 0 additions & 14 deletions test/spec.js

This file was deleted.

17 changes: 17 additions & 0 deletions test/spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as assert from 'assert'
import env from '../src'

describe('Utils: env', () => {
it('should return env if defined', () => {
process.env.ENV_TEST_ENV = 1
assert.equal(env('ENV_TEST_ENV'), '1')
})

it('should return undefined if not defined', () => {
assert.equal(env('ANOTHER_TEST_ENV'), void 0)
})

it('should return default value if env is not defined', () => {
assert.equal(env('ANOTHER_TEST_ENV', 2), 2)
})
})
16 changes: 16 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"declaration": true,
"outDir": "lib",
"noImplicitAny": false,
"sourceMap": true
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
]
}
9 changes: 9 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"defaultSeverity": "error",
"extends": [
"tslint-config-standard"
],
"jsRules": {},
"rules": {},
"rulesDirectory": []
}

0 comments on commit e20cd78

Please sign in to comment.