UNPKG

@gpa-gemstone/helper-functions

Version:
45 lines (44 loc) 2.38 kB
"use strict"; // ****************************************************************************************************** // IsCron.ts - Gbtc // // Copyright © 2022, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this // file except in compliance with the License. You may obtain a copy of the License at: // // http://opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 07/18/2022 - G. Santos // Generated original version of source code. // // ****************************************************************************************************** Object.defineProperty(exports, "__esModule", { value: true }); exports.IsCron = IsCron; /** * This function returns a boolean signifing if the string passed in is a valid Cron string or not. * @param value: String to be validated */ function IsCron(value) { var minuteToken = "[1-5]?[0-9]"; // Do we do this string manipulation every time? A way to save on this memory? var hourToken = "[1]?[0-9]|2[0-3]"; var monthDayToken = "[1-9]|[12][0-9]|3[01]"; var monthToken = "[1-9]|1[0-2]"; var weekdayToken = "[0-6]"; var regexCommonExpression = "((?:\\*)|(?:({token},)+{token}{1})|(?:{token}-{token})|(?:(?:\\*\\/)?{token}))"; var regexToken = "(^[*]$)|(^" + regexCommonExpression.replace(/{token}/g, minuteToken) + " " + regexCommonExpression.replace(/{token}/g, hourToken) + " " + regexCommonExpression.replace(/{token}/g, monthDayToken) + " " + regexCommonExpression.replace(/{token}/g, monthToken) + " " + regexCommonExpression.replace(/{token}/g, weekdayToken) + "$)"; return value.toString().match(regexToken) != null; }