<commit_before>/**
 * is-personnummer
 * https://github.com/frozzare/is-personnummer
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

/**
 * Export the module for AMD, Browser and Node.
 */

(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define([], factory);
  } else if (typeof module !== 'undefined' && module.exports) {
    module.exports = factory();
  } else {
    root.exports = factory();
  }
}(this, function () {

  /**
   * The Luhn algorithm.
   *
   * @param {string|number} str
   *
   * @return {number}
   */

  function luhn (str) {
    var v   = 0,
        sum = 0;

    if (typeof str === 'number') {
      str += '';
    }

    for (var i = 0, l = str.length; i < l; i++) {
      v = str[i];
      v *= 2 - (i % 2);
      if (v > 9) {
        v -= 9;
      }
      sum += v;
    }

    return Math.ceil(sum / 10) * 10 - sum;
  }


  /**
   * Test date if lunh is true.
   *
   * @param {int} year
   * @param {int} month
   * @param {int} day
   *
   * @return {boolean}
   */

  function testDate (year, month, day) {
    month -= 1;
    var date = new Date(year, month, day);
    return !(date.getYear() !== year || date.getMonth() !== month || date.getDate() !== day);
  }


  /**
   * Validate Swedish personal identity numbers.
   *
   * @param {string|number} str
   *
   * @return {boolean}
   */

  return function (str) {
    if (typeof str !== 'number' && typeof str !== 'string') {
      return false;
    }

    str += '';

    var reg     = /^(\d{2}){0,1}(\d{2})(\d{2})(\d{2})([\-|\+]{0,1})?(\d{3})(\d{0,1})$/,
        match   = reg.exec(str);

    if (!match) {
      return false;
    }

    var century = match[1],
        year    = match[2],
        month   = match[3],
        day     = match[4],
        sep     = match[5],
        num     = match[6],
        check   = match[7];

    if (sep === undefined) {
      sep = '-';
    }

    if (year.length === 4) {
      year = year.substr(2)
    }

    var valid = luhn(year + month + day + num) === +check && !!check;

    if (valid && testDate(+year, +month, +day)) {
      return valid;
    }

    return valid && testDate(+year, +month, +day - 60);
  }

}));
<commit_msg>Using short convert to string instead of checking if is number<commit_after>/**
 * is-personnummer
 * https://github.com/frozzare/is-personnummer
 *
 * Copyright (c) 2014 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

/**
 * Export the module for AMD, Browser and Node.
 */

(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define([], factory);
  } else if (typeof module !== 'undefined' && module.exports) {
    module.exports = factory();
  } else {
    root.exports = factory();
  }
}(this, function () {

  /**
   * The Luhn algorithm.
   *
   * @param {string|number} str
   *
   * @return {number}
   */

  function luhn (str) {
    var v   = 0,
        sum = 0;

    str += '';

    for (var i = 0, l = str.length; i < l; i++) {
      v = str[i];
      v *= 2 - (i % 2);
      if (v > 9) {
        v -= 9;
      }
      sum += v;
    }

    return Math.ceil(sum / 10) * 10 - sum;
  }


  /**
   * Test date if lunh is true.
   *
   * @param {int} year
   * @param {int} month
   * @param {int} day
   *
   * @return {boolean}
   */

  function testDate (year, month, day) {
    month -= 1;
    var date = new Date(year, month, day);
    return !(date.getYear() !== year || date.getMonth() !== month || date.getDate() !== day);
  }


  /**
   * Validate Swedish personal identity numbers.
   *
   * @param {string|number} str
   *
   * @return {boolean}
   */

  return function (str) {
    if (typeof str !== 'number' && typeof str !== 'string') {
      return false;
    }

    str += '';

    var reg     = /^(\d{2}){0,1}(\d{2})(\d{2})(\d{2})([\-|\+]{0,1})?(\d{3})(\d{0,1})$/,
        match   = reg.exec(str);

    if (!match) {
      return false;
    }

    var century = match[1],
        year    = match[2],
        month   = match[3],
        day     = match[4],
        sep     = match[5],
        num     = match[6],
        check   = match[7];

    if (sep === undefined) {
      sep = '-';
    }

    if (year.length === 4) {
      year = year.substr(2)
    }

    var valid = luhn(year + month + day + num) === +check && !!check;

    if (valid && testDate(+year, +month, +day)) {
      return valid;
    }

    return valid && testDate(+year, +month, +day - 60);
  }

}));

{'fraction_non_alphanumeric': 0.1953125, 'fraction_numerical': 0.016964285714285713, 'mean_word_length': 1.9097402597402597, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '4449460', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1586, 'n_words': 420}