Skip to content

Commit bcf37f7

Browse files
authored
Implemented WW Timer Library with Play, Stop, and Pause APIs via WebSocket (#1)
* Feat: created WW Timer * Other: Added eslint rules * Other: Eslint 규칙 추가 * Other: Added husky * BREAKING CHANGES: changed 'play' method name to 'start' * Docs: API 변경 사항 반영 * Other: updated for npm deploy * Other: keywords 정의 * Refactor: Rename play method to start in WWTimer class This commit renames the `play` method to `start` in the WWTimer class to better reflect the action being performed by the method. The change aims to improve code readability and make the method's purpose more intuitive, especially for developers familiar with common naming conventions for starting processes or activities. All references to the `play` method have been updated to `start`, ensuring consistency throughout the codebase. No functionality has been altered by this renaming. * Add: rollup configuration for ES module bundling Added a rollup.config.js file to configure the bundling process for the WWTimer project. This configuration specifies 'src/index.js' as the entry point and outputs the bundled file in ES module format to 'dist/ww-timer.js'. This setup ensures the project is bundled efficiently for use with modern JavaScript module systems. * Add: workflow for deploying package to NPM with version confirmation This commit introduces a new GitHub Actions workflow to automate the process of deploying our package to NPM. It requires a manual trigger through the GitHub UI, where the user is prompted to confirm the version they wish to deploy. This ensures that deployments are intentional and verified. The workflow includes steps for checking out the code, setting up Node.js, validating the tag, installing dependencies, linting, building, and finally deploying the package to NPM. * Update: build script and add Rollup as a dev dependency - Simplified the "build" script in package.json to use the rollup configuration file by changing it to "rollup -c". This change leverages the rollup.config.js file for the build process, making the build script cleaner and more maintainable. - Added Rollup as a development dependency to ensure a consistent build process across different environments. This addition aids in maintaining the build setup within the project's ecosystem without requiring * Add: registry-url and NODE_AUTH_TOKEN for NPM deployment workflow Enhanced the NPM deployment GitHub Actions workflow by specifying the `registry-url` for the `actions/setup-node` step and including the `NODE_AUTH_TOKEN` environment variable in the deploy step. These changes ensure that the workflow has the necessary configurations to authenticate and publish the package to the NPM registry securely. The `registry-url` is set to "https://registry.npmjs.org", aligning the deployment process with the official NPM registry * Remove: deploy script from package.json The "deploy" script has been removed from the `package.json` to streamline the project's scripts. This change reflects a shift towards utilizing external CI/CD pipelines or manual commands for deployment processes, adhering to a cleaner and more focused `package.json` structure. Adjustments were made to ensure the project's build and development lifecycle scripts remain concise and relevant to common development workflows. * Update: deployment command to use npm directly in GitHub Actions Changed the deployment command in the 'Deploy package on NPM' GitHub Actions workflow from `yarn publish` to `npm publish`. This adjustment ensures direct utilization of npm for the publishing process, leveraging the `NODE_AUTH_TOKEN` environment variable for authentication. This modification aligns the deployment step more closely with npm * Add: Added LISENCE File
1 parent cd9e9ca commit bcf37f7

35 files changed

+4106
-6
lines changed

.DS_Store

6 KB
Binary file not shown.

.eslintrc.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
es2021: true
6+
},
7+
extends: [
8+
'airbnb-base',
9+
'eslint:recommended'
10+
],
11+
plugins: [
12+
'import'
13+
],
14+
overrides: [
15+
{
16+
env: {
17+
node: true
18+
},
19+
files: [
20+
'.eslintrc.{js,cjs}'
21+
],
22+
parserOptions: {
23+
sourceType: 'script'
24+
}
25+
}
26+
],
27+
parserOptions: {
28+
ecmaVersion: 'latest',
29+
sourceType: 'module'
30+
},
31+
rules: {
32+
indent: ['error', 2],
33+
'linebreak-style': ['error', 'unix'],
34+
quotes: ['error', 'single'],
35+
semi: ['error', 'always'],
36+
'comma-dangle': ['error', {
37+
arrays: 'never',
38+
objects: 'never',
39+
imports: 'never',
40+
exports: 'never',
41+
functions: 'never'
42+
}],
43+
'no-restricted-globals': ['off'],
44+
'import/prefer-default-export': ['off']
45+
},
46+
ignorePatterns: ['examples/', 'dist/', 'node_modules/', '**/*.d.ts']
47+
};

