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

string-tool

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-tool - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

.travis.yml

11

package.json
{
"name": "string-tool",
"version": "1.2.0",
"version": "1.2.1",
"description": "Useful functions for handling Strings",
"main": "string-tool.es5.js",
"scripts": {
"test": "make test"
},
"keywords": [

@@ -14,2 +10,7 @@ "string"

"license": "GPLv3",
"repository": "JannesMeyer/string-tool",
"scripts": {
"test": "make test"
},
"main": "string-tool.es5.js",
"devDependencies": {

@@ -16,0 +17,0 @@ "babel": "x",

@@ -1,6 +0,5 @@

import { startsWith, capitalize } from '../string-tool.es5';
import { startsWith, capitalize, nthIndexOf, cutFirst, cutFromIndex } from '../';
describe('startsWith', () => {
it('should return true when the string starts with another string', () => {
describe("startsWith", () => {
it("should return true when the string starts with another string", () => {
expect(startsWith('A test', 'A t')).toBe(true);

@@ -10,11 +9,9 @@ expect(startsWith('A test', 'A test')).toBe(true);

it('should return false when the string starts with something else', () => {
it("should return false when the string starts with something else", () => {
expect(startsWith('something', 'nothing')).toBe(false);
});
});
describe('capitalize', () => {
it('should return true when the first letter was capitalized correctly', () => {
describe("capitalize", () => {
it("should return true when the first letter was capitalized correctly", () => {
expect(capitalize('a')).toEqual('A');

@@ -26,6 +23,15 @@ expect(capitalize('ß')).toEqual('SS');

it('should return an empty string when the input is empty', () => {
it("should return an empty string when the input is empty", () => {
expect(capitalize('')).toEqual('');
});
});
describe("nthIndexOf", () => {
it("should find the position of the searchString", () => {
expect(nthIndexOf('test test test', 'test', 2)).toEqual(5);
});
it("should return undefined when the searchString doesn't exist", () => {
expect(nthIndexOf('bla bla bla', 'test', 2)).toBe(undefined);
});
});
/**
* Check if the string starts with another string
* Checks if `str` starts with the `searchString`
*/

@@ -9,6 +9,43 @@ export function startsWith(str, searchString) {

/**
* Capitalize the first letter of a string
* Capitalizes the first letter of `str`
*/
export function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
/**
* Finds the index of the nth occurence of `searchString`
*
* @see: String.prototype.indexOf
* @see: String.prototype.lastIndexOf
*/
export function nthIndexOf(str, searchString, n, fromIndex) {
for (var i = 0; i < n && fromIndex !== -1; i++) {
if (fromIndex !== undefined) {
fromIndex += 1;
}
fromIndex = str.indexOf(searchString, fromIndex);
}
return (fromIndex === -1 ? undefined : fromIndex);
}
/**
* Remove the first occurence of `searchString`
*/
export function cutFirst(str, searchString) {
var index = str.indexOf(searchString);
if (index === -1) {
return str;
}
return str.slice(0, index) + str.slice(index + searchString.length);
}
/**
* Remove everything after `fromIndex`
*/
export function cutFromIndex(str, fromIndex) {
if (fromIndex === -1 || fromIndex === undefined) {
return str;
}
return str.slice(0, fromIndex);
}

Sorry, the diff of this file is not supported yet

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