<commit_before>'use strict';

const { AsyncStorage } = require('react-native');

/*
 * Adapted from https://github.com/No9/localstorage-down
 */

function AsyncStorageCore(dbname) {
  this._prefix = createPrefix(dbname);
}

const createPrefix = (dbname) => dbname.replace(/!/g, '!!') + '!'; // escape bangs in dbname;
const prepKey = (key, core) => core._prefix + key;
const unprefix = (strings, prefix) => {
  const prefixLen = prefix.length
  return strings
    .filter(str => str.slice(0, prefixLen) === prefix)
    .map(str => str.slice(prefixLen));
}

AsyncStorageCore.prototype.getKeys = function (callback) {
  var keys = [];
  var prefix = this._prefix;
  var prefixSupported = !!AsyncStorage.getAllKeysWithPrefix;
  var getAllKeys = prefixSupported
    ? AsyncStorage.getAllKeysWithPrefix.bind(AsyncStorage, prefix)
    : AsyncStorage.getAllKeys.bind(AsyncStorage);

  getAllKeys((err, allKeys) => {
    if (err) return callback(err);

    if (!prefixSupported) {
      keys = unprefix(allKeys, prefix);
    }

    keys.sort();
    callback(null, keys);
  })
};

AsyncStorageCore.prototype.put = function (key, value, callback) {
  key = prepKey(key, this);
  AsyncStorage.setItem(key, value, callback);
};

AsyncStorageCore.prototype.multiPut = function (pairs, callback) {
  var self = this
  pairs.forEach((pair) => {
    pair[0] = prepKey(pair[0], self);
  })

  AsyncStorage.multiSet(pairs, callback);
};

AsyncStorageCore.prototype.get = function (key, callback) {
  key = prepKey(key, this);
  AsyncStorage.getItem(key, callback);
};

AsyncStorageCore.prototype.multiGet = function (keys, callback) {
  var self = this
  keys = keys.map((key) => {
    return prepKey(key, self)
  })

  AsyncStorage.multiGet(keys)
    .then(function (pairs) {
      callback(null, pairs.map(function (pair) {
        return pair[1]
      }))
    })
    .catch(callback)
};

AsyncStorageCore.prototype.remove = function (key, callback) {
  key = prepKey(key, this);
  AsyncStorage.removeItem(key, callback);
};

AsyncStorageCore.prototype.multiRemove = function (keys, callback) {
  keys = keys.map((key) => prepKey(key, this))
  AsyncStorage.multiRemove(keys, callback);
};

AsyncStorageCore.destroy = function (dbname, callback) {
  var prefix = createPrefix(dbname);
  var prefixLen = prefix.length;
  AsyncStorage.getAllKeys(function(err, keys) {
    if (err) return callback(err);

    keys = keys.filter(function(key) {
      return key.slice(0, prefixLen) === prefix;
    })

    AsyncStorage.multiRemove(keys, callback);
  })
};

module.exports = AsyncStorageCore;<commit_msg>fix: revert deleted edge case optimization for multiRemove<commit_after>'use strict';

const { AsyncStorage } = require('react-native');

/*
 * Adapted from https://github.com/No9/localstorage-down
 */

function AsyncStorageCore(dbname) {
  this._prefix = createPrefix(dbname);
}

const createPrefix = (dbname) => dbname.replace(/!/g, '!!') + '!'; // escape bangs in dbname;
const prepKey = (key, core) => core._prefix + key;
const unprefix = (strings, prefix) => {
  const prefixLen = prefix.length
  return strings
    .filter(str => str.slice(0, prefixLen) === prefix)
    .map(str => str.slice(prefixLen));
}

AsyncStorageCore.prototype.getKeys = function (callback) {
  var keys = [];
  var prefix = this._prefix;
  var prefixSupported = !!AsyncStorage.getAllKeysWithPrefix;
  var getAllKeys = prefixSupported
    ? AsyncStorage.getAllKeysWithPrefix.bind(AsyncStorage, prefix)
    : AsyncStorage.getAllKeys.bind(AsyncStorage);

  getAllKeys((err, allKeys) => {
    if (err) return callback(err);

    if (!prefixSupported) {
      keys = unprefix(allKeys, prefix);
    }

    keys.sort();
    callback(null, keys);
  })
};

AsyncStorageCore.prototype.put = function (key, value, callback) {
  key = prepKey(key, this);
  AsyncStorage.setItem(key, value, callback);
};

AsyncStorageCore.prototype.multiPut = function (pairs, callback) {
  var self = this
  pairs.forEach((pair) => {
    pair[0] = prepKey(pair[0], self);
  })

  AsyncStorage.multiSet(pairs, callback);
};

AsyncStorageCore.prototype.get = function (key, callback) {
  key = prepKey(key, this);
  AsyncStorage.getItem(key, callback);
};

AsyncStorageCore.prototype.multiGet = function (keys, callback) {
  var self = this
  keys = keys.map((key) => {
    return prepKey(key, self)
  })

  AsyncStorage.multiGet(keys)
    .then(function (pairs) {
      callback(null, pairs.map(function (pair) {
        return pair[1]
      }))
    })
    .catch(callback)
};

AsyncStorageCore.prototype.remove = function (key, callback) {
  key = prepKey(key, this);
  AsyncStorage.removeItem(key, callback);
};

AsyncStorageCore.prototype.multiRemove = function (keys, callback) {
  keys = keys.map((key) => prepKey(key, this))
  AsyncStorage.multiRemove(keys, callback);
};

AsyncStorageCore.destroy = function (dbname, callback) {
  var prefix = createPrefix(dbname);
  var prefixLen = prefix.length;
  AsyncStorage.getAllKeys(function(err, keys) {
    if (err) return callback(err);

    keys = keys.filter(function(key) {
      return key.slice(0, prefixLen) === prefix;
    })

    if (!keys.length) {
      return callback();
    }

    AsyncStorage.multiRemove(keys, callback);
  })
};

module.exports = AsyncStorageCore;
{'fraction_non_alphanumeric': 0.147008547008547, 'fraction_numerical': 0.002279202279202279, 'mean_word_length': 4.053742802303263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '2600202', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1663, 'n_words': 352}