How to use slice-ansi - 7 common examples

To help you get started, we’ve selected a few slice-ansi 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 gajus / table / src / wrapWord.js View on Github external
// https://regex101.com/r/gY5kZ1/1
  const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');

  do {
    let chunk;

    chunk = subject.match(re);

    if (chunk) {
      chunk = chunk[0];

      subject = slice(subject, stringWidth(chunk));

      chunk = chunk.trim();
    } else {
      chunk = slice(subject, 0, size);
      subject = slice(subject, size);
    }

    chunks.push(chunk);
  } while (stringWidth(subject));

  return chunks;
};
github vadimdemedes / ink / src / experimental / output.js View on Github external
for (let line of lines) {
				const currentLine = output[y + offsetY];

				// Line can be missing if `text` is taller than height of pre-initialized `this.output`
				if (!currentLine) {
					continue;
				}

				const length = stringLength(line);

				for (const transformer of transformers) {
					line = transformer(line);
				}

				output[y + offsetY] = sliceAnsi(currentLine, 0, x) + line + sliceAnsi(currentLine, x + length);

				offsetY++;
			}
		}

		const generatedOutput = output
			.map(line => line.trimRight())
			.join('\n');

		return {
			output: generatedOutput,
			height: output.length
		};
	}
}
github vadimdemedes / ink / src / output.js View on Github external
let offsetY = 0;

		for (let line of lines) {
			const length = stringLength(line);
			const currentLine = this.output[y + offsetY];

			// Line can be missing if `text` is taller than height of pre-initialized `this.output`
			if (!currentLine) {
				continue;
			}

			for (const transformer of transformers) {
				line = transformer(line);
			}

			this.output[y + offsetY] = sliceAnsi(currentLine, 0, x) + line + sliceAnsi(currentLine, x + length);

			offsetY++;
		}
	}
github runtools / run / packages / common / src / index.js View on Github external
function truncate(message) {
    return sliceANSI(message, 0, windowSize.width - 3);
  }
}
github gajus / table / src / wrapString.js View on Github external
export default (subject, size) => {
  let subjectSlice;

  subjectSlice = subject;

  const chunks = [];

  do {
    chunks.push(slice(subjectSlice, 0, size));

    subjectSlice = slice(subjectSlice, size).trim();
  } while (stringWidth(subjectSlice));

  return chunks;
};
github nikersify / jay / source / prompt.ts View on Github external
const slice = (start: number, end?: number) =>
				sliceAnsi(highlightedLine, start, end)
github gajus / table / src / wrapWord.js View on Github external
const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');

  do {
    let chunk;

    chunk = subject.match(re);

    if (chunk) {
      chunk = chunk[0];

      subject = slice(subject, stringWidth(chunk));

      chunk = chunk.trim();
    } else {
      chunk = slice(subject, 0, size);
      subject = slice(subject, size);
    }

    chunks.push(chunk);
  } while (stringWidth(subject));

  return chunks;
};

slice-ansi

Slice a string with ANSI escape codes

MIT
Latest version published 6 months ago

Package Health Score

76 / 100
Full package analysis

Popular slice-ansi functions