<commit_before>"use strict";
/*global window*/

var strictEncode = null;
var strictDecode = null;

if (typeof window !== "undefined" && typeof window.btoa === "function") { // When running in a browser.

    strictEncode = function (unencoded) {
        return window.btoa(unencoded);
    };

    strictDecode = function (encoded) {
        return window.atob(encoded);
    };

} else { // When running in Node.

    strictEncode = function (unencoded) {
        return new Buffer(unencoded).toString("base64");
    };

    strictDecode = function (encoded) {
        return new Buffer(encoded, "base64");
    };
}

module.exports = {
    strictEncode: strictEncode,
    strictDecode: strictDecode,

    urlSafeEncode: function (unencoded) {
        return strictEncode(unencoded).replace("+", "-").replace("/", "_");
    },

    urlSafeDecode: function (encoded) {
        return strictDecode(encoded.replace("-", "+").replace("_", "/"));
    }
};<commit_msg>Support `options` in the main `base64it` module<commit_after>"use strict";

var nativeEncode = require("./base64Native").encode;
var nativeDecode = require("./base64Native").decode;
var stripPadding = require("./utils").stripPadding;
var breakIntoPieces = require("./utils").breakIntoPieces;

function applyOptions(encoded, options) {
    options = options || {};
    if (options.stripPadding) {
        encoded = stripPadding(encoded);
    }
    if (options.lineLength) {
        encoded = breakIntoPieces(encoded, options.lineLength);
    }
    if (options.urlSafe) {
        encoded = encoded.replace(/\+/g, "-").replace(/\//g, "_");
    }
    return encoded;
}

function encodeWithOptions(unencoded, options) {
    var encoded = nativeEncode(unencoded);
    return applyOptions(encoded, options);
}

function urlSafeDecode(encoded) {
    return nativeDecode(encoded.replace(/-/g, "+").replace(/_/g, "/"));
}

module.exports = {
    encode: encodeWithOptions,
    decode: urlSafeDecode,

    strictEncode: function (unencoded, options) {
        options = options || {};
        options.urlSafe = false;
        return encodeWithOptions(unencoded, options);
    },
    strictDecode: nativeDecode,

    urlSafeEncode: function (unencoded, options) {
        options = options || {};
        options.urlSafe = true;
        return encodeWithOptions(unencoded, options);
    },
    urlSafeDecode: urlSafeDecode
};
{'fraction_non_alphanumeric': 0.1458069953645175, 'fraction_numerical': 0.004214075010535188, 'mean_word_length': 3.308529945553539, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4576530', 'n_tokens_mistral': 682, 'n_tokens_neox': 667, 'n_words': 153}