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

@maskito/kit

Package Overview
Dependencies
Maintainers
4
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@maskito/kit - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

src/lib/utils/date/raise-segment-value-to-min.d.ts

4

package.json
{
"name": "@maskito/kit",
"version": "0.6.0",
"version": "0.7.0",
"description": "The optional framework-agnostic Maskito's package with ready-to-use masks",

@@ -33,3 +33,3 @@ "keywords": [

"peerDependencies": {
"@maskito/core": "^0.6.0"
"@maskito/core": "^0.7.0"
},

@@ -36,0 +36,0 @@ "main": "./src/index.js",

@@ -22,2 +22,3 @@ import { maskitoPipe } from '@maskito/core';

datesSeparator: DATE_RANGE_SEPARATOR,
dateSegmentSeparator: separator,
}), createMinMaxRangeLengthPostprocessor({

@@ -24,0 +25,0 @@ dateModeTemplate,

import { DEFAULT_MAX_DATE, DEFAULT_MIN_DATE } from '../../../constants';
import { clamp, dateToSegments, parseDateString, segmentsToDate, toDateString, } from '../../../utils';
import { raiseSegmentValueToMin } from '../../../utils/date/raise-segment-value-to-min';
import { parseTimeString } from '../../../utils/time';

@@ -8,10 +9,13 @@ import { isDateTimeStringComplete, parseDateTimeString } from '../utils';

const [dateString, timeString] = parseDateTimeString(value, dateModeTemplate);
const parsedDate = parseDateString(dateString, dateModeTemplate);
const parsedTime = parseTimeString(timeString);
if (!isDateTimeStringComplete(value, dateModeTemplate, timeMode)) {
const fixedDate = raiseSegmentValueToMin(parsedDate, dateModeTemplate);
const fixedValue = toDateString(Object.assign(Object.assign({}, fixedDate), parsedTime), dateModeTemplate, timeMode);
const tail = value.slice(fixedValue.length);
return {
selection,
value: value,
value: fixedValue + tail,
};
}
const parsedDate = parseDateString(dateString, dateModeTemplate);
const parsedTime = parseTimeString(timeString);
const date = segmentsToDate(parsedDate, parsedTime);

@@ -18,0 +22,0 @@ const clampedDate = clamp(date, min, max);

@@ -12,5 +12,10 @@ import { maskitoPipe } from '@maskito/core';

})),
postprocessor: createMinMaxDatePostprocessor({ min, max, dateModeTemplate }),
postprocessor: createMinMaxDatePostprocessor({
min,
max,
dateModeTemplate,
dateSegmentSeparator: separator,
}),
};
}
//# sourceMappingURL=date-mask.js.map

@@ -5,2 +5,3 @@ import { MaskitoOptions } from '@maskito/core';

* @example 0,|00005 => Backspace => |5
* @example -0,|00005 => Backspace => -|5
* @example User types "000000" => 0|

@@ -7,0 +8,0 @@ * @example 0| => User types "5" => 5|

@@ -0,4 +1,6 @@

