Skip to content

Commit

Permalink
feat: add vanilla masker definition file
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOliveiraM committed Mar 1, 2023
1 parent 8585949 commit dfd52e9
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"react",
"typescript"
],
"version": "2.1.18",
"version": "2.1.19",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -57,7 +57,6 @@
"@types/react": "^18.0.23",
"@types/react-dom": "^18.0.7",
"@types/styled-components": "^5.1.26",
"@types/vanilla-masker": "^1.2.1",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"babel-loader": "^8.2.5",
Expand Down
52 changes: 52 additions & 0 deletions src/types/vanilla-masker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Type definitions for vanilla-masker 1.2
// Project: https://fleury.io/vanilla-masker/
// Definitions by: BenLorantfy <https://github.com/BenLorantfy>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

declare module 'vanilla-masker' {
type MoneyOptions = {
// Decimal precision -> "90"
precision?: number | undefined

// Decimal separator -> ",90"
separator?: string | undefined

// Number delimiter -> "12.345.678"
delimiter?: string | undefined

// Money unit -> "R$ 12.345.678,90"
unit?: string | undefined

// Money unit -> "12.345.678,90 R$"
suffixUnit?: string | undefined

// Force type only number instead decimal,
// masking decimals with ",00"
// Zero cents -> "R$ 1.234.567.890,00"
zeroCents?: boolean | undefined
}

type PatternOptions = {
// Pattern to mask value against.
pattern?: string | undefined

// Placeholder option to represent remaining characters to be entered
placeholder?: string | undefined
}

const VMasker: {
(el: Element | NodeListOf<Element>): {
maskMoney: (options?: MoneyOptions) => void
maskNumber: () => void
maskAlphaNum: () => void
maskPattern: (pattern: string) => void
unMask: () => void
}
toMoney: (value: string | number, options?: MoneyOptions) => string
toPattern: (value: string | number, options?: string | PatternOptions) => string
toNumber: (value: string | number) => string
toAlphaNumeric: (value: string | number) => string
}

export = VMasker
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["src"],
"include": ["src", "**/*.ts", "**/*.tsx", "**/*.d.ts"],
"exclude": ["node_modules", "dist"],
"compilerOptions": {
"resolveJsonModule": true,
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3290,11 +3290,6 @@
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.6.tgz#250a7b16c3b91f672a24552ec64678eeb1d3a08d"
integrity sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==

"@types/vanilla-masker@^1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@types/vanilla-masker/-/vanilla-masker-1.2.1.tgz#5eb024a7ee9d5e9e2caf7e61cb07c37a80c74445"
integrity sha512-b5ajZhEff5Ymf0znJ6ReHd4RIzZxb8QORD52/gC9qiG1wgBG+uraJbOgIXIyn4/OLOko/bmDajXuxn2WnYD3ew==

"@types/webpack-env@^1.16.0":
version "1.16.3"
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.16.3.tgz#b776327a73e561b71e7881d0cd6d34a1424db86a"
Expand Down

0 comments on commit dfd52e9

Please sign in to comment.