<commit_before>define(
  'ephox.phoenix.wrap.Wrapper',

  [
    'ephox.compass.Arr',
    'ephox.perhaps.Option',
    'ephox.phoenix.api.data.Spot',
    'ephox.phoenix.api.general.Split',
    'ephox.phoenix.wrap.Navigation'
  ],

  function (Arr, Option, Spot, Split, Navigation) {
    var wrapWith = function (universe, base, baseOffset, end, endOffset, nu) {
      var nodes = Split.range(universe, base, baseOffset, end, endOffset);
      return wrapper(universe, nodes, nu);
    };

    var wrapper = function (universe, wrapped, nu) {
      if (wrapped.length === 0) return wrapped;

      var filtered = Arr.filter(wrapped, function (x) {
        return universe.property().isText(x) && universe.property().getText(x).length > 0;
      });

      return Arr.map(filtered, function (w) {
        var container = nu();
        universe.insert().before(w, container.element());
        container.wrap(w);
        return container.element();
      });
    };

    var endPoints = function (universe, wrapped) {
      return Option.from(wrapped[0]).map(function (first) {
        var last = Navigation.toLast(universe, wrapped[wrapped.length - 1]);
        return Spot.points(
          Spot.point(first, 0),
          Spot.point(last.element(), last.offset())
        );
      });
    };

    var leaves = function (universe, base, baseOffset, end, endOffset, nu) {<commit_msg>TBIO-175: Wrapper documentation<commit_after>define(
  'ephox.phoenix.wrap.Wrapper',

  [
    'ephox.compass.Arr',
    'ephox.perhaps.Option',
    'ephox.phoenix.api.data.Spot',
    'ephox.phoenix.api.general.Split',
    'ephox.phoenix.wrap.Navigation'
  ],

  function (Arr, Option, Spot, Split, Navigation) {
    /**
     * Wrap all text nodes between two DOM positions, using the nu() wrapper
     */
    var wrapWith = function (universe, base, baseOffset, end, endOffset, nu) {
      var nodes = Split.range(universe, base, baseOffset, end, endOffset);
      return wrapper(universe, nodes, nu);
    };

    /**
     * Wrap non-empty text nodes using the nu() wrapper
     */
    var wrapper = function (universe, wrapped, nu) {
      if (wrapped.length === 0) return wrapped;

      var filtered = Arr.filter(wrapped, function (x) {
        return universe.property().isText(x) && universe.property().getText(x).length > 0;
      });

      return Arr.map(filtered, function (w) {
        var container = nu();
        universe.insert().before(w, container.element());
        container.wrap(w);
        return container.element();
      });
    };

    /**
     * Return the cursor positions at the start and end of a collection of wrapper elements
     */
    var endPoints = function (universe, wrapped) {
      return Option.from(wrapped[0]).map(function (first) {
        var last = Navigation.toLast(universe, wrapped[wrapped.length - 1]);
        return Spot.points(
          Spot.point(first, 0),
    /**
     *
     */
          Spot.point(last.element(), last.offset())
        );
      });
    };

    /**
     * Calls wrapWith() on text nodes in the range, and returns the end points
     */
    var leaves = function (universe, base, baseOffset, end, endOffset, nu) {
{'fraction_non_alphanumeric': 0.14312796208530806, 'fraction_numerical': 0.004107424960505529, 'mean_word_length': 2.6141552511415527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1356821', 'n_tokens_mistral': 983, 'n_tokens_neox': 969, 'n_words': 236}