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

@linkdotnet/stringoperations

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@linkdotnet/stringoperations - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

25

dist/data-structure/rope.d.ts

@@ -51,4 +51,23 @@ /**

*/
concatRope(other: Rope, recalculateWeights?: boolean): Rope;
concatRope(other: Rope | undefined, recalculateWeights?: boolean): Rope;
/**
* Splits the rope into two new ones at the defined index
* @param index Zero based index where the rope should be split. The index is always part of the left side of the rope
*/
split(index: number): [Rope, Rope | undefined];
/**
* Inserts another rope into the current one and returns the merger
* @param rope New rope to add to the current one
* @param index Zero based index where the new rope has to be inserted
* @returns The merged rope
*/
insert(rope: Rope, index: number): Rope;
/**
* Deletes a substring from the rope
* @param startIndex Inclusive starting index
* @param length Length to delete
* @returns New rope with deleted range
*/
delete(startIndex: number, length: number): Rope;
/**
* Creates the rope with the given text

@@ -63,4 +82,6 @@ * @param text The initial text to add in the rope

private static charAtInternal;
private static getStrings;
private static splitRope;
private calculateAndSetWeight;
private static getStrings;
private checkRecalculation;
}

@@ -21,5 +21,3 @@ "use strict";

charAt(index) {
if (this.hasToRecaluclateWeights) {
this.calculateAndSetWeight();
}
this.checkRecalculation();
return Rope.charAtInternal(this, index);

@@ -74,3 +72,3 @@ }

if (recalculateWeights) {
newRope.calculateAndSetWeight();
this.checkRecalculation();
}

@@ -80,2 +78,42 @@ return newRope;

/**
* Splits the rope into two new ones at the defined index
* @param index Zero based index where the rope should be split. The index is always part of the left side of the rope
*/
split(index) {
if (index < 0) {
throw new RangeError('Index was negative');
}
this.checkRecalculation();
return Rope.splitRope(this, index);
}
/**
* Inserts another rope into the current one and returns the merger
* @param rope New rope to add to the current one
* @param index Zero based index where the new rope has to be inserted
* @returns The merged rope
*/
insert(rope, index) {
const pair = this.split(index);
const left = pair[0].concatRope(rope);
return left.concatRope(pair[1]);
}
/**
* Deletes a substring from the rope
* @param startIndex Inclusive starting index
* @param length Length to delete
* @returns New rope with deleted range
*/
delete(startIndex, length) {
if (startIndex < 0) {
throw new RangeError('Index was negative');
}
if (length <= 0) {
throw new RangeError('Length has to be at least 1');
}
this.checkRecalculation();
const beforeStartIndex = this.split(startIndex - 1)[0];
const afterEndIndex = this.split(startIndex + length - 1)[1];
return beforeStartIndex.concatRope(afterEndIndex);
}
/**
* Creates the rope with the given text

@@ -117,5 +155,2 @@ * @param text The initial text to add in the rope

}
calculateAndSetWeight() {
this.weight = this.left === undefined ? this.fragment.length : Rope.getWeightInternal(this.left);
}
static getStrings(node, results) {

@@ -131,3 +166,31 @@ if (!node) {

}
static splitRope(node, index) {
if (!node.left) {
if (index === node.weight - 1) {
return [node, undefined];
}
const item1 = Rope.create(node.fragment.slice(0, index + 1));
const item2 = Rope.create(node.fragment.slice(index + 1, node.weight));
return [item1, item2];
}
if (index === node.weight - 1) {
return [node.left, node.right];
}
if (index < node.weight) {
const splitLeftSide = Rope.splitRope(node.left, index);
return [splitLeftSide[0], splitLeftSide[1].concatRope(node.right)];
}
const splitRightSide = Rope.splitRope(node.right, index - node.weight);
return [node.left.concatRope(splitRightSide[0]), splitRightSide[1]];
}
calculateAndSetWeight() {
this.weight = this.left === undefined ? this.fragment.length : Rope.getWeightInternal(this.left);
}
checkRecalculation() {
if (this.hasToRecaluclateWeights) {
this.calculateAndSetWeight();
this.hasToRecaluclateWeights = false;
}
}
}
exports.Rope = Rope;

18

package.json
{
"name": "@linkdotnet/stringoperations",
"version": "0.4.0",
"version": "0.4.1",
"description": "Collection of string utilities. Edit-Distances, Search and Data structures. Offers for example trie, levenshtein distance.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [ "/dist"],
"files": [
"/dist"
],
"scripts": {
"build": "tsc",
"lint:fix": "eslint --fix --ext .ts .",
"test": "jasmine-ts --config=jasmine.json --captureExceptions --verbose"
"lint": "eslint --ext .ts .",
"test": "jest",
"test:coverage": "jest --collectCoverage=true"
},

@@ -29,3 +33,3 @@ "keywords": [

"devDependencies": {
"@types/jasmine": "^3.6.9",
"@types/jest": "^26.0.22",
"@typescript-eslint/eslint-plugin": "^4.19.0",

@@ -36,7 +40,7 @@ "@typescript-eslint/parser": "^4.19.0",

"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.3.3",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.3.1",
"jasmine": "^3.7.0",
"jasmine-spec-reporter": "^6.0.0",
"jasmine-ts": "^0.3.0",
"jest": "^26.6.3",
"ts-jest": "^26.5.4",
"ts-node": "^7.0.1",

@@ -43,0 +47,0 @@ "typescript": "^4.2.3"

# String Operations for TypeScript
![npm](https://img.shields.io/npm/dt/@linkdotnet/stringoperations)
[![NodeJS CI](https://github.com/linkdotnet/ts-stringoperations/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/linkdotnet/ts-stringoperations/actions/workflows/test.yml)

@@ -4,0 +5,0 @@ This library implements some basic string algorithm as well as data structures for a better way of handling strings.

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