<commit_before>/**
 * Copyright 2013-2017  <NAME>
 *
 * This file is part of GenieACS.
 *
 * GenieACS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * GenieACS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with GenieACS.  If not, see <http://www.gnu.org/licenses/>.
 */
"use strict";

const common = require('./common');


const CHANGE_FLAGS = {
  object: 2,
  writable: 4,
  value: 8
};


function sanitizeParameterValue(parameterValue) {
  if (parameterValue[0] != null) {
    switch (parameterValue[1]) {
      case 'xsd:boolean':
        if (typeof parameterValue[0] !== 'boolean') {
          parameterValue[0] = !!JSON.parse(parameterValue[0]);
        }
        break;
      case 'xsd:string':
        if (typeof parameterValue[0] !== 'string') {
          parameterValue[0] = '' + parameterValue[0];
        }
        break;
      case 'xsd:int':
      case 'xsd:unsignedInt':
        if (typeof parameterValue[0] !== 'number') {
          parameterValue[0] = +parameterValue[0];
        }
        break;
      case 'xsd:dateTime':
        if (typeof parameterValue[0] !== 'number') {
          let v = +parameterValue[0];
          if (isNaN(v)) {
            v = Date.parse(parameterValue[0]);
            if (isNaN(v))
              v = '' + parameterValue[0];
          }
          parameterValue[0] = v;
        }
        break;
      default:
        if (parameterValue[1] != null)
          throw new Error(`Parameter value type "${parameterValue[1]}" not recognized.`);

        parameterValue[0] = JSON.parse(JSON.stringify(parameterValue[0]));
        break;
    }
  }
  return parameterValue;
}


function getAliasDeclarations(path, timestamp) {<commit_msg>Fix exception when setting invalid bool value<commit_after>/**
 * Copyright 2013-2017  <NAME>
 *
 * This file is part of GenieACS.
 *
 * GenieACS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * GenieACS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with GenieACS.  If not, see <http://www.gnu.org/licenses/>.
 */
"use strict";

const common = require('./common');


const CHANGE_FLAGS = {
  object: 2,
  writable: 4,
  value: 8
};


function parseBool(v) {
  v = "" + v;
  if (v === "true" || v === "TRUE" || v === "True" || v === "1")
    return true;
  else if (v === "false" || v === "FALSE" || v === "False" || v === "0")
    return false;
  else
    return null;
}


function sanitizeParameterValue(parameterValue) {
  if (parameterValue[0] != null) {
    switch (parameterValue[1]) {
      case 'xsd:boolean':
        if (typeof parameterValue[0] !== 'boolean') {
          let v = parseBool(parameterValue[0]);
          if (v == null)
            v = '' + parameterValue[0];
          parameterValue[0] = v;
        }
        break;
      case 'xsd:string':
        if (typeof parameterValue[0] !== 'string') {
          parameterValue[0] = '' + parameterValue[0];
        }
        break;
      case 'xsd:int':
      case 'xsd:unsignedInt':
        if (typeof parameterValue[0] !== 'number') {
          let v = parseInt(parameterValue[0]);
          if (isNaN(v))
            v = '' + parameterValue[0];
          parameterValue[0] = v;
        }
        break;
      case 'xsd:dateTime':
        if (typeof parameterValue[0] !== 'number') {
          let v = parseInt(parameterValue[0]);
          if (isNaN(v)) {
            v = Date.parse(parameterValue[0]);
            if (isNaN(v))
              v = '' + parameterValue[0];
          }
          parameterValue[0] = v;
        }
        break;
      default:
        if (parameterValue[1] != null)
          throw new Error(`Parameter value type "${parameterValue[1]}" not recognized.`);

        parameterValue[0] = JSON.parse(JSON.stringify(parameterValue[0]));
        break;
    }
  }
  return parameterValue;
}


function getAliasDeclarations(path, timestamp) {
{'fraction_non_alphanumeric': 0.12649465072372562, 'fraction_numerical': 0.014264736731697085, 'mean_word_length': 2.5033063923585597, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6384774', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1365, 'n_words': 447}