Skip to content

Commit

Permalink
import fixes + umd
Browse files Browse the repository at this point in the history
  • Loading branch information
vltansky committed Apr 27, 2020
1 parent 163cfba commit 6871140
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/umd/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "Similiar to console.time() but returns readable elapsed time e.g Label: 1 hour 20 minutes 10.3 seconds",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
"browser": "lib/umd/index.js",
"types": "lib/index.d.ts",
"files": [
"lib/**/*"
Expand All @@ -16,7 +15,7 @@
"build:cjs": "tsc --module commonjs --target es5 --outDir lib/cjs",
"build:umd": "rollup -c",
"build:umd:min": "cd lib/umd && terser --compress --mangle --comments -o index.js -- index.js",
"watch": "tsc --watch",
"watch": "npm run build:cjs -- --watch",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.ts\"",
"lint": "tslint -p tsconfig.json",
"release": "dotenv release-it"
Expand Down Expand Up @@ -59,6 +58,7 @@
"browser-hrtime": "^1.0.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^7.1.3",
"@types/node": "^13.13.0",
"coveralls": "^3.1.0",
"dotenv-cli": "^3.1.0",
Expand Down
10 changes: 4 additions & 6 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import resolve from '@rollup/plugin-node-resolve';

export default {
input: 'lib/esm/index.js',
output: 'lib/umd/index.js',
output: {
name: 'Elapssed-logger',
name: 'Elapsed_logger',
file: 'lib/umd/index.js',
format: 'umd',
exports: "named",
globals: {
'browser-hrtime': 'hrtime',
}
},
external: [ 'browser-hrtime' ]
plugins: [resolve()]
};
60 changes: 60 additions & 0 deletions tests/umd.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>

<head>
<!-- <script crossorigin src="https://unpkg.com/browser-hrtime/lib/umd/index.js"></script> -->
<!-- <script crossorigin src="https://unpkg.com/elapsed-time-logger/lib/umd/index.js"></script> -->
<script src="../lib/umd/index.js"></script>
<script>
var elapsed = Elapsed_logger;
elapsed.start('test2');
setTimeout(()=>{
elapsed.end('test2');
}, 1300);


elapsed.start('test');
setTimeout(()=>{
elapsed.end('test');
}, 1300);

elapsed.start('testoverride');
setTimeout(()=>{
elapsed.end('testoverride', 'override label');
}, 100);


elapsed.start('vlad');
setTimeout(()=>{
const test = elapsed.get('vlad');
console.log(test);
}, 1200);

// ElapsedLogger is similliar to console.time() & console.timeEnd()
elapsed.start('label');
elapsed.start('timer label');
setTimeout(()=>{
elapsed.end('label');
elapsed.end('timer label');
}, 800);


// or use ElapsedLogger as an instance (recommended)
const elapsedTimer = elapsed.start();
// const elapsedTimer2 = elapsed.start();
console.log('smth');
setTimeout(()=>{
const t = elapsedTimer.get();
console.log(t);
// elapsedTimer2.end(chalk.green('you can use colors here, try chalk or colors packages:'));
elapsedTimer.end('finished:');
}, 800);


</script>
</head>

<body>
</body>

</html>

0 comments on commit 6871140

Please sign in to comment.