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

angular-date-input

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-date-input - npm Package Compare versions

Comparing version 1.0.0 to 1.3.0

81

dist/angular-date-input.js

@@ -19,6 +19,8 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

function link (scope, element, attrs, ctrl) {
var SEPARATOR = '/'
var MM_DD_YYYY = /^\D*(\d{1,4})(\D+)?(\d{1,2})?(\D+)?(\d{1,4})?/
var dateMask = new StringMask('00/00/0000')
function removeNonDigits (value) {
return value.replace(/[^0-9]/g, '')
return value.replace(/([A-Z]|[a-z])/g, '')
}

@@ -29,3 +31,3 @@

formatedValue = dateMask.apply(value) || ''
return formatedValue.trim().replace(/[^0-9]$/, '')
return removeNonDigits(formatedValue.trim())
}

@@ -38,6 +40,57 @@

return applyDateMask(removeNonDigits(value))
return applyDateMask(value || '')
}
function parser (value) {
var parseDate = function (value) {
var parts = value.match(MM_DD_YYYY)
if (!parts) return []
var month = parts[1] || ''
var separator1 = parts[2] || ''
var date = parts [3] || ''
var separator2 = parts[4] || ''
var year = parts[5] || ''
if (year.length > 0) {
separator2 = SEPARATOR
} else if (separator1 === ' /') {
month = month.substring(0, 1)
separator1 = ''
} else if (month.length === 2 || separator1) {
separator1 = SEPARATOR
} else if (month.length > 2) {
month = month.substring(0, 2)
separator1 = ''
} else if (month.length === 1 && month !== '0' && month !== '1') {
month = '0' + month
separator1 = '/'
} else if (date.length === 1 && date !== '0' && date !== '1' && date !== '2' && date !== '3') {
date = '0' + date
separator2 = '/'
}
if (date && parseInt(date, 10) > 31) {
date = 31
}
if (month && parseInt(month, 10) > 12) {
date = 12
}
var currentYear = (new Date()).getFullYear()
if (year && parseInt(year, 10) > currentYear) {
year = currentYear
}
return [
month,
separator1,
date,
separator2,
year
].filter(Boolean)
}
var parser = function (value) {
if (ctrl.$isEmpty(value)) {

@@ -47,12 +100,24 @@ return value

var formatedValue = applyDateMask(removeNonDigits(value))
var newValue = removeNonDigits(parseDate(value).join(''))
var formattedValue = formatter(newValue)
if (ctrl.$viewValue !== formatedValue) {
ctrl.$setViewValue(formatedValue)
if (ctrl.$viewValue !== newValue) {
ctrl.$setViewValue(newValue)
ctrl.$render()
}
return formatedValue
return removeNonDigits(newValue)
}
element.on('keydown', function (ev) {
if (ev.keyCode === 8) {
var parts = parseDate(ev.target.value)
if (parts.length === 2) {
ctrl.$setViewValue('')
ctrl.$render()
}
}
})
ctrl.$formatters.push(formatter)

@@ -59,0 +124,0 @@ ctrl.$parsers.push(parser)

@@ -17,6 +17,8 @@ var StringMask = require('string-mask')

function link (scope, element, attrs, ctrl) {
var SEPARATOR = '/'
var MM_DD_YYYY = /^\D*(\d{1,4})(\D+)?(\d{1,2})?(\D+)?(\d{1,4})?/
var dateMask = new StringMask('00/00/0000')
function removeNonDigits (value) {
return value.replace(/[^0-9]/g, '')
return value.replace(/([A-Z]|[a-z])/g, '')
}

@@ -27,3 +29,3 @@

formatedValue = dateMask.apply(value) || ''
return formatedValue.trim().replace(/[^0-9]$/, '')
return removeNonDigits(formatedValue.trim())
}

@@ -36,6 +38,57 @@

return applyDateMask(removeNonDigits(value))
return applyDateMask(value || '')
}
function parser (value) {
var parseDate = function (value) {
var parts = value.match(MM_DD_YYYY)
if (!parts) return []
var month = parts[1] || ''
var separator1 = parts[2] || ''
var date = parts [3] || ''
var separator2 = parts[4] || ''
var year = parts[5] || ''
if (year.length > 0) {
separator2 = SEPARATOR
} else if (separator1 === ' /') {
month = month.substring(0, 1)
separator1 = ''
} else if (month.length === 2 || separator1) {
separator1 = SEPARATOR
} else if (month.length > 2) {
month = month.substring(0, 2)
separator1 = ''
} else if (month.length === 1 && month !== '0' && month !== '1') {
month = '0' + month
separator1 = '/'
} else if (date.length === 1 && date !== '0' && date !== '1' && date !== '2' && date !== '3') {
date = '0' + date
separator2 = '/'
}
if (date && parseInt(date, 10) > 31) {
date = 31
}
if (month && parseInt(month, 10) > 12) {
date = 12
}
var currentYear = (new Date()).getFullYear()
if (year && parseInt(year, 10) > currentYear) {
year = currentYear
}
return [
month,
separator1,
date,
separator2,
year
].filter(Boolean)
}
var parser = function (value) {
if (ctrl.$isEmpty(value)) {

@@ -45,14 +98,26 @@ return value

var formatedValue = applyDateMask(removeNonDigits(value))
var newValue = removeNonDigits(parseDate(value).join(''))
var formattedValue = formatter(newValue)
if (ctrl.$viewValue !== formatedValue) {
ctrl.$setViewValue(formatedValue)
if (ctrl.$viewValue !== newValue) {
ctrl.$setViewValue(newValue)
ctrl.$render()
}
return formatedValue
return removeNonDigits(newValue)
}
element.on('keydown', function (ev) {
if (ev.keyCode === 8) {
var parts = parseDate(ev.target.value)
if (parts.length === 2) {
ctrl.$setViewValue('')
ctrl.$render()
}
}
})
ctrl.$formatters.push(formatter)
ctrl.$parsers.push(parser)
}

2

package.json
{
"name": "angular-date-input",
"version": "1.0.0",
"version": "1.3.0",
"description": "angular date input",

@@ -5,0 +5,0 @@ "main": "index.js",

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