1.0.0 • Published 5 years ago

substring-by-coordinates v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

substringByCoordinates

Subtract strings by coordinates.

API

export default function substringByCoordinates(
    str: string,
    start: [number, number],
    end?: [number, number]
): string;
  • str The original string.
  • start The coordinate of where to begin subtracting.
  • end The coordinate of where to stop subtracting.

NOTE: coordinates are 0-indexed, for example, [0, 0] stands for the first line and first column.

Example

let str = `I have a dream, that one day this nation will rise up and live out 
the true meaning of its creed: We hold these truths to be self-evident, that all
men are created equal.`;

assert.strictEqual(substringByCoordinates(str, [0, 0]), str);
assert.strictEqual(substringByCoordinates(str, [0, 0], [2, 22]), str);
assert.strictEqual(substringByCoordinates(str, [0, 0], [0, 14]), "I have a dream");
assert.strictEqual(substringByCoordinates(str, [0, 9], [0, 14]), "dream");

assert.strictEqual(
    substringByCoordinates(str, [1, 31], [1, 70]),
    "We hold these truths to be self-evident"
);

assert.strictEqual(
    substringByCoordinates(str, [0, 21], [1, 29]),
    "one day this nation will rise up and live out \nthe true meaning of its creed"
);