.github/workflows/deploy.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Deploy package on NPM
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
isConfirmed:
6+
description: "Which version do you want to deploy? (ex. 1.0.0)"
7+
required: true
8+
type: boolean
9+
jobs:
10+
deploy-package-on-npm:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 18
17+
cache: "yarn"
18+
registry-url: "https://registry.npmjs.org"
19+
- name: Validate Tag
20+
if: ${{ (github.ref_type != 'tag' || inputs.IS_CONFIRMED == 'false') }}
21+
run: |
22+
exit 1
23+
- name: Install dependencies
24+
run: yarn
25+
- name: Lint
26+
run: yarn lint
27+
- name: Build
28+
run: yarn build
29+
- name: Deploy
30+
run: npm publish
31+
env:
32+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/node
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=node
3+
4+
### Node ###
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
lerna-debug.log*
12+
.pnpm-debug.log*
13+
14+
# Diagnostic reports (https://nodejs.org/api/report.html)
15+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
16+
17+
# Runtime data
18+
pids
19+
*.pid
20+
*.seed
21+
*.pid.lock
22+
23+
# Directory for instrumented libs generated by jscoverage/JSCover
24+
lib-cov
25+
26+
# Coverage directory used by tools like istanbul
27+
coverage
28+
*.lcov
29+
30+
# nyc test coverage
31+
.nyc_output
32+
33+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
34+
.grunt
35+
36+
# Bower dependency directory (https://bower.io/)
37+
bower_components
38+
39+
# node-waf configuration
40+
.lock-wscript
41+
42+
# Compiled binary addons (https://nodejs.org/api/addons.html)
43+
build/Release
44+
45+
# Dependency directories
46+
node_modules/
47+
jspm_packages/
48+
49+
# Snowpack dependency directory (https://snowpack.dev/)
50+
web_modules/
51+
52+
# TypeScript cache
53+
*.tsbuildinfo
54+
55+
# Optional npm cache directory
56+
.npm
57+
58+
# Optional eslint cache
59+
.eslintcache
60+
61+
# Optional stylelint cache
62+
.stylelintcache
63+
64+
# Microbundle cache
65+
.rpt2_cache/
66+
.rts2_cache_cjs/
67+
.rts2_cache_es/
68+
.rts2_cache_umd/
69+
70+
# Optional REPL history
71+
.node_repl_history
72+
73+
# Output of 'npm pack'
74+
*.tgz
75+
76+
# Yarn Integrity file
77+
.yarn-integrity
78+
79+
# dotenv environment variable files
80+
.env
81+
.env.development.local
82+
.env.test.local
83+
.env.production.local
84+
.env.local
85+
86+
# parcel-bundler cache (https://parceljs.org/)
87+
.cache
88+
.parcel-cache
89+
90+
# Next.js build output
91+
.next
92+
out
93+
94+
# Nuxt.js build / generate output
95+
.nuxt
96+
dist
97+
98+
# Gatsby files
99+
.cache/
100+
# Comment in the public line in if your project uses Gatsby and not Next.js
101+
# https://nextjs.org/blog/next-9-1#public-directory-support
102+
# public
103+
104+
# vuepress build output
105+
.vuepress/dist
106+
107+
# vuepress v2.x temp and cache directory
108+
.temp
109+
110+
# Docusaurus cache and generated files
111+
.docusaurus
112+
113+
# Serverless directories
114+
.serverless/
115+
116+
# FuseBox cache
117+
.fusebox/
118+
119+
# DynamoDB Local files
120+
.dynamodb/
121+
122+
# TernJS port file
123+
.tern-port
124+
125+
# Stores VSCode versions used for testing VSCode extensions
126+
.vscode-test
127+
128+
# yarn v2
129+
.yarn/cache
130+
.yarn/unplugged
131+
.yarn/build-state.yml
132+
.yarn/install-state.gz
133+
.pnp.*
134+
135+
### Node Patch ###
136+
# Serverless Webpack directories
137+
.webpack/
138+
139+
# Optional stylelint cache
140+
141+
# SvelteKit build / generate output
142+
.svelte-kit
143+
144+
# End of https://www.toptal.com/developers/gitignore/api/node

