-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from AliMD/feat/logger
Feat/logger
- Loading branch information
Showing
13 changed files
with
130 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
"name": "@one/demo", | ||
"name": "@vatr/demo", | ||
"version": "0.0.0", | ||
"description": "@one packages demo", | ||
"description": "@vatr packages demo", | ||
"main": "index.js", | ||
"author": "@one community", | ||
"author": "@vatr community", | ||
"type": "module", | ||
"private": "true", | ||
"repository": { | ||
|
@@ -25,8 +25,8 @@ | |
"MohammadMahdi Zamanian <[email protected]>" | ||
], | ||
"dependencies": { | ||
"@one/svg-icon": "^0.0.0", | ||
"@one/util": "^0.0.0", | ||
"@vatr/svg-icon": "^0.0.0", | ||
"@vatr/util": "^0.0.0", | ||
"lit": "^2.1.3", | ||
"tslib": "^2.2.0" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { persianNumberToEnglishNumber } from '@one/util/persian-number.js'; | ||
import { persianNumberToEnglishNumber } from '@vatr/util/persian-number.js'; | ||
|
||
console.log(persianNumberToEnglishNumber('۱۲۳۴')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"description": "The Vatr Library", | ||
"repository": "https://github.com/AliMD/One", | ||
"author": "S. Ali Mihandoost <[email protected]>", | ||
"license": "MIT", | ||
"private": true, | ||
"workspaces": [ | ||
"package/*", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# @vatr/logger | ||
|
||
Create a logger function for fancy console debug with custom scope. | ||
|
||
## Example usage | ||
|
||
```js | ||
import { createLogger } from '@vatr/logger'; | ||
|
||
const log = createLogger('my-scope', 'debug', true); | ||
log('foo'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@vatr/logger", | ||
"version": "0.0.0", | ||
"description": "Create a logger function for fancy console debug with custom scope.", | ||
"main": "logger.js", | ||
"type": "module", | ||
"types": "logger.d.ts", | ||
"author": "S. Ali Mihandoost <[email protected]>", | ||
"license": "MIT", | ||
"files": [ | ||
"**/*.js", | ||
"**/*.d.ts", | ||
"**/*.map", | ||
"**/*.html", | ||
"**/*.md" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/AliMD/vatr", | ||
"directory": "package/logger" | ||
}, | ||
"dependencies": { | ||
"tslib": "^2.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
export type LoggerType = (message: string, ...restParam: Array<unknown>) => void; | ||
export type LogLevelType = 'debug' | 'error' | 'info' | 'log' | 'trace' | 'warn'; | ||
|
||
let colorIndex = 0; | ||
const colorList = [ | ||
'#f05561', | ||
'#35b997', | ||
'#ee224a', | ||
'#91c13e', | ||
'#22af4b', | ||
'#f0e995', | ||
'#0fe995', | ||
'#0f89ca', | ||
'#08b9a5', | ||
'#fee851', | ||
'#ee573d', | ||
'#f9df30', | ||
'#1da2dc', | ||
'#f05123', | ||
'#ee2524', | ||
]; | ||
|
||
const getNextColor = (): string => { | ||
const color = colorList[colorIndex]; | ||
colorIndex++; | ||
if (colorIndex >= colorList.length) { | ||
colorIndex = 0; | ||
} | ||
return color; | ||
}; | ||
|
||
/** | ||
* Create a logger function for fancy console debug with custom scope. | ||
* | ||
* @property {boolean} force - if set to true logger will work even if its not in debug mode. | ||
* @example | ||
* const log = createLogger('my scope', 'log', true); | ||
* log('my log message :)'); | ||
*/ | ||
export function createLogger(scope: string, level: LogLevelType = 'debug', force?: boolean): LoggerType { | ||
const color = getNextColor(); | ||
return (message: string, ...restParam: Array<unknown>) => { | ||
if (!(force === true || window.localStorage?.getItem('DEBUG') != null)) return; | ||
// first args must be separated as keyPattern for fix issue of `this._log('a=%s', a)` | ||
console[level]( | ||
`%c%s%c ${message}`, | ||
`color: ${color}; font-size: 1.2em;`, | ||
scope, | ||
'color: inherit;font-size: 1em', | ||
...restParam, | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"composite": true, | ||
"rootDir": "src", | ||
"outDir": ".", | ||
}, | ||
// files, include and exclude from the inheriting config are always overwritten. | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"exclude": [], | ||
"references": [ | ||
// { "path": "../x" }, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
{ | ||
"name": "@one/svg-icon", | ||
"name": "@vatr/svg-icon", | ||
"version": "0.0.0", | ||
"description": "Typescript/Javascript Icon Pack Lit", | ||
"main": "index.js", | ||
"author": "@one community", | ||
"author": "@vatr community", | ||
"type": "module", | ||
"private": true, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/AliMD/One/tree/next/package/svg-icon" | ||
|
@@ -24,7 +25,7 @@ | |
"MohammadMahdi Zamanian <[email protected]>" | ||
], | ||
"dependencies": { | ||
"lit": "^2.1.2", | ||
"lit": "^2.2.0", | ||
"tslib": "^2.3.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters