Skip to content

Commit

Permalink
chore: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Sloaix committed Feb 25, 2024
0 parents commit 48701be
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: test
on:
push:
branches:
# 任何分支
- '*'

jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: Test
run: deno task test
Empty file added .gitignore
Empty file.
13 changes: 13 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"printWidth": 120,
"tabWidth": 2,
"tabs": false,
"semi": false,
"trailingComma": "none",
"singleQuote": true,
"quoteProps": "as-needed",
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf",
"htmlWhitespaceSensitivity": "ignore"
}
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Test debug",
"type": "node",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"test",
"--inspect-wait",
"--allow-all"
],
"attachSimplePort": 9229
},
{
"request": "launch",
"name": "Launch Program",
"type": "node",
"program": "${file}",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"run"
],
}
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"deno.enable": true,
"deno.lint": true,
"deno.unstable": true
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 deno-torrent

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# [uTP](https://deno.land/x/dt_utp) [![Custom badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Flatest-version%2Fx%2Fdt_utp%2Fmod.ts)](https://deno.land/x/dt_utp)

μTP protocol implementation in TypeScript for Deno. This is a work in progress and not yet functional.
13 changes: 13 additions & 0 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"imports": {
"std/": "https://deno.land/[email protected]/"
},
"tasks": {
"test": "deno test --allow-read"
},
"test": {
"include": [
"./test"
]
}
}
Empty file added mod.ts
Empty file.
32 changes: 32 additions & 0 deletions src/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
let BENCODE_DEBUG_ENABLE = false

export function disableDebug() {
BENCODE_DEBUG_ENABLE = false
}

export function enableDebug() {
BENCODE_DEBUG_ENABLE = true
}

export function logd(message?: any, ...optionalParams: any[]) {
if (!BENCODE_DEBUG_ENABLE) return

// format current date: 2021-01-01 00:00:00
const date = new Date()
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()

const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()

const time = `${year}-${month}-${day} ${hour}:${minute}:${second}`

// 为time添加颜色
const formattedTime = `\x1b[36m${time}\x1b[0m`

const formattedMessage = `[${formattedTime}] ${message}`

console.log(formattedMessage, ...optionalParams)
}

0 comments on commit 48701be

Please sign in to comment.