.husky/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
yarn lint

.husky/pre-push

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
PROHIBITED_REF="refs/heads/master"
4+
5+
if read local_ref local_sha remote_ref remote_sha
6+
then
7+
if [ "$remote_ref" = "$PROHIBITED_REF" ]
8+
then
9+
echo "prevent to push master"
10+
exit 1
11+
fi
12+
fi
13+
14+
exit 0

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.gitignore
2+
.git/
3+
node_modules/
4+
npm-debug.log

LISENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 univdev<[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,58 @@
11
![WW Timer](./banner.jpg)
2-
# Introduce
3-
The 'WW Timer' is a timer for browsers that operate using web workers.
4-
# Why need
5-
Implementing a timer in a browser is challenging for a variety of reasons.
6-
- Accurate time calculation may be difficult depending on the congestion level of the event loop.
7-
- Browser operating in the background does not have 'setInterval' or 'setTimeout' working properly.
2+
# WW Timer
3+
WW Timer is a highly accurate timer library for web browsers.
4+
5+
## Why It's Needed
6+
Typically, when implementing timer functionality in web browsers, the `setTimeout` or `setInterval` methods are used. However, due to the nature of JavaScript's execution model, achieving precise time measurement can be challenging.
7+
8+
JavaScript's asynchronous functions are subject to delays depending on the number of tasks the web browser is executing. This can result in the `setTimeout` and `setInterval` functions being deprioritized in the event loop, which, while generally inconsequential for standard functionality, can introduce critical errors in timing accuracy for timer implementations.
9+
10+
## Solution
11+
The solution lies in utilizing the [Web Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) supported by browsers. Since Web Workers operate independently of the browser's main thread, they are not affected by the complexity of the tasks being executed in the web app. This independence allows for more accurate time measurements, irrespective of the main thread's load.
12+
13+
## Features
14+
- **Accuracy**: Provides highly accurate timing by circumventing the event loop's congestion.
15+
- **Independence**: Operates separately from the main thread, ensuring timer precision is maintained.
16+
- **Ease of Use**: Designed to be straightforward to implement within any web application.
17+
18+
## Installation
19+
```sh
20+
# npm
21+
npm install ww-timer
22+
# yarn
23+
yarn add ww-timer
24+
```
25+
26+
## Quick Start
27+
```javascript
28+
// Import WW Timer
29+
import WWTimer from 'ww-timer';
30+
31+
// Create a new timer
32+
const timer = new WWTimer();
33+
34+
// Start the timer with a callback function
35+
timer.start(() => {
36+
console.log('Timer tick');
37+
});
38+
39+
// Pause the timer
40+
timer.pause();
41+
42+
// Destroy the timer instance
43+
timer.destroy();
44+
```
45+
46+
## API Reference
47+
- `start(callback, interval)`: Starts the timer with the specified callback function and interval.
48+
- `pause()`: Stops the timer.
49+
- `destroy()`: Destroy the timer instance.
50+
51+
## Compatibility
52+
Compatible with most modern web browsers that support the Web Workers API.
53+
54+
## Contributing
55+
Contributions to the WW Timer project are welcome. Please refer to the CONTRIBUTING.md file for more details.
56+
57+
## License
58+
WW Timer is released under the MIT License. See the LICENSE file for more information.

examples/.DS_Store

6 KB
Binary file not shown.

0 commit comments

Comments
 (0)