import { CHAR_MINUS } from '../../../constants';
/**
* It removes leading zeroes for integer part.
* @example 0,|00005 => Backspace => |5
* @example -0,|00005 => Backspace => -|5
* @example User types "000000" => 0|

@@ -12,8 +14,12 @@ * @example 0| => User types "5" => 5|

const [integerPart, decimalPart = ''] = value.split(decimalSeparator);
const integersWithNoRepeatedZeroes = integerPart.replace(/^0+/, '0');
const newIntegerPart = integersWithNoRepeatedZeroes.length > 1 &&
integersWithNoRepeatedZeroes.startsWith('0')
? integersWithNoRepeatedZeroes.slice(1)
: integersWithNoRepeatedZeroes;
const removedCharacters = integerPart.length - newIntegerPart.length;
const zeroTrimmedIntegerPart = trimLeadingZeroes(integerPart);
if (integerPart === zeroTrimmedIntegerPart) {
return { value, selection };
}
const isIntegerPartEmpty = !zeroTrimmedIntegerPart || zeroTrimmedIntegerPart === CHAR_MINUS;
const newIntegerPart = isIntegerPartEmpty
? `${zeroTrimmedIntegerPart}0`
: zeroTrimmedIntegerPart;
const newFrom = from - countTrimmedZeroesBefore(value, from) + Number(isIntegerPartEmpty);
const newTo = to - countTrimmedZeroesBefore(value, to) + Number(isIntegerPartEmpty);
return {

@@ -23,9 +29,13 @@ value: newIntegerPart +

decimalPart,
selection: [
Math.max(from - removedCharacters, 0),
Math.max(to - removedCharacters, 0),
],
selection: [Math.max(newFrom, 0), Math.max(newTo, 0)],
};
};
}
function trimLeadingZeroes(value) {
return value.replace(new RegExp(`^(${CHAR_MINUS})?0+`), '$1');
}
function countTrimmedZeroesBefore(value, index) {
const valueBefore = value.slice(0, index);
return valueBefore.length - trimLeadingZeroes(valueBefore).length;
}
//# sourceMappingURL=leading-zeroes-validation-postprocessor.js.map

@@ -0,1 +1,2 @@

import { CHAR_MINUS } from '../../../constants';
/**

@@ -15,5 +16,6 @@ * It pads integer part with zero if user types decimal separator (for empty input).

}
const valueBeforeCursor = value.slice(0, from);
return {
elementState,
data: value.slice(0, from) ? data : `0${data}`,
data: valueBeforeCursor && valueBeforeCursor !== CHAR_MINUS ? data : `0${data}`,
};

@@ -20,0 +22,0 @@ };

import { MaskitoOptions } from '@maskito/core';
export declare function createMinMaxDatePostprocessor({ dateModeTemplate, min, max, datesSeparator, }: {
export declare function createMinMaxDatePostprocessor({ dateModeTemplate, min, max, datesSeparator, dateSegmentSeparator, }: {
dateModeTemplate: string;

@@ -7,3 +7,4 @@ min?: Date;

datesSeparator?: string;
dateSegmentSeparator?: string;
}): NonNullable<MaskitoOptions['postprocessor']>;
//# sourceMappingURL=min-max-date-postprocessor.d.ts.map
import { DEFAULT_MAX_DATE, DEFAULT_MIN_DATE } from '../constants';
import { clamp, dateToSegments, isDateStringComplete, parseDateRangeString, parseDateString, segmentsToDate, toDateString, } from '../utils';
export function createMinMaxDatePostprocessor({ dateModeTemplate, min = DEFAULT_MIN_DATE, max = DEFAULT_MAX_DATE, datesSeparator = '', }) {
import { raiseSegmentValueToMin } from '../utils/date/raise-segment-value-to-min';
export function createMinMaxDatePostprocessor({ dateModeTemplate, min = DEFAULT_MIN_DATE, max = DEFAULT_MAX_DATE, datesSeparator = '', dateSegmentSeparator = '.', }) {
return ({ value, selection }) => {

@@ -10,7 +11,12 @@ const endsWithDatesSeparator = datesSeparator && value.endsWith(datesSeparator);

validatedValue += validatedValue ? datesSeparator : '';
const parsedDate = parseDateString(dateString, dateModeTemplate);
if (!isDateStringComplete(dateString, dateModeTemplate)) {
validatedValue += dateString;
const fixedDate = raiseSegmentValueToMin(parsedDate, dateModeTemplate);
const fixedValue = toDateString(fixedDate, dateModeTemplate);
const tail = dateString.endsWith(dateSegmentSeparator)
? dateSegmentSeparator
: '';
validatedValue += fixedValue + tail;
continue;
}
const parsedDate = parseDateString(dateString, dateModeTemplate);
const date = segmentsToDate(parsedDate);

@@ -17,0 +23,0 @@ const clampedDate = clamp(date, min, max);

export const getDateSegmentValueLength = (dateString) => {
var _a, _b, _c;
return ({
day: ((_a = dateString.match('/d/g')) === null || _a === void 0 ? void 0 : _a.length) || 2,
month: ((_b = dateString.match('/m/g')) === null || _b === void 0 ? void 0 : _b.length) || 2,
year: ((_c = dateString.match('/y/g')) === null || _c === void 0 ? void 0 : _c.length) || 4,
day: ((_a = dateString.match(/d/g)) === null || _a === void 0 ? void 0 : _a.length) || 0,
month: ((_b = dateString.match(/m/g)) === null || _b === void 0 ? void 0 : _b.length) || 0,
year: ((_c = dateString.match(/y/g)) === null || _c === void 0 ? void 0 : _c.length) || 0,
});
};
//# sourceMappingURL=date-segment-value-length.js.map

@@ -22,3 +22,3 @@ import { padWithZeroesUntilValid } from '../pad-with-zeroes-until-valid';

fantomSeparator +
getDateSegmentValueLength(dateString)[segmentName];
getDateSegmentValueLength(dateModeTemplate)[segmentName];
const isLastSegmentDigitAdded = lastSegmentDigitIndex >= from && lastSegmentDigitIndex <= to;

@@ -29,2 +29,6 @@ if (isLastSegmentDigitAdded && Number(segmentValue) > Number(maxSegmentValue)) {

}
if (isLastSegmentDigitAdded && Number(segmentValue) < 1) {
// 31.0|1.2010 => Type 0 => 31.0|1.2010
return { validatedDateString: '', updatedSelection: [from, to] }; // prevent changes
}
const { validatedSegmentValue, prefixedZeroesCount } = padWithZeroesUntilValid(segmentValue, `${maxSegmentValue}`);

@@ -31,0 +35,0 @@ paddedZeroes += prefixedZeroesCount;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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