Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

consumed

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consumed

Easy string consumption

  • 1.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by600%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status downloads npm Code Climate Test Coverage dependencies Size

consumed

Easy string consumption for parsing and lexing.

Installation

npm install --save consumed

Summary

Create a new instance of the Consumed object and pass in a string. Then you can use a single letter or a regex pattern to grab part of the string and remove it from the original.

Usage

Node

var Consumed = require('consume');

Browser

Serve dist/consumed.js or dist/consumed.min.js:

<script src="dist/consumed.min.js"></script>
<script>
  var consumer = new Consumed('foo');
</script>

This script is only 446 bytes!

Example

var consumer = new Consumed('foo bar baz');

// Get up to the first instance of a letter
var match = consumer.consumeTill('b');
console.log(match); // 'foo '
console.log(consumer.str); // 'bar baz'

// Get up to the first instance of a letter, but include that letter
match = consumer.consumeTill('b', /*inclusive=*/true);
console.log(match); // 'bar b'
console.log(consumer.str); // 'az'

// Or match a pattern
consumer = new Consumed('foo bar baz');
match = consumer.consume(/.*(.)\1/);
console.log(match); // 'foo'
console.log(consumer.str); // ' bar baz'

Contributing

Please see the contribution guidelines.

Keywords

FAQs

Package last updated on 23 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc