added prettier and eslint for dev

main
vikingowl 5 months ago
parent 0039e54de2
commit 77c3b90d02
  1. 83
      .eslintrc.json
  2. 6
      .prettierrc.toml
  3. 546
      .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
  4. 785
      .yarn/releases/yarn-3.2.0.cjs
  5. 7
      .yarnrc.yml
  6. 32
      lib/domUtils.ts
  7. 80
      lib/formatters.ts
  8. 8
      lib/index.ts
  9. 3
      lib/utils.ts
  10. 3062
      package-lock.json
  11. 37
      package.json
  12. 24
      src/domUtils.ts
  13. 69
      src/formatters.ts
  14. 3
      src/index.ts
  15. 3
      src/utils.ts
  16. 6
      tsconfig.json
  17. 35
      yarn.lock

@ -0,0 +1,83 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier/prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
],
"curly": [
"error",
"multi-or-nest"
],
"max-len": [
"error",
{
"code": 80,
"ignoreUrls": true,
"ignoreComments": true
}
],
"no-mixed-operators": "error",
"no-tabs": [
"error",
{
"allowIndentationTabs": true
}
],
"lines-around-comment": [
"error",
{
"beforeBlockComment": true,
"afterBlockComment": true,
"beforeLineComment": true,
"afterLineComment": true,
"allowBlockStart": true,
"allowBlockEnd": true,
"allowObjectStart": true,
"allowObjectEnd": true,
"allowArrayStart": true,
"allowArrayEnd": true
}
],
"lines-between-class-members": [
"error",
"never"
],
"padding-line-between-statements": [
"error",
{
"blankLine": "always",
"prev": "*",
"next": "return"
}
]
}
}

@ -0,0 +1,6 @@
trailingComma = 'none'
tabWidth = 2
semi = false
singleQuote = true
printWidth = 80
bracketSameLine = true

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1,7 +0,0 @@
nodeLinker: node-modules
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"
yarnPath: .yarn/releases/yarn-3.2.0.cjs

@ -0,0 +1,32 @@
export const addGlobalEventListener = (
type: string,
selector: string,
callback: (arg0: Event) => void,
options: boolean | AddEventListenerOptions,
parent = document
): void => {
parent.addEventListener(
type,
(e: Event) => {
if (e != null && e.target != null) {
const el = e.target as Element
if (el.matches(selector)) callback(e)
}
},
options
)
}
export const qs = (
selector: string | keyof HTMLElementTagNameMap,
parent = document
): Element => {
return parent.querySelector(selector)
}
export const qsa = (
selector: string | keyof HTMLElementTagNameMap,
parent = document
): Element[] => {
return [...parent.querySelectorAll(selector)]
}

@ -0,0 +1,80 @@
export const formatCurrency = (
number: number,
currency: string,
locale: string | undefined = undefined
): string => {
const CURRENCY_FORMATTER = new Intl.NumberFormat(locale, {
currency: currency,
style: 'currency'
})
return CURRENCY_FORMATTER.format(number)
}
export const formatNumber = (
number: number,
locale: string | undefined = undefined
): string => {
const NUMBER_FORMATTER = new Intl.NumberFormat(locale)
return NUMBER_FORMATTER.format(number)
}
export const formatCompactNumber = (
number: number,
locale: string | undefined = undefined
): string => {
const COMPACT_NUMBER_FORMATTER = new Intl.NumberFormat(locale, {
notation: 'compact'
})
return COMPACT_NUMBER_FORMATTER.format(number)
}
type DivisionsT = {
amount: number
name:
| 'year'
| 'years'
| 'quarter'
| 'quarters'
| 'month'
| 'months'
| 'week'
| 'weeks'
| 'day'
| 'days'
| 'hour'
| 'hours'
| 'minute'
| 'minutes'
| 'second'
| 'seconds'
}
const DIVISIONS: DivisionsT[] = [
{ amount: 60, name: 'seconds' },
{ amount: 60, name: 'minutes' },
{ amount: 24, name: 'hours' },
{ amount: 7, name: 'days' },
{ amount: 4.34524, name: 'weeks' },
{ amount: 12, name: 'months' },
{ amount: Number.POSITIVE_INFINITY, name: 'years' }
]
export const formatRelativeDate = (
toDate: number,
fromDate: number = new Date().getSeconds(),
locale: string | undefined = undefined
): string => {
const RELATIVE_DATE_FORMATTER = new Intl.RelativeTimeFormat(locale, {
numeric: 'auto'
})
let duration = (toDate - fromDate) / 1000
for (let i = 0; i <= DIVISIONS.length; i++) {
const division = DIVISIONS[i]
if (Math.abs(duration) < division.amount)
return RELATIVE_DATE_FORMATTER.format(Math.round(duration), division.name)
duration /= division.amount
}
}

@ -0,0 +1,8 @@
export { sleep } from './utils.js'
export { qsa, qs, addGlobalEventListener } from './domUtils.js'
export {
formatCompactNumber,
formatNumber,
formatCurrency,
formatRelativeDate
} from './formatters.js'

@ -0,0 +1,3 @@
export const sleep = (time: number): Promise<unknown> => {
return new Promise((resolve) => setTimeout(resolve, time))
}

3062
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -1,14 +1,21 @@
{
"name": "vikingowls-ts-snippets",
"version": "0.0.4",
"description": "Vikingowls typescript snippets library",
"main": "./dist/index.js",
"version": "0.0.6",
"description": "VikingOwls typescript snippets library",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"/dist"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc",
"publish": "yarn run build && npm publish",
"publish-beta": "yarn run build && npm publish --tag beta"
"publish:lib": "npm run build && npm publish",
"publish:beta": "npm run build && npm publish --tag beta",
"publish:dryrun": "npm run build && npm publish --dry-run"
},
"author": "Christian Nachtigall <cw.nachtigall@gmail.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://git.harting.dev/vikingowl/snippets-ts"
@ -22,14 +29,18 @@
"beta",
"library"
],
"author": "Christian Nachtigall <cw.nachtigall@gmail.com>",
"license": "MIT",
"types": "./dist/index.d.ts",
"packageManager": "yarn@3.2.0",
"exports": {
".": "./lib.index.js"
},
"dependencies": {
"typescript": "^4.6.3"
},
"files": [
"/dist"
]
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.30.0",
"@typescript-eslint/parser": "^5.30.0",
"eslint": "^8.18.0",
"eslint-config-prettier": "^8.5.0",
"prettier": "^2.7.1",
"prettier-eslint": "^15.0.1"
}
}

@ -1,24 +0,0 @@
export const addGlobalEventListener = (
type: string,
selector: string,
callback: (arg0: Event) => void,
options: boolean | AddEventListenerOptions,
parent = document
): void => {
parent.addEventListener(
type,
e => {
// @ts-ignore
if (e.target.matches(selector)) callback(e)
},
options
)
}
export const qs = (selector: keyof HTMLElementTagNameMap, parent = document): Element => {
return parent.querySelector(selector)
}
export const qsa = (selector: keyof HTMLElementTagNameMap, parent = document): Element[] => {
return [...parent.querySelectorAll(selector)]
}

@ -1,69 +0,0 @@
export const formatCurrency = (
number: number,
currency: string,
locale: string | undefined = undefined
): string => {
const CURRENCY_FORMATTER = new Intl.NumberFormat(locale, {
currency: currency,
style: "currency",
})
return CURRENCY_FORMATTER.format(number)
}
export const formatNumber = (
number: number,
locale: string | undefined = undefined
): string => {
const NUMBER_FORMATTER = new Intl.NumberFormat(locale)
return NUMBER_FORMATTER.format(number)
}
export const formatCompactNumber = (
number: number,
locale: string | undefined = undefined
): string => {
const COMPACT_NUMBER_FORMATTER = new Intl.NumberFormat(locale, {
notation: "compact"
})
return COMPACT_NUMBER_FORMATTER.format(number)
}
type DivisionsT = {
amount: number
name:
"year" | "years" |
"quarter" | "quarters" |
"month" | "months" |
"week" | "weeks" |
"day" | "days" |
"hour" | "hours" |
"minute" | "minutes" |
"second" | "seconds"
}
const DIVISIONS: DivisionsT[] = [
{ amount: 60, name: "seconds" },
{ amount: 60, name: "minutes" },
{ amount: 24, name: "hours" },
{ amount: 7, name: "days" },
{ amount: 4.34524, name: "weeks" },
{ amount: 12, name: "months" },
{ amount: Number.POSITIVE_INFINITY, name: "years" },
]
export const formatRelativeDate = (
toDate: number,
fromDate: number = new Date().getSeconds(),
locale: string | undefined = undefined
): string => {
const RELATIVE_DATE_FORMATTER = new Intl.RelativeTimeFormat(locale, {
numeric: "auto"
})
let duration = (toDate - fromDate) / 1000
for (let i = 0; i <= DIVISIONS.length; i++) {
const division = DIVISIONS[i]
if (Math.abs(duration) < division.amount) {
return RELATIVE_DATE_FORMATTER.format(Math.round(duration), division.name)
}
duration /= division.amount
}
}

@ -1,3 +0,0 @@
export * from "./utils.js"
export * from "./domUtils.js"
export * from "./formatters.js"

@ -1,3 +0,0 @@
export const sleep = (time: number): Promise<unknown> => {
return new Promise((resolve => setTimeout(resolve, time)))
}

@ -1,11 +1,11 @@
{
"compilerOptions": {
"module": "ESNext",
"module": "CommonJS",
"target": "ESNext",
"declaration": true,
"outDir": "./dist",
"outDir": "./dist"
},
"include": [
"src/**/*"
"lib/**/*"
]
}

@ -1,35 +0,0 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!
__metadata:
version: 6
cacheKey: 8
"typescript@npm:^4.6.3":
version: 4.6.3
resolution: "typescript@npm:4.6.3"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 255bb26c8cb846ca689dd1c3a56587af4f69055907aa2c154796ea28ee0dea871535b1c78f85a6212c77f2657843a269c3a742d09d81495b97b914bf7920415b
languageName: node
linkType: hard
"typescript@patch:typescript@^4.6.3#~builtin<compat/typescript>":
version: 4.6.3
resolution: "typescript@patch:typescript@npm%3A4.6.3#~builtin<compat/typescript>::version=4.6.3&hash=bda367"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 6bf45caf847062420592e711bc9c28bf5f9a9a7fa8245343b81493e4ededae33f1774009d1234d911422d1646a2c839f44e1a23ecb111b40a60ac2ea4c1482a8
languageName: node
linkType: hard
"vikingowls-ts-snippets@^0.0.1, vikingowls-ts-snippets@workspace:.":
version: 0.0.0-use.local
resolution: "vikingowls-ts-snippets@workspace:."
dependencies:
typescript: ^4.6.3
vikingowls-ts-snippets: ^0.0.1
languageName: unknown
linkType: soft
Loading…
Cancel
Save