diff --git a/karma.conf.js b/karma.conf.js index 3329f35..6286a7d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,12 +1,14 @@ module.exports = function (config) { + const package = require('./package.json'); + //console.log(package); config.set({ basePath: '', frameworks: ['jasmine'], files: [ 'node_modules/moment/moment.js', - 'tests/moment-timezone-with-data.js', + 'tests/unit-tests/moment-timezone-with-data.js', 'moment-dt.js', - 'tests/moment-dt.spec.js' + 'tests/unit-tests/moment-dt.spec.js' ], exclude: [], reporters: ['progress', 'coverage', 'coveralls'], @@ -23,10 +25,10 @@ module.exports = function (config) { 'karma-eslint' ], globals: { - packageVersion: require('./package.json').version + packageVersion: package.version }, preprocessors: { - 'tests/moment-dt.spec.js': ['global', 'eslint'], + 'tests/unit-tests/moment-dt.spec.js': ['global', 'eslint'], 'moment-dt.js': ['coverage', 'eslint'] }, coverageReporter: { diff --git a/moment-dt.d.ts b/moment-dt.d.ts new file mode 100644 index 0000000..e27f2ca --- /dev/null +++ b/moment-dt.d.ts @@ -0,0 +1,22 @@ +import * as moment from 'moment-timezone'; + +declare module "moment-timezone" { + interface MomentTsTz { + ts: number; + tz: string; + } + + interface Moment { + dt(): MomentTsTz; + } + + interface MomentDt { + (dt: MomentTsTz): moment.Moment; + version: string; + } + + const dt: MomentDt; +} + +// require("moment-dt") === require("moment-timezone") +export = moment; \ No newline at end of file diff --git a/moment-dt.js b/moment-dt.js index 4c223af..ea4d5af 100644 --- a/moment-dt.js +++ b/moment-dt.js @@ -11,7 +11,7 @@ } }(this, function (moment) { - var VERSION = "1.0.1"; + var VERSION = "1.0.2"; /* istanbul ignore if */ if (!moment.tz) { diff --git a/moment-dt.min.js b/moment-dt.min.js index 8073a5b..8d81fb9 100644 --- a/moment-dt.min.js +++ b/moment-dt.min.js @@ -1 +1 @@ -!function(t,n){"use strict";"object"==typeof exports?module.exports=n(require("moment")):"function"==typeof define&&define.amd?define("moment-dt",["moment"],n):t.moment=n(t.moment)}(this,function(t){"use strict";if(!t.tz)throw new Error("Can't find moment-timezone");return t.fn.dt=function(){return{ts:this.isValid()?t.utc(this).unix():null,tz:this.tz()||null}},t.dt=function(n){return n||(n={}),t.unix("number"==typeof n.ts?n.ts:"invalid").tz(n.tz||"invalid timezone")},t.dt.version="1.0.1",t}); +"use strict";!function(t,n){"object"==typeof exports?module.exports=n(require("moment")):"function"==typeof define&&define.amd?define("moment-dt",["moment"],n):t.moment=n(t.moment)}(this,function(t){if(!t.tz)throw new Error("Can't find moment-timezone");return t.fn.dt=function(){return{ts:this.isValid()?t.utc(this).unix():null,tz:this.tz()||null}},t.dt=function(n){return n||(n={}),t.unix("number"==typeof n.ts?n.ts:"invalid").tz(n.tz||"invalid timezone")},t.dt.version="1.0.2",t}); diff --git a/package.json b/package.json index a8db822..ba5d29f 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,17 @@ { "name": "moment-dt", - "version": "1.0.1", + "version": "1.0.2", "description": "Convert timestamp-with-timezone-objects from and to moment.js", "main": "moment-dt.js", + "typings": "./moment-dt.d.ts", "scripts": { - "test": "npm run prod:test", + "test": "run-s prod:test:*", "start": "run-p dev:*", "dev:test": "karma start", "build": "run-s prod:*", "prod:minify": "uglifyjs --compress --mangle -- moment-dt.js > moment-dt.min.js", - "prod:test": "karma start --singleRun" + "prod:test:unit": "karma start --singleRun", + "prod:test:typings": "tsc --project tests/typings-tests" }, "repository": { "type": "git", @@ -28,20 +30,22 @@ }, "homepage": "https://github.com/smartin85/moment-dt#readme", "dependencies": { + "@types/moment-timezone": "^0.2.34", "moment": ">= 2.8.1 <3.0.0", "moment-timezone": "^0.5.11" }, "devDependencies": { - "jasmine-core": "~2.5.2", + "jasmine-core": "2.5.2", "karma": "1.6.0", - "karma-chrome-launcher": "~2.0.0", - "karma-coverage": "^1.1.1", - "karma-coveralls": "^1.1.2", - "karma-eslint": "^2.2.0", - "karma-global-preprocessor": "~0.0.2", - "karma-jasmine": "~1.1.0", - "karma-phantomjs-launcher": "~1.0.2", - "npm-run-all": "^4.0.2", + "karma-chrome-launcher": "2.0.0", + "karma-coverage": "1.1.1", + "karma-coveralls": "1.1.2", + "karma-eslint": "2.2.0", + "karma-global-preprocessor": "0.0.2", + "karma-jasmine": "1.1.0", + "karma-phantomjs-launcher": "1.0.4", + "npm-run-all": "4.0.2", + "typescript": "2.2.2", "uglify-js": "2.8.22" } } diff --git a/tests/typings-tests/moment-dt-tests.ts b/tests/typings-tests/moment-dt-tests.ts new file mode 100644 index 0000000..b06e204 --- /dev/null +++ b/tests/typings-tests/moment-dt-tests.ts @@ -0,0 +1,8 @@ +/// +import moment = require('../../moment-dt'); + + +var timezone: string = moment().tz(); +var dt:{ts: number, tz: string} = moment().dt(); +var mom: moment.Moment = moment.dt({ts: 1492630664, tz: "Europe/Berlin"}); +var version: string = moment.dt.version; \ No newline at end of file diff --git a/tests/typings-tests/tsconfig.json b/tests/typings-tests/tsconfig.json new file mode 100644 index 0000000..a6dfa58 --- /dev/null +++ b/tests/typings-tests/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "module": "commonjs", + "noEmit": true, + "noImplicitAny": true + }, + "files": [ + "../../moment-dt.d.ts", + "./moment-dt-tests.ts" + ] +} \ No newline at end of file diff --git a/tests/moment-dt.spec.js b/tests/unit-tests/moment-dt.spec.js similarity index 100% rename from tests/moment-dt.spec.js rename to tests/unit-tests/moment-dt.spec.js diff --git a/tests/moment-timezone-with-data.js b/tests/unit-tests/moment-timezone-with-data.js similarity index 100% rename from tests/moment-timezone-with-data.js rename to tests/unit-tests/moment-timezone-with-data.js