Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

boleto

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boleto - npm Package Compare versions

Comparing version 0.1.10 to 0.1.11

28

index.js
#!/usr/bin/env node
'use strict';
'use strict'
const inquirer = require('inquirer');
const boleto = require('./lib/boleto');
const inquirer = require('inquirer')
const boleto = require('./lib/boleto')
const twoDigits = (number) => {
return number < 10 ? '0' + number : number;
};
return number < 10 ? '0' + number : number
}
const getDate = (date) => {
const day = twoDigits(date.getDate());
const month = twoDigits(date.getMonth() + 1);
return `${day}/${(month)}/${date.getFullYear()}`;
};
const day = twoDigits(date.getDate())
const month = twoDigits(date.getMonth() + 1)
return `${day}/${(month)}/${date.getFullYear()}`
}

@@ -23,3 +23,3 @@ const questions = [

message: 'Linha digitável:'
},{
}, {
name: 'value',

@@ -29,3 +29,3 @@ type: 'input',

message: 'Valor (inclua os centavos, separando por vírgula):'
},{
}, {
name: 'dueDate',

@@ -36,6 +36,6 @@ type: 'input',

}
];
]
inquirer.prompt(questions, (answers) => {
console.log('Nova linha digitável:', boleto(answers));
});
console.log('Nova linha digitável:', boleto(answers))
})

@@ -1,57 +0,55 @@

;(function(root, factory) {
'use strict';
;(function (root, factory) {
'use strict'
/* istanbul ignore next */
if(typeof define === 'function' && define.amd) {
define('boleto', factory);
if (typeof define === 'function' && define.amd) {
define('boleto', factory)
} else if (typeof exports === 'object') {
exports = module.exports = factory()
} else {
root.boleto = factory()
}
else if(typeof exports === 'object') {
exports = module.exports = factory();
}
else {
root.boleto = factory();
}
})(this, function() {
'use strict';
})(this, function () {
'use strict'
function getMonth(monthId) {
return +monthId - 1;
function getMonth (monthId) {
return +monthId - 1
}
function getDifferenceByDays(miliseconds) {
return miliseconds / 1000 / 60 / 60 / 24;
function getDifferenceByDays (miliseconds) {
return miliseconds / 1000 / 60 / 60 / 24
}
function lessThan14ZerosAtTheEnd(number) {
console.log(number.match(/\d{14}$/));
return !number.match(/\d{14}$/);
function lessThan14ZerosAtTheEnd (number) {
console.log(number.match(/\d{14}$/))
return !number.match(/\d{14}$/)
}
function hasLength47Digits(number) {
console.log(number.length);
return number.length === 47;
function hasLength47Digits (number) {
console.log(number.length)
return number.length === 47
}
function boleto(answers) {
var clearDigits = answers.digits.replace(/\D/g, '');
if(
function boleto (answers) {
var clearDigits = answers.digits.replace(/\D/g, '')
if (
!hasLength47Digits(clearDigits) ||
lessThan14ZerosAtTheEnd(clearDigits)
) {
return 'Linha digitável inválida!';
return 'Linha digitável inválida!'
}
var newDate = answers.dueDate.split('/').map(num => +num);
var firstDate = new Date(1997, getMonth(10), 7);
var dueDate = new Date(newDate[2], getMonth(newDate[1]), newDate[0]);
var value = answers.value.replace(/\D/g, '');
var days = parseInt(getDifferenceByDays(dueDate - firstDate), 10);
var newDate = answers.dueDate.split('/').map((num) => +num)
var firstDate = new Date(1997, getMonth(10), 7)
var dueDate = new Date(newDate[2], getMonth(newDate[1]), newDate[0])
var value = answers.value.replace(/\D/g, '')
var days = parseInt(getDifferenceByDays(dueDate - firstDate), 10)
var newDigits = clearDigits
.replace(/(0{14})$/, (match) => {
return match.replace(/0{4}/, days)
.replace(new RegExp(`0{${value.length}}$`), value);
.replace(new RegExp(`0{${value.length}}$`), value)
})
;
return newDigits;
return newDigits
}
return boleto;
return boleto
})
{
"name": "boleto",
"version": "0.1.10",
"version": "0.1.11",
"description": "Gera uma nova Linha Digitável, adicionando data de vencimento e valor.",
"main": "index.js",
"scripts": {
"lint": "standard --verbose | snazzy",
"test": "echo \"Error: no test specified\" && exit 1"

@@ -25,3 +26,12 @@ },

"inquirer": "^0.12.0"
},
"devDependencies": {
"snazzy": "^3.0.0",
"standard": "^6.0.7"
},
"standard": {
"globals": [
"define"
]
}
}

@@ -1,15 +0,15 @@

;(function(boleto) {
'use strict';
;(function (boleto) {
'use strict'
function $(el) {
return document.querySelector(el);
function $ (el) {
return document.querySelector(el)
}
var $digits = $('[data-js="digits"]');
var $date = $('[data-js="date"]');
var $value = $('[data-js="value"]');
var $generate = $('[data-js="generate"]');
var $newCode = $('[data-js="new-code"]');
var $digits = $('[data-js="digits"]')
var $date = $('[data-js="date"]')
var $value = $('[data-js="value"]')
var $generate = $('[data-js="generate"]')
var $newCode = $('[data-js="new-code"]')
$generate.onclick = function() {
$generate.onclick = function () {
console.log($date.value)

@@ -20,7 +20,7 @@ var newNumber = boleto({

value: $value.value
});
})
$newCode.innerText = newNumber;
$newCode.innerText = newNumber
}
})(window.boleto);
})(window.boleto)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc