Socket
Socket
Sign inDemoInstall

greedy-wrap

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

greedy-wrap - npm Package Compare versions

Comparing version 0.0.1 to 0.1.1

14

index.js
'use strict';
var stringLength = require('string-length');
var ansiRegex = require('ansi-regex');
module.exports = function (str, opts) {

@@ -14,3 +17,4 @@ var recursiveSpaceLeft = 0;

var regex = /\S+|\s?/g;
var ansi = ansiRegex().toString().split('/')[1];
var regex = new RegExp(ansi + "|\\S+|\\s?", "g");
var words = str.match(regex);

@@ -29,3 +33,3 @@ var spaceLeft = width;

if (current.length > width) {
if (stringLength(current) > width) {
var overflow = wrap( current.substr(spaceLeft), { width: width } );

@@ -35,8 +39,8 @@ result += current.substr(0, spaceLeft) + linebreak + overflow;

} else {
if (current.length > spaceLeft) {
if (stringLength(current) > spaceLeft) {
result = result + linebreak + current;
spaceLeft = width - current.length;
spaceLeft = width - stringLength(current);
} else {
result += current;
spaceLeft -= current.length;
spaceLeft -= stringLength(current);
}

@@ -43,0 +47,0 @@ }

{
"name": "greedy-wrap",
"version": "0.0.1",
"version": "0.1.1",
"description": "A recursive greedy algorithm implementation for the word wrap process.",

@@ -22,5 +22,11 @@ "license": "MIT",

"keywords": [
"word-wrap", "word wrap", "greedy", "greedy-wrap"
"word-wrap",
"word wrap",
"greedy",
"greedy-wrap"
],
"dependencies": {},
"dependencies": {
"ansi-regex": "^2.0.0",
"string-length": "^1.0.1"
},
"devDependencies": {

@@ -27,0 +33,0 @@ "mocha": "*"

# greedy-wrap [![Build Status](https://travis-ci.org/danilosampaio/greedy-wrap.svg?branch=master)](https://travis-ci.org/danilosampaio/greedy-wrap)
> A recursive greedy algorithm implementation for the word wrap process.
> It also correctly calculate the width of the words containing ansi escape codes.

@@ -28,2 +29,3 @@

greedyWrap('Supercalifragilisticexpialidocious', {width: 10});

@@ -37,2 +39,12 @@

ious
greedyWrap('\u001b[1mthis\u001b[22m is a text with only \u001b[1mshort\u001b[22m words.', {width: 10})
//=> Result:
this is a
text with
only short
words.
```

@@ -39,0 +51,0 @@

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