Apply prettier rules

This commit is contained in:
2024-11-14 18:47:38 +01:00
parent 610227815a
commit aa0785fc71
291 changed files with 23646 additions and 22071 deletions

View File

@@ -4,47 +4,44 @@
*/
/// import jQuery
const $ = require('jquery');
const $ = require("jquery");
global.$ = global.jQuery = $;
/// import select2
const select2 = require('select2');
const select2 = require("select2");
global.select2 = select2;
require('select2/dist/css/select2.css');
require('select2-bootstrap-theme/dist/select2-bootstrap.css');
require("select2/dist/css/select2.css");
require("select2-bootstrap-theme/dist/select2-bootstrap.css");
/*
* Load Chill themes assets
*/
require('./chillmain.scss');
require("./chillmain.scss");
import { chill } from './js/chill.js';
import { chill } from "./js/chill.js";
global.chill = chill;
require('./js/date');
require('./js/counter.js');
require("./js/date");
require("./js/counter.js");
/// Load fonts
require('./fonts/OpenSans/OpenSans.scss')
require("./fonts/OpenSans/OpenSans.scss");
/// Load images
require('./img/favicon.ico');
require('./img/logo-chill-sans-slogan_white.png');
require('./img/logo-chill-outil-accompagnement_white.png');
require("./img/favicon.ico");
require("./img/logo-chill-sans-slogan_white.png");
require("./img/logo-chill-outil-accompagnement_white.png");
/*
* Load local libs
* Some libs are only used in a few pages, they are loaded on a case by case basis
*/
require('../lib/breadcrumb/index.js');
require('../lib/download-report/index.js');
require('../lib/select_interactive_loading/index.js');
require("../lib/breadcrumb/index.js");
require("../lib/download-report/index.js");
require("../lib/select_interactive_loading/index.js");
//require('../lib/show_hide/index.js');
//require('../lib/tabs/index.js');

View File

@@ -1,107 +1,111 @@
/* jslint vars: true */
/*jslint indent: 4 */
/* global moment, $, window */
'use strict';
"use strict";
var chill = function() {
var chill = (function () {
/**
* Display an alert message when the user wants to leave a page containing a given form
* in a given state.
*
* The action of displaying the form be parametrised as :
* - always display the alert message when leaving
* - only display the alert message when the form contains some modified fields.
*
* @param{string} form_id An identification string of the form
* @param{string} alert_message The alert message to display
* @param{boolean} check_unsaved_data If true display the alert message only when the form
* contains some modified fields otherwise always display the alert when leaving
* @return nothing
*/
function _generalDisplayAlertWhenLeavingForm(
form_id,
alert_message,
check_unsaved_data,
) {
var form_submitted = false;
var unsaved_data = false;
/**
* Display an alert message when the user wants to leave a page containing a given form
* in a given state.
*
* The action of displaying the form be parametrised as :
* - always display the alert message when leaving
* - only display the alert message when the form contains some modified fields.
*
* @param{string} form_id An identification string of the form
* @param{string} alert_message The alert message to display
* @param{boolean} check_unsaved_data If true display the alert message only when the form
* contains some modified fields otherwise always display the alert when leaving
* @return nothing
*/
function _generalDisplayAlertWhenLeavingForm(form_id, alert_message, check_unsaved_data) {
var form_submitted = false;
var unsaved_data = false;
$(form_id)
.submit(function () {
form_submitted = true;
})
.on("reset", function () {
unsaved_data = false;
});
$(form_id)
.submit(function() {
form_submitted = true;
})
.on('reset', function() {
unsaved_data = false;
})
;
$.each($(form_id).find(":input"), function (i, e) {
$(e).change(function () {
unsaved_data = true;
});
});
$.each($(form_id).find(':input'), function(i,e) {
$(e).change(function() {
unsaved_data = true;
});
});
$(window).bind("beforeunload", function () {
if (!form_submitted && (unsaved_data || !check_unsaved_data)) {
return alert_message;
}
});
}
$(window).bind('beforeunload', function(){
if((!form_submitted) && (unsaved_data || !check_unsaved_data)) {
return alert_message;
}
});
}
/**
* Mark the choices "not specified" as check by default.
*
* This function apply to `custom field choices` when the `required`
* option is false and `expanded` is true (checkboxes or radio buttons).
*
* @param{string} choice_name the name of the input
*/
function checkNullValuesInChoices(choice_name) {
var choices;
choices = $("input[name='"+choice_name+"']:checked");
if (choices.size() === 0) {
$.each($("input[name='"+choice_name+"']"), function (i, e) {
if (e.value === "") {
e.checked = true;
}
});
/**
* Mark the choices "not specified" as check by default.
*
* This function apply to `custom field choices` when the `required`
* option is false and `expanded` is true (checkboxes or radio buttons).
*
* @param{string} choice_name the name of the input
*/
function checkNullValuesInChoices(choice_name) {
var choices;
choices = $("input[name='" + choice_name + "']:checked");
if (choices.size() === 0) {
$.each($("input[name='" + choice_name + "']"), function (i, e) {
if (e.value === "") {
e.checked = true;
}
});
}
}
/**
* Display an alert message when the user wants to leave a page containing a given
* modified form.
*
* @param{string} form_id An identification string of the form
* @param{string} alert_message The alert message to display
* @return nothing
*/
function displayAlertWhenLeavingModifiedForm(form_id, alert_message) {
_generalDisplayAlertWhenLeavingForm(form_id, alert_message, true);
}
/**
* Display an alert message when the user wants to leave a page containing a given
* modified form.
*
* @param{string} form_id An identification string of the form
* @param{string} alert_message The alert message to display
* @return nothing
*/
function displayAlertWhenLeavingModifiedForm(form_id, alert_message) {
_generalDisplayAlertWhenLeavingForm(form_id, alert_message, true);
}
/**
* Display an alert message when the user wants to leave a page containing a given
* form that was not submitted.
*
* @param{string} form_id An identification string of the form
* @param{string} alert_message The alert message to display
* @return nothing
*/
function displayAlertWhenLeavingUnsubmittedForm(form_id, alert_message) {
_generalDisplayAlertWhenLeavingForm(form_id, alert_message, false);
}
/**
* Display an alert message when the user wants to leave a page containing a given
* form that was not submitted.
*
* @param{string} form_id An identification string of the form
* @param{string} alert_message The alert message to display
* @return nothing
*/
function displayAlertWhenLeavingUnsubmittedForm(form_id, alert_message) {
_generalDisplayAlertWhenLeavingForm(form_id, alert_message, false);
}
/* Enable the following behavior : when the user change the value
/* Enable the following behavior : when the user change the value
of an other field, its checkbox is checked.
*/
function checkOtherValueOnChange() {
$('.input-text-other-value').each(function() {
$(this).change(function() {
var checkbox = $(this).parent().find('input[type=checkbox][value=_other]')[0];
$(checkbox).prop('checked', ($(this).val() !== ''));
});
});
}
function checkOtherValueOnChange() {
$(".input-text-other-value").each(function () {
$(this).change(function () {
var checkbox = $(this)
.parent()
.find("input[type=checkbox][value=_other]")[0];
$(checkbox).prop("checked", $(this).val() !== "");
});
});
}
/**
/**
* Create an interraction between two select element (the parent and the
* child) of a given form : each parent option has a category, the
* child select only display options that have the same category of the
@@ -138,208 +142,231 @@ var chill = function() {
- quand vide
- quand choix
*/
function categoryLinkParentChildSelect() {
var forms_to_link = $('form:has(select.chill-category-link-parent)');
function categoryLinkParentChildSelect() {
var forms_to_link = $("form:has(select.chill-category-link-parent)");
forms_to_link.each(function(i,form_selector) {
var form = $(form_selector), parent_multiple;
form.old_category = null;
form.link_parent = $(form).find('.chill-category-link-parent');
form.link_child = $(form).find('.chill-category-link-child');
forms_to_link.each(function (i, form_selector) {
var form = $(form_selector),
parent_multiple;
form.old_category = null;
form.link_parent = $(form).find(".chill-category-link-parent");
form.link_child = $(form).find(".chill-category-link-child");
// check if the parent allow multiple or single results
parent_multiple = $(form).find('.chill-category-link-parent').get(0).multiple;
// if we use select2, parent_multiple will be `undefined`
if (typeof parent_multiple == 'undefined') {
// currently, I do not know how to check if multiple using select2.
// we suppose that multiple is false (old behaviour)
parent_multiple = false
}
// check if the parent allow multiple or single results
parent_multiple = $(form)
.find(".chill-category-link-parent")
.get(0).multiple;
// if we use select2, parent_multiple will be `undefined`
if (typeof parent_multiple == "undefined") {
// currently, I do not know how to check if multiple using select2.
// we suppose that multiple is false (old behaviour)
parent_multiple = false;
}
$(form.link_parent).addClass('select2');
$(form.link_parant).select2({allowClear: true}); // it is weird: when I fix the typo here, the whole stuff does not work anymore...
$(form.link_parent).addClass("select2");
$(form.link_parant).select2({ allowClear: true }); // it is weird: when I fix the typo here, the whole stuff does not work anymore...
if (parent_multiple == false) {
if (parent_multiple == false) {
form.old_category = null;
if ($(form.link_parent).select2("data") !== null) {
form.old_category = $(form.link_parent).select2(
"data",
).element[0].dataset.linkCategory;
}
form.old_category = null;
if($(form.link_parent).select2('data') !== null) {
form.old_category = ($(form.link_parent).select2('data').element[0].dataset.linkCategory);
}
$(form.link_child).find('option')
.each(function(i,e) {
if(
((!$(e).data('link-category')) || $(e).data('link-category') == form.old_category) &&
((!$(e).data('link-categories')) || form.old_category in $(e).data('link-categories').split(','))
) {
$(e).show();
// here, we should handle the optgroup
} else {
$(e).hide();
// here, we should handle the optgroup
}
});
form.link_parent.change(function() {
var new_category = ($(form.link_parent).select2('data').element[0].dataset.linkCategory);
if(new_category != form.old_category) {
$(form.link_child).find('option')
.each(function(i,e) {
if(
((!$(e).data('link-category')) || $(e).data('link-category') == new_category) &&
((!$(e).data('link-categories')) || new_category in $(e).data('link-categories').split(','))
) {
$(e).show();
// here, we should handle the optgroup
} else {
$(e).hide();
// here, we should handle the opgroup
}
});
$(form.link_child).find('option')[0].selected = true;
form.old_category = new_category;
}
});
$(form.link_child)
.find("option")
.each(function (i, e) {
if (
(!$(e).data("link-category") ||
$(e).data("link-category") == form.old_category) &&
(!$(e).data("link-categories") ||
form.old_category in $(e).data("link-categories").split(","))
) {
$(e).show();
// here, we should handle the optgroup
} else {
var i=0,
selected_items = $(form.link_parent).find(':selected');
$(e).hide();
// here, we should handle the optgroup
}
});
form.old_categories = [];
for (i=0;i < selected_items.length; i++) {
form.old_categories.push(selected_items[i].value);
form.link_parent.change(function () {
var new_category = $(form.link_parent).select2("data").element[0]
.dataset.linkCategory;
if (new_category != form.old_category) {
$(form.link_child)
.find("option")
.each(function (i, e) {
if (
(!$(e).data("link-category") ||
$(e).data("link-category") == new_category) &&
(!$(e).data("link-categories") ||
new_category in $(e).data("link-categories").split(","))
) {
$(e).show();
// here, we should handle the optgroup
} else {
$(e).hide();
// here, we should handle the opgroup
}
$(form.link_child).find('option')
.each(function(i,e) {
var visible;
if(form.old_categories.indexOf(e.dataset.linkCategory) != -1) {
$(e).show();
if (e.parentNode instanceof HTMLOptGroupElement) {
$(e.parentNode).show();
}
} else {
$(e).hide();
if (e.parentNode instanceof HTMLOptGroupElement) {
// we check if the other options are visible.
visible = false
for (var l=0; l < e.parentNode.children.length; l++) {
if (window.getComputedStyle(e.parentNode.children[l]).getPropertyValue('display') != 'none') {
visible = true;
}
}
// if any options are visible, we hide the optgroup
if (visible == false) {
$(e.parentNode).hide();
}
}
}
});
form.link_parent.change(function() {
var new_categories = [],
selected_items = $(form.link_parent).find(':selected'),
visible;
for (i=0;i < selected_items.length; i++) {
new_categories.push(selected_items[i].value);
}
if(new_categories != form.old_categories) {
$(form.link_child).find('option')
.each(function(i,e) {
if(new_categories.indexOf(e.dataset.linkCategory) != -1) {
$(e).show();
// if parent is an opgroup, we show it
if (e.parentNode instanceof HTMLOptGroupElement) {
$(e.parentNode).show();
}
} else {
$(e).hide();
// we check if the parent is an optgroup
if (e.parentNode instanceof HTMLOptGroupElement) {
// we check if other options are visible
visible = false
for (var l=0; l < e.parentNode.children.length; l++) {
if (window.getComputedStyle(e.parentNode.children[l]).getPropertyValue('display') != 'none') {
visible = true;
}
}
// if any options are visible, we hide the optgroup
if (visible == false) {
$(e.parentNode).hide();
}
}
}
});
//$(form.link_child).find('option')[0].selected = true;
form.old_categories = new_categories;
}
});
}
});
$(form.link_child).find("option")[0].selected = true;
form.old_category = new_category;
}
});
}
} else {
var i = 0,
selected_items = $(form.link_parent).find(":selected");
function _displayHideTargetWithCheckbox(checkbox) {
var target = checkbox.dataset.displayTarget,
hideableElements;
hideableElements = document.querySelectorAll('[data-display-show-hide="' + target + '"]');
if (checkbox.checked) {
for (let i=0; i < hideableElements.length; i = i+1) {
hideableElements[i].style.display = "unset";
}
} else {
for (let i=0; i < hideableElements.length; i = i+1) {
hideableElements[i].style.display = "none";
}
form.old_categories = [];
for (i = 0; i < selected_items.length; i++) {
form.old_categories.push(selected_items[i].value);
}
$(form.link_child)
.find("option")
.each(function (i, e) {
var visible;
if (form.old_categories.indexOf(e.dataset.linkCategory) != -1) {
$(e).show();
if (e.parentNode instanceof HTMLOptGroupElement) {
$(e.parentNode).show();
}
} else {
$(e).hide();
if (e.parentNode instanceof HTMLOptGroupElement) {
// we check if the other options are visible.
visible = false;
for (var l = 0; l < e.parentNode.children.length; l++) {
if (
window
.getComputedStyle(e.parentNode.children[l])
.getPropertyValue("display") != "none"
) {
visible = true;
}
}
// if any options are visible, we hide the optgroup
if (visible == false) {
$(e.parentNode).hide();
}
}
}
});
form.link_parent.change(function () {
var new_categories = [],
selected_items = $(form.link_parent).find(":selected"),
visible;
for (i = 0; i < selected_items.length; i++) {
new_categories.push(selected_items[i].value);
}
if (new_categories != form.old_categories) {
$(form.link_child)
.find("option")
.each(function (i, e) {
if (new_categories.indexOf(e.dataset.linkCategory) != -1) {
$(e).show();
// if parent is an opgroup, we show it
if (e.parentNode instanceof HTMLOptGroupElement) {
$(e.parentNode).show();
}
} else {
$(e).hide();
// we check if the parent is an optgroup
if (e.parentNode instanceof HTMLOptGroupElement) {
// we check if other options are visible
visible = false;
for (var l = 0; l < e.parentNode.children.length; l++) {
if (
window
.getComputedStyle(e.parentNode.children[l])
.getPropertyValue("display") != "none"
) {
visible = true;
}
}
// if any options are visible, we hide the optgroup
if (visible == false) {
$(e.parentNode).hide();
}
}
}
});
//$(form.link_child).find('option')[0].selected = true;
form.old_categories = new_categories;
}
});
}
});
}
function _displayHideTargetWithCheckbox(checkbox) {
var target = checkbox.dataset.displayTarget,
hideableElements;
hideableElements = document.querySelectorAll(
'[data-display-show-hide="' + target + '"]',
);
if (checkbox.checked) {
for (let i = 0; i < hideableElements.length; i = i + 1) {
hideableElements[i].style.display = "unset";
}
} else {
for (let i = 0; i < hideableElements.length; i = i + 1) {
hideableElements[i].style.display = "none";
}
}
}
/**
* create an interaction between a checkbox and element to show if the
* checkbox is checked, or hide if the checkbox is not checked.
*
* The checkbox must have the data `data-display-target` with an id,
* and the parts to show/hide must have the data `data-display-show-hide`
* with the same value.
*
* Example :
*
* ```
* <input data-display-target="export_abc" value="1" type="checkbox">
*
* <div data-display-show-hide="export_abc">
* <!-- your content here will be hidden / shown according to checked state -->
* </div>
* ```
*
* Hint: for forms in symfony, you could use the `id` of the form element,
* accessible through `{{ form.vars.id }}`. This id should be unique.
*
*
* @returns {undefined}
*/
function listenerDisplayCheckbox() {
var elements = document.querySelectorAll("[data-display-target]");
/**
* create an interaction between a checkbox and element to show if the
* checkbox is checked, or hide if the checkbox is not checked.
*
* The checkbox must have the data `data-display-target` with an id,
* and the parts to show/hide must have the data `data-display-show-hide`
* with the same value.
*
* Example :
*
* ```
* <input data-display-target="export_abc" value="1" type="checkbox">
*
* <div data-display-show-hide="export_abc">
* <!-- your content here will be hidden / shown according to checked state -->
* </div>
* ```
*
* Hint: for forms in symfony, you could use the `id` of the form element,
* accessible through `{{ form.vars.id }}`. This id should be unique.
*
*
* @returns {undefined}
*/
function listenerDisplayCheckbox() {
var elements = document.querySelectorAll("[data-display-target]");
for (let i=0; i < elements.length; i = i+1) {
elements[i].addEventListener("change", function(e) {
_displayHideTargetWithCheckbox(e.target);
});
// initial display-hide
_displayHideTargetWithCheckbox(elements[i]);
}
for (let i = 0; i < elements.length; i = i + 1) {
elements[i].addEventListener("change", function (e) {
_displayHideTargetWithCheckbox(e.target);
});
// initial display-hide
_displayHideTargetWithCheckbox(elements[i]);
}
}
return {
checkOtherValueOnChange: checkOtherValueOnChange,
displayAlertWhenLeavingModifiedForm: displayAlertWhenLeavingModifiedForm,
displayAlertWhenLeavingUnsubmittedForm: displayAlertWhenLeavingUnsubmittedForm,
checkNullValuesInChoices: checkNullValuesInChoices,
categoryLinkParentChildSelect: categoryLinkParentChildSelect,
listenerDisplayCheckbox: listenerDisplayCheckbox,
};
} ();
return {
checkOtherValueOnChange: checkOtherValueOnChange,
displayAlertWhenLeavingModifiedForm: displayAlertWhenLeavingModifiedForm,
displayAlertWhenLeavingUnsubmittedForm:
displayAlertWhenLeavingUnsubmittedForm,
checkNullValuesInChoices: checkNullValuesInChoices,
categoryLinkParentChildSelect: categoryLinkParentChildSelect,
listenerDisplayCheckbox: listenerDisplayCheckbox,
};
})();
export { chill };

View File

@@ -9,27 +9,24 @@
const isNum = (v) => !isNaN(v);
const parseCounter = () => {
document.querySelectorAll('span.counter')
.forEach(el => {
let r = [];
el.innerText
.trim()
.split(' ')
.forEach(w => {
if (isNum(w)) {
r.push(`<span>${w}</span>`);
} else {
r.push(w);
}
})
;
el.innerHTML = r.join(' ');
})
;
document.querySelectorAll("span.counter").forEach((el) => {
let r = [];
el.innerText
.trim()
.split(" ")
.forEach((w) => {
if (isNum(w)) {
r.push(`<span>${w}</span>`);
} else {
r.push(w);
}
});
el.innerHTML = r.join(" ");
});
};
window.addEventListener('DOMContentLoaded', function (e) {
parseCounter();
window.addEventListener("DOMContentLoaded", function (e) {
parseCounter();
});
export { parseCounter };

View File

@@ -12,16 +12,16 @@
* Do not take time into account
*
*/
export const dateToISO = (date: Date|null): string|null => {
export const dateToISO = (date: Date | null): string | null => {
if (null === date) {
return null;
}
return [
date.getFullYear(),
(date.getMonth() + 1).toString().padStart(2, '0'),
date.getDate().toString().padStart(2, '0')
].join('-');
(date.getMonth() + 1).toString().padStart(2, "0"),
date.getDate().toString().padStart(2, "0"),
].join("-");
};
/**
@@ -29,7 +29,7 @@ export const dateToISO = (date: Date|null): string|null => {
*
* **Experimental**
*/
export const ISOToDate = (str: string|null): Date|null => {
export const ISOToDate = (str: string | null): Date | null => {
if (null === str) {
return null;
}
@@ -37,34 +37,32 @@ export const ISOToDate = (str: string|null): Date|null => {
return null;
}
const
[year, month, day] = str.split('-').map(p => parseInt(p));
const [year, month, day] = str.split("-").map((p) => parseInt(p));
return new Date(year, month-1, day, 0, 0, 0, 0);
}
return new Date(year, month - 1, day, 0, 0, 0, 0);
};
/**
* Return a date object from iso string formatted as YYYY-mm-dd:HH:MM:ss+01:00
*
*/
export const ISOToDatetime = (str: string|null): Date|null => {
export const ISOToDatetime = (str: string | null): Date | null => {
if (null === str) {
return null;
}
const
[cal, times] = str.split('T'),
[year, month, date] = cal.split('-').map(s => parseInt(s)),
const [cal, times] = str.split("T"),
[year, month, date] = cal.split("-").map((s) => parseInt(s)),
[time, timezone] = times.split(times.charAt(8)),
[hours, minutes, seconds] = time.split(':').map(s => parseInt(s));
;
if ('0000' === timezone) {
return new Date(Date.UTC(year, month-1, date, hours, minutes, seconds));
[hours, minutes, seconds] = time.split(":").map((s) => parseInt(s));
if ("0000" === timezone) {
return new Date(
Date.UTC(year, month - 1, date, hours, minutes, seconds),
);
}
return new Date(year, month-1, date, hours, minutes, seconds);
}
return new Date(year, month - 1, date, hours, minutes, seconds);
};
/**
* Convert a date to ISO8601, valid for usage in api
@@ -74,39 +72,43 @@ export const datetimeToISO = (date: Date): string => {
let cal, time, offset;
cal = [
date.getFullYear(),
(date.getMonth() + 1).toString().padStart(2, '0'),
date.getDate().toString().padStart(2, '0')
].join('-');
(date.getMonth() + 1).toString().padStart(2, "0"),
date.getDate().toString().padStart(2, "0"),
].join("-");
time = [
date.getHours().toString().padStart(2, '0'),
date.getMinutes().toString().padStart(2, '0'),
date.getSeconds().toString().padStart(2, '0')
].join(':');
date.getHours().toString().padStart(2, "0"),
date.getMinutes().toString().padStart(2, "0"),
date.getSeconds().toString().padStart(2, "0"),
].join(":");
offset = [
date.getTimezoneOffset() <= 0 ? '+' : '-',
Math.abs(Math.floor(date.getTimezoneOffset() / 60)).toString().padStart(2, '0'),
':',
Math.abs(date.getTimezoneOffset() % 60).toString().padStart(2, '0'),
].join('');
date.getTimezoneOffset() <= 0 ? "+" : "-",
Math.abs(Math.floor(date.getTimezoneOffset() / 60))
.toString()
.padStart(2, "0"),
":",
Math.abs(date.getTimezoneOffset() % 60)
.toString()
.padStart(2, "0"),
].join("");
const x = cal + 'T' + time + offset;
const x = cal + "T" + time + offset;
return x;
};
export const intervalDaysToISO = (days: number|string|null): string => {
export const intervalDaysToISO = (days: number | string | null): string => {
if (null === days) {
return 'P0D';
return "P0D";
}
return `P${days}D`;
}
};
export const intervalISOToDays = (str: string|null): number|null => {
export const intervalISOToDays = (str: string | null): number | null => {
if (null === str) {
return null
return null;
}
if ("" === str.trim()) {
@@ -121,40 +123,42 @@ export const intervalISOToDays = (str: string|null): number|null => {
continue;
}
switch (str.charAt(i)) {
case 'P':
case "P":
isDate = true;
break;
case 'T':
case "T":
isDate = false;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case "0":
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
vstring = vstring + str.charAt(i);
break;
case 'Y':
case "Y":
days = days + Number.parseInt(vstring) * 365;
vstring = "";
break;
case 'M':
case "M":
days = days + Number.parseInt(vstring) * 30;
vstring = "";
break;
case 'D':
case "D":
days = days + Number.parseInt(vstring);
vstring = "";
break;
default:
throw Error("this character should not appears: " + str.charAt(i));
throw Error(
"this character should not appears: " + str.charAt(i),
);
}
}
return days;
}
};