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

string-ts

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-ts - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

16

dist/index.d.ts

@@ -134,2 +134,16 @@ /**

/**
* Splits a string into an array of substrings.
* T: The string to split.
* delimiter: The delimiter.
*/
type Split<T, delimiter extends string> = T extends `${infer first}${delimiter}${infer rest}` ? [first, ...Split<rest, delimiter>] : [T];
/**
* A strongly typed version of `String.prototype.split`.
* @param str the string to split.
* @param delimiter the delimiter.
* @returns the splitted string in both type level and runtime.
* @example split('hello world', ' ') // ['hello', 'world']
*/
declare function split<T extends string, D extends string = ''>(str: T, delimiter?: D): Split<T, D>;
/**
* Trims all whitespaces at the start of a string.

@@ -380,2 +394,2 @@ * T: The string to trim.

export { CamelCase, ConstantCase, DeepCamelKeys, DeepConstantKeys, DeepDelimiterKeys, DeepKebabKeys, DeepPascalKeys, DeepSnakeKeys, DelimiterCase, Digit, Is, IsDigit, IsLetter, IsLower, IsSeparator, IsSpecial, IsUpper, Join, KebabCase, PascalCase, Replace, ReplaceAll, Separator, SnakeCase, TitleCase, Trim, TrimEnd, TrimStart, Words, capitalize, deepCamelKeys, deepConstantKeys, deepDelimiterKeys, deepKebabKeys, deepPascalKeys, deepSnakeKeys, deepTransformKeys, join, replace, replaceAll, toCamelCase, toConstantCase, toDelimiterCase, toKebabCase, toLowerCase, toPascalCase, toSnakeCase, toTitleCase, toUpperCase, trim, trimEnd, trimStart, words };
export { CamelCase, ConstantCase, DeepCamelKeys, DeepConstantKeys, DeepDelimiterKeys, DeepKebabKeys, DeepPascalKeys, DeepSnakeKeys, DelimiterCase, Digit, Is, IsDigit, IsLetter, IsLower, IsSeparator, IsSpecial, IsUpper, Join, KebabCase, PascalCase, Replace, ReplaceAll, Separator, SnakeCase, Split, TitleCase, Trim, TrimEnd, TrimStart, Words, capitalize, deepCamelKeys, deepConstantKeys, deepDelimiterKeys, deepKebabKeys, deepPascalKeys, deepSnakeKeys, deepTransformKeys, join, replace, replaceAll, split, toCamelCase, toConstantCase, toDelimiterCase, toKebabCase, toLowerCase, toPascalCase, toSnakeCase, toTitleCase, toUpperCase, trim, trimEnd, trimStart, words };

@@ -34,2 +34,3 @@ "use strict";

replaceAll: () => replaceAll,
split: () => split,
toCamelCase: () => toCamelCase,

@@ -64,2 +65,5 @@ toConstantCase: () => toConstantCase,

}
function split(str, delimiter) {
return str.split(delimiter ?? "");
}
function trimStart(str) {

@@ -165,2 +169,3 @@ return str.trimStart();

replaceAll,
split,
toCamelCase,

@@ -167,0 +172,0 @@ toConstantCase,

5

package.json
{
"name": "string-ts",
"version": "0.4.1",
"version": "0.5.0",
"description": "Strongly-typed string functions.",

@@ -18,6 +18,7 @@ "main": "./dist/index.js",

"devDependencies": {
"@typescript-eslint/eslint-plugin": "latest",
"eslint": "latest",
"prettier": "latest",
"tsup": "latest",
"typescript": "^5.1.3",
"typescript": "^5.1.6",
"vitest": "latest"

@@ -24,0 +25,0 @@ },

@@ -44,2 +44,3 @@ # Strongly-typed string functions for all!

- [replaceAll](#replaceall)
- [split](#split)
- [Strongly-typed alternatives to common loosely-typed functions](#strongly-typed-alternatives-to-common-loosely-typed-functions)

@@ -173,2 +174,13 @@ - [words](#words)

### split
This function is a strongly-typed counterpart of `String.prototype.split`.
```ts
import { split } from 'string-ts';
const str = 'hello-world' as const;
const result = split(str, '-');
// ^ ['hello', 'world']
```
## Strongly-typed alternatives to common loosely-typed functions

@@ -376,2 +388,3 @@

St.ReplaceAll<'hello-world', 'l', '1'> // 'he11o-wor1d'
St.Split<'hello-world', '-'> // ['hello', 'world']
St.TrimStart<' hello world '> // 'hello world '

@@ -378,0 +391,0 @@ St.TrimEnd<' hello world '> // ' hello world'

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