Skip to content

Commit

Permalink
feat(logger): vatr logger package
Browse files Browse the repository at this point in the history
  • Loading branch information
AliMD committed Feb 24, 2022
1 parent 448cd94 commit 711268e
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ settings:
# TODO: Add other classes

rules:
max-len:
- warn
- code: 120
no-eval:
- error
- allowIndirect: true
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "The Vatr Library",
"repository": "https://github.com/AliMD/One",
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
"license": "MIT",
"private": true,
"workspaces": [
"package/*",
Expand Down
12 changes: 12 additions & 0 deletions package/logger/README.md
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');
```
25 changes: 25 additions & 0 deletions package/logger/package.json
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 <ali.mihandoost@gmail.com>",
"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"
}
}
53 changes: 53 additions & 0 deletions package/logger/src/logger.ts
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,
);
};
}
16 changes: 16 additions & 0 deletions package/logger/tsconfig.json
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" },
]
}
3 changes: 2 additions & 1 deletion package/svg-icon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"author": "@one community",
"type": "module",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/AliMD/One/tree/next/package/svg-icon"
Expand All @@ -24,7 +25,7 @@
"MohammadMahdi Zamanian <mm25zamanian@gmail.com>"
],
"dependencies": {
"lit": "^2.1.2",
"lit": "^2.2.0",
"tslib": "^2.3.1"
}
}
2 changes: 1 addition & 1 deletion package/svg-icon/src/ion-icon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { svg } from 'lit';
import {svg} from 'lit';
export const accessibilityOutline = svg`<svg width="24" height="24" viewBox="0 0 512 512"><circle fill="none" stroke="currentcolor" stroke-linejoin="round" stroke-width="32" cx="256" cy="56" r="40"/><path fill="none" stroke="currentcolor" stroke-linejoin="round" stroke-width="32" d="M204.23,274.44c2.9-18.06,4.2-35.52-.5-47.59-4-10.38-12.7-16.19-23.2-20.15L88,176.76c-12-4-23.21-10.7-24-23.94-1-17,14-28,29-24,0,0,88,31.14,163,31.14s162-31,162-31c18-5,30,9,30,23.79,0,14.21-11,19.21-24,23.94l-88,31.91c-8,3-21,9-26,18.18-6,10.75-5,29.53-2.1,47.59l5.9,29.63L351.21,467.9c2.8,13.15-6.3,25.44-19.4,27.74S308,489,304.12,476.28L266.56,360.35q-2.71-8.34-4.8-16.87L256,320l-5.3,21.65q-2.52,10.35-5.8,20.48L208,476.18c-4,12.85-14.5,21.75-27.6,19.46S158,480.05,160.94,467.9l37.39-163.83Z"/></svg>`;
export const accessibilitySharp = svg`<svg width="24" height="24" viewBox="0 0 512 512"><path d="M448,112c-66.82,17.92-119.55,32-192,32S130.82,129.92,64,112L48,163c48,20.53,96.71,35.16,147.2,53.2L144,496l56.4,16L246,336h20l45.6,176L368,496,316.8,216.2C367.26,199.93,416,183.53,464,164Z"/><path d="M256,112a56,56,0,1,1,56-56A56.06,56.06,0,0,1,256,112Z"/></svg>`;
export const accessibility = svg`<svg width="24" height="24" viewBox="0 0 512 512"><path d="M256,112a56,56,0,1,1,56-56A56.06,56.06,0,0,1,256,112Z"/><path d="M432,112.8l-.45.12h0l-.42.13c-1,.28-2,.58-3,.89-18.61,5.46-108.93,30.92-172.56,30.92-59.13,0-141.28-22-167.56-29.47a73.79,73.79,0,0,0-8-2.58c-19-5-32,14.3-32,31.94,0,17.47,15.7,25.79,31.55,31.76v.28l95.22,29.74c9.73,3.73,12.33,7.54,13.6,10.84,4.13,10.59.83,31.56-.34,38.88l-5.8,45L150.05,477.44q-.15.72-.27,1.47l-.23,1.27h0c-2.32,16.15,9.54,31.82,32,31.82,19.6,0,28.25-13.53,32-31.94h0s28-157.57,42-157.57,42.84,157.57,42.84,157.57h0c3.75,18.41,12.4,31.94,32,31.94,22.52,0,34.38-15.74,32-31.94-.21-1.38-.46-2.74-.76-4.06L329,301.27l-5.79-45c-4.19-26.21-.82-34.87.32-36.9a1.09,1.09,0,0,0,.08-.15c1.08-2,6-6.48,17.48-10.79l89.28-31.21a16.9,16.9,0,0,0,1.62-.52c16-6,32-14.3,32-31.93S451,107.81,432,112.8Z"/></svg>`;
Expand Down
1 change: 1 addition & 0 deletions package/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"author": "@one community",
"type": "module",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/AliMD/One/tree/next/package/util"
Expand Down
13 changes: 5 additions & 8 deletions package/util/src/persian-number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ const arabicNumbers = [
/**
* persianNumberToEnglishNumber
*/
export function persianNumberToEnglishNumber(string: string): string
{
if (typeof string === 'string')
{
for (let number = 0; number < 10; number++)
{
export function persianNumberToEnglishNumber(string: string): string {
if (typeof string === 'string') {
for (let number = 0; number < 10; number++) {
string = string
.replace(persianNumbers[number], number.toString())
.replace(arabicNumbers[number], number.toString());
.replace(persianNumbers[number], number.toString())
.replace(arabicNumbers[number], number.toString());
}
}
return string;
Expand Down

0 comments on commit 711268e

Please sign in to comment.