How to use trim - 10 common examples

To help you get started, we’ve selected a few trim examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mulesoft / api-notebook / public / scripts / lib / codemirror / strip-input.js View on Github external
var endPosition = { ch: Infinity, line: Infinity };
  var text        = cm.doc.getRange(prevPosition, endPosition);

  // Remove everything after the position
  cm.doc.replaceRange('', prevPosition, endPosition);

  // Trim and/or remove the last line if it is now empty
  var lastLine = trim.right(cm.doc.getLine(cm.doc.lastLine()));

  if (lastLine) {
    cm.doc.setLine(cm.doc.lastLine(), lastLine);
  } else {
    cm.doc.removeLine(cm.doc.lastLine());
  }

  return trim.left(text.substr(string.length));
};
github component / dom / dom.js View on Github external
// List
  if (selector instanceof List) {
    return selector;
  }

  // node
  if (selector.nodeName) {
    return new List([selector]);
  }

  if ('string' != typeof selector) {
    throw new TypeError('invalid selector');
  }

  // html
  var htmlselector = trim.left(selector);
  if (isHTML(htmlselector)) {
    return new List([domify(htmlselector)], htmlselector);
  }

  // selector
  var ctx = context
    ? (context instanceof List ? context[0] : context)
    : document;

  return new List(query.all(selector, ctx), selector);
}
github component / dom / index.js View on Github external
// List
  if (selector instanceof List) {
    return selector;
  }

  // node
  if (selector.nodeName) {
    return new List([selector]);
  }

  if ('string' != typeof selector) {
    throw new TypeError('invalid selector');
  }

  // html
  var htmlselector = trim.left(selector);
  if (isHTML(htmlselector)) {
    return new List([domify(htmlselector)], htmlselector);
  }

  // selector
  var ctx = context
    ? (context instanceof List ? context[0] : context)
    : document;

  return new List(query.all(selector, ctx), selector);
}
github mulesoft / api-notebook / public / scripts / lib / codemirror / strip-input.js View on Github external
var stripInput = function (prevPosition, cm, string) {
  var endPosition = { ch: Infinity, line: Infinity };
  var text        = cm.doc.getRange(prevPosition, endPosition);

  // Remove everything after the position
  cm.doc.replaceRange('', prevPosition, endPosition);

  // Trim and/or remove the last line if it is now empty
  var lastLine = trim.right(cm.doc.getLine(cm.doc.lastLine()));

  if (lastLine) {
    cm.doc.setLine(cm.doc.lastLine(), lastLine);
  } else {
    cm.doc.removeLine(cm.doc.lastLine());
  }

  return trim.left(text.substr(string.length));
};
github auth0 / lock-passwordless / src / cred / country_codes.js View on Github external
export function find(str) {
  let query = trim(str);
  let by;
  if (/^\+?\d+$/.test(query)) {
    by = "diallingCode";
    query = query[0] === "+" ? query : `+${query}`;
    query = query.toLowerCase();
  } else if (query.length <= 2) {
    by = "isoCode";
    query = query.toUpperCase()
  } else {
    by = "country";
    query = query.toLowerCase();
  }

  return countryCodes.filter(x => {
    switch(by) {
      case "diallingCode":
github uschek / somafm / cli.js View on Github external
function showChannel(channel) {
  console.log(
    `  ${chalk.bold(channel.fullTitle)} [${chalk.green(channel.id)}]

${wrap(chalk.blue(channel.description))}

    ${chalk.yellow('Now playing')}   ${trim.left(wrap(channel.lastPlaying, {marginLeft: 18}))}

             ${chalk.yellow('DJ')}   ${channel.dj}
          ${chalk.yellow('Genre')}   ${channel.genre}
      ${chalk.yellow('Listeners')}   ${channel.listeners}

     ${chalk.yellow('Stream URL')}   ${channel.stream.urls[0]}`
  );
}
github remarkjs / remark-vdom / lib / compilers.js View on Github external
function all(parent) {
    var self = this;
    var nodes = parent.children;
    var values = [];
    var index = -1;
    var length = nodes.length;
    var value;
    var prev;

    while (++index < length) {
        value = self.visit(nodes[index], parent);

        if (value) {
            if (prev && prev.type === 'break') {
                if (value.text) {
                    value.text = trim.left(value.text);
                } else if (
                    value.children &&
                    value.children[0] &&
                    value.children[0].text
                ) {
                    value.children[0].text = trim.left(value.children[0].text);
                }
            }

            values = values.concat(value);
        }

        prev = nodes[index];
    }

    return values;
github remarkjs / remark-html / remark-html.js View on Github external
function all(parent) {
    var self = this;
    var nodes = parent.children;
    var values = [];
    var index = -1;
    var length = nodes.length;
    var value;
    var prev;

    while (++index < length) {
        value = self.visit(nodes[index], parent);

        if (value) {
            if (prev && prev.type === 'break') {
                value = trim.left(value);
            }

            values.push(value);
        }

        prev = nodes[index];
    }

    return values;
}
github uschek / somafm / cli.js View on Github external
favourites.getFavourites({search}).then(favouriteItems => {
    for (const item of favouriteItems) {
      let output = favourites.isObject(item) ? item.title : item;

      if (item.channelTitle && item.channelTitle.length > 0) {
        output += ' ' + chalk.dim('· ' + item.channelTitle + ' · ' + dateFormat(item.timestamp, 'YY/MM/DD'));
      }

      console.log(`  ${chalk.red(figures.heart)} ${trim.left(wrap(output, {marginLeft: 4}))}`);
    }
  });
}
github remarkjs / remark-html / lib / compilers.js View on Github external
function all(parent) {
    var self = this;
    var nodes = parent.children;
    var values = [];
    var index = -1;
    var length = nodes.length;
    var value;
    var prev;

    while (++index < length) {
        value = self.visit(nodes[index], parent);

        if (value) {
            if (prev && prev.type === 'break') {
                value = trim.left(value);
            }

            values.push(value);
        }

        prev = nodes[index];
    }

    return values;
}

trim

Trim string whitespace

MIT
Latest version published 4 years ago

Package Health Score

52 / 100
Full package analysis

Popular trim functions