Skip to content

Commit

Permalink
fix mask federal bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lagden committed May 4, 2021
1 parent 5fb934b commit 813f653
Show file tree
Hide file tree
Showing 17 changed files with 7,485 additions and 26,825 deletions.
3 changes: 0 additions & 3 deletions .babelrc.js

This file was deleted.

5 changes: 3 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ root = true

[*]
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{md,yaml,yml,json}]
[*.{md,yml,json}]
indent_style = space

[*.{md,pug,marko}]
[*.{md,yml}]
trim_trailing_whitespace = false
48 changes: 48 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

module.exports = {
env: {
es2021: true,
node: true
},
parser: '@babel/eslint-parser',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module'
},
plugins: ['html'],
extends: [
'xo',
'plugin:unicorn/recommended'
],
rules: {
indent: ['error', 'tab'],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'never'],
'semi-spacing': [
'error',
{
before: false,
after: true
}
],
'no-console': 0,
camelcase: 0,
'capitalized-comments': 0,
'spaced-comment': 0,
'padding-line-between-statements': 0,
'unicorn/filename-case': 0,
'unicorn/prevent-abbreviations': 0,
'unicorn/prefer-module': 0,
'unicorn/no-zero-fractions': 0,
// 'unicorn/no-abusive-eslint-disable': 0,
// Bug do svelte lint
'no-multiple-empty-lines': [
'error',
{max: 2, maxBOF: 2, maxEOF: 0}
],
// Bug no ctx.body Koa
'require-atomic-updates': 0
}
}
12 changes: 9 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- run: npm ci
- run: npm run coverage
- run: yarn set version berry
- run: >
echo 'nodeLinker: node-modules' >> .yarnrc.yml
- run: ls -la
- run: cat .yarnrc.yml
- run: yarn install
- run: npm test
env:
CI: true

Expand Down
50 changes: 15 additions & 35 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,49 +1,29 @@
dist/*
# node
node_modules

# Yarn
.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
!.yarnrc.yml
.pnp.*

# Logs
logs
*.log
npm-debug.log*
*.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
# Coverage
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
*.lcov
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
103 changes: 73 additions & 30 deletions __test__/index.spec.js → __test__/currency.spec.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,82 @@
/* globals beforeEach expect test document */
/* eslint no-new: 0 */

'use strict'

import simulant from 'simulant'
import Currency from '../src/index.js'
import Currency from '../src/currency.js'

beforeEach(() => {
document.body.innerHTML = '<input id="money" type="text">'
})

test('static mask number default', () => {
const v = Currency.masking(1100)
const v = Currency.masking(1100.00)
expect(v).toEqual('1.100,00')
})

test('Jorge Caetano', () => {
const v = Currency.masking(223.22)
expect(v).toEqual('223,22')
})

test('static mask number', () => {
const v = Currency.masking(1100, {prefix: 'R$'})
expect(v).toEqual('R$ 1.100,00')
const v = Currency.masking(1100, {
options: {
style: 'currency',
currency: 'BRL'
}
})
expect(v).toEqual('R$ 1.100,00')
})

test('static mask number 0', () => {
const v = Currency.masking(0, {prefix: 'R$'})
expect(v).toEqual('R$ 0,00')
const v = Currency.masking(0, {
options: {
style: 'currency',
currency: 'BRL'
}
})
expect(v).toEqual('R$ 0,00')
})

test('static mask number fraction', () => {
const v = Currency.masking(5500.00, {prefix: 'R$'})
expect(v).toEqual('R$ 5.500,00')
const v = Currency.masking(5500.00, {
options: {
style: 'currency',
currency: 'BRL'
}
})
expect(v).toEqual('R$ 5.500,00')
})

test('static mask number string', () => {
const v = Currency.masking('1111', {prefix: 'R$'})
expect(v).toEqual('R$ 11,11')
const v = Currency.masking('1111', {
options: {
style: 'currency',
currency: 'BRL'
}
})
expect(v).toEqual('R$ 11,11')
})

test('static mask number string fraction', () => {
const v = Currency.masking('1111.00', {prefix: 'R$'})
expect(v).toEqual('R$ 1.111,00')
const v = Currency.masking('1111.00', {
options: {
style: 'currency',
currency: 'BRL'
}
})
expect(v).toEqual('R$ 1.111,00')
})

test('static euro', () => {
const v = Currency.masking('1111.00', {sufix: '€'})
expect(v).toEqual('1.111,00 €')
})

test('static position', () => {
const pos = Currency.position('1.111,00 €', {sufix: '€'})
expect(pos).toEqual(8)
const v = Currency.masking('1111.00', {
locales: 'de-DE',
options: {
style: 'currency',
currency: 'EUR'
}
})
expect(v).toEqual('1.111,00 €')
})

test('input', () => {
Expand Down Expand Up @@ -76,23 +106,31 @@ test('keyup', () => {
const mask = new Currency(input, {
keyEvent: 'keyup',
maskOpts: {
sufix: '€'
locales: 'de-DE',
options: {
style: 'currency',
currency: 'EUR'
}
}
})

for (const char of '111199'.split('')) {
input.value += char
simulant.fire(input, 'keyup')
}

expect(input.value).toEqual('1.111,99 €')
expect(input.value).toEqual('1.111,99 €')
mask.destroy()
})

test('blur', () => {
const input = document.querySelector('#money')
input.value = ''

const mask = new Currency(input, {keyEvent: 'keyup', triggerOnBlur: true})
const mask = new Currency(input, {
keyEvent: 'keyup',
triggerOnBlur: true
})
input.value = '1250'
simulant.fire(input, 'blur')

Expand All @@ -115,15 +153,20 @@ test('options', () => {
const input = document.querySelector('#money')
input.value = ''

const mask = new Currency(input, {triggerOnBlur: true, maskOpts: {
prefix: 'US$',
decimal: '.',
thousand: ','
}})
const mask = new Currency(input, {
triggerOnBlur: true,
maskOpts: {
locales: 'en-US',
options: {
style: 'currency',
currency: 'USD'
}
}
})
input.value = '1500099'
simulant.fire(input, 'blur')

expect(input.value).toEqual('US$ 15,000.99')
expect(input.value).toEqual('$15,000.99')
mask.destroy()
})

Expand Down
40 changes: 0 additions & 40 deletions bin/_fn
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,3 @@ abort() {
ok() {
printf "\n \033[32mOk: $@\033[0m\n\n"
}

load_env() {
_DIR="$(pwd)"
ENVFILE_BASE="${2:-$_DIR}/.env-base"
ENVFILE_LOCAL="${2:-$_DIR}/.env-local"
ENVFILE_OPT="${2:-$_DIR}/.env-${1:-development}"
if test ! -e $ENVFILE_BASE -o ! -e $ENVFILE_OPT; then
abort "Environment file not found"
fi

set -a
. ${ENVFILE_BASE}
. ${ENVFILE_OPT}
set +a

if test -e $ENVFILE_LOCAL; then
set -a
. ${ENVFILE_LOCAL}
set +a
fi
}

gen_env() {
_DIR="$(cd -P "$(dirname "$0")" && pwd)"
GEN_ENV="${2:-$_DIR}/gen_env"

if test -z $1; then
abort "Missing output"
fi

if test ! -f "${GEN_ENV}"; then
abort "File not found: ${GEN_ENV}"
fi

_DIR_FILE=$(dirname "$1")
mkdir -p $_DIR_FILE

$GEN_ENV > $1
ok "ENVs generated... ${1}"
}
Loading

0 comments on commit 813f653

Please sign in to comment.