Skip to content

Releases: gustavoguichard/string-ts

v2.2.0

19 Jun 18:21
f8f8f48
Compare
Choose a tag to compare

What's Changed

Adds a replaceKeys method to shallowly transform the keys of an object with the replace method:

import { replaceKeys } from 'string-ts'

const data = {
  helloWorld: {
    fooBar: 'baz',
  },
} as const
const result = replaceKeys(data, 'o', 'a')
//    ^ { 'hellaWorld': { 'fooBar': 'baz' } }

PRs

Full Changelog: v2.1.1...v2.2.0

v2.1.1

25 Apr 23:37
6d59d0e
Compare
Choose a tag to compare

What's Changed

Full Changelog: v2.0.0...v2.1.1

v2.1.0

18 Mar 20:35
1fc01e9
Compare
Choose a tag to compare

Release notes

This release introduces a bunch of package updates and an important fix from @jly36963 to solve #181 and improve the library when working with interpolated strings or string unions. E.g:

startsWith(`abc${string}`, 'abc') // true

What's Changed

  • fix: handle template literals in startsWith by @jly36963 in #182

  • chore(deps-dev): bump @vitest/coverage-v8 from 1.0.4 to 1.1.0 by @dependabot in #139

  • chore(deps-dev): bump vitest from 1.0.4 to 1.1.0 by @dependabot in #140

  • chore: Better test types error messages by @gustavoguichard in #138

  • chore(deps): bump styfle/cancel-workflow-action from 0.12.0 to 0.12.1 by @dependabot in #163

  • chore(deps): bump codecov/codecov-action from 3 to 4 by @dependabot in #167

  • chore(deps-dev): bump prettier from 3.1.1 to 3.2.5 by @dependabot in #168

  • chore(deps-dev): bump @typescript-eslint/eslint-plugin from 6.15.0 to 7.2.0 by @dependabot in #180

  • chore(deps-dev): bump @vitest/coverage-v8 from 1.1.0 to 1.4.0 by @dependabot in #183

  • chore(deps-dev): bump vitest from 1.1.0 to 1.4.0 by @dependabot in #184

  • chore(deps-dev): bump tsup from 8.0.1 to 8.0.2 by @dependabot in #171

Full Changelog: v2.0.0...v2.1.0

v2.0.0

19 Dec 12:20
11383d7
Compare
Choose a tag to compare

Breaking Changes (not so much)

Now we will drop apostrophes in the casing transformation functions like so:

// string-ts@1.x.x
const result = camelCase(`I can't`)
//     ^? "iCan'T"

// string-ts@2.x.x
const result = camelCase(`I can't`)
//     ^? "iCant"

I personally consider this change a fix instead of a breaking change but we decided to cut a major release to avoid messing up with current expectations.

Improvements

Other PRs

  • chore(deps-dev): bump prettier from 3.0.3 to 3.1.0 by @dependabot in #112
  • chore(deps-dev): bump @typescript-eslint/eslint-plugin from 6.10.0 to 6.11.0 by @dependabot in #113
  • chore(deps-dev): bump tsup from 7.2.0 to 8.0.1 by @dependabot in #119
  • chore(deps-dev): bump typescript from 5.2.2 to 5.3.2 by @dependabot in #118
  • chore(deps-dev): bump @typescript-eslint/eslint-plugin from 6.11.0 to 6.12.0 by @dependabot in #117
  • chore(deps-dev): bump eslint from 8.53.0 to 8.54.0 by @dependabot in #116
  • chore(deps-dev): bump @typescript-eslint/eslint-plugin from 6.12.0 to 6.13.1 by @dependabot in #121
  • chore(deps-dev): bump eslint from 8.54.0 to 8.55.0 by @dependabot in #124
  • chore(deps-dev): bump typescript from 5.3.2 to 5.3.3 by @dependabot in #127
  • chore(deps-dev): bump @typescript-eslint/eslint-plugin from 6.13.1 to 6.13.2 by @dependabot in #126
  • chore(deps-dev): bump @vitest/coverage-v8 from 0.34.6 to 1.0.2 by @dependabot in #128
  • chore(deps-dev): bump prettier from 3.1.0 to 3.1.1 by @dependabot in #130
  • chore(deps-dev): bump @vitest/coverage-v8 from 1.0.2 to 1.0.4 by @dependabot in #131
  • chore(deps-dev): bump vitest from 1.0.2 to 1.0.4 by @dependabot in #132
  • chore(deps-dev): bump @typescript-eslint/eslint-plugin from 6.13.2 to 6.15.0 by @dependabot in #137
  • docs: add hverlin as a contributor for code by @allcontributors in #133
  • chore(deps): bump actions/upload-artifact from 3 to 4 by @dependabot in #135
  • chore(deps-dev): bump eslint from 8.55.0 to 8.56.0 by @dependabot in #136

New Contributors

Full Changelog: v1.3.3...v2.0.0

v1.3.3

09 Nov 12:44
65e139d
Compare
Choose a tag to compare

What's Changed

The results of string functions should now be either deterministic (with string literals or unions of string literals) or fallback to standard types (for string interpolations or anything broader than that), eg:

type A = Slice<'foo', 0, 2> // 'fo'
type B = Slice<'foo' | 'bar', 0, 2> // 'fo' | 'ba'
type C = Slice<`foo${string}`, 0, 2> // string
type D = Slice<'foo', 0, number> // string

Kudos to @jly36963 for taking that challenge πŸ‘

Pull requests

New Contributors

Full Changelog: v1.3.2...v1.3.3

v1.3.2

12 Oct 21:36
ff69fbf
Compare
Choose a tag to compare

What's Changed

  • fix: re-export trim by @jly36963 in #82
  • ci: add dependabot config by @p9f in #84
  • ci: test output against previous version of typescript by @p9f in #83
  • chore(deps-dev): bump eslint from 8.43.0 to 8.51.0 by @dependabot in #85
  • chore(deps): bump actions/setup-node from 2 to 3 by @dependabot in #86
  • chore(deps): bump actions/checkout from 3 to 4 by @dependabot in #88
  • chore(deps-dev): bump prettier from 2.8.8 to 3.0.3 by @dependabot in #89
  • chore(deps): bump styfle/cancel-workflow-action from 0.9.1 to 0.12.0 by @dependabot in #87
  • chore(deps-dev): bump vitest from 0.32.2 to 0.34.6 by @dependabot in #91
  • chore(deps-dev): bump tsup from 7.0.0 to 7.2.0 by @dependabot in #90
  • chore(deps-dev): bump typescript from 5.1.6 to 5.2.2 by @dependabot in #92

New Contributors

Full Changelog: v1.3.0...v1.3.1

v1.3.0 - Organization, tree-shaking, normalization of functions names 🌳

11 Oct 13:37
a3e2eb8
Compare
Choose a tag to compare

What's changed

πŸŽ„ Tree-shaking

This release brings a lot of internal architecture changes to make tree-shakingΒ as easy as possible for the bundlers.
With efforts from all the core contributors we were able to optimize the output of the package and re-organize the whole project to achieve that.

πŸ›‘οΈ 100% coverage

Now every line of string-ts is covered with tests... and we mean type tests too!

🎁 New methods

3 new methods were added:

πŸ”„ reverse

You can now reverse strings at both runtime and type-level. by @mjuksel

πŸ‘¨β€πŸ‘¦ upperCase and lowerCase

Attention, these new methods are different than the native toLowerCase and toUpperCase as the existing ones (which already exist in this library) will only change the case of letters in a string and the new methods work similar to the other casing functions, such as camelCase which will strip separators, split words and join them. So, think of lowerCase as toLowerCase(delimiterCase("Hello-World...", ' ')) => "hello world".

In fact that is the exact implementation of the new lowerCase at both runtime and type-level.

We are not adding the type utilities for these 2 new methods as they would cause a lot of confusion with the default Lowercase and Uppercase from TS. It is easy to build that type utility though:

import { type DelimiterCase } from "string-ts"

type MyLC<T extends string> = Lowercase<DelimiterCase<T, " ">>
type MyUC<T extends string> = Uppercase<DelimiterCase<T, " ">>

πŸ‘΄πŸΌ Deprecations: Renaming and deprecating old casing utilities

As you could see in the section above, there's a difference in functionality between the native String.prototype.toLowerCase (which maps to our toLowerCase) and our own lowerCase method. That is because most of the casing utilities will rely on the words function splitting the words of a string, removing the separators and joining the characters in some fashion.

For that reason we decided to rename that second group by removing the to prefix from those functions. We also deprecated the methods with old names so you want to rename those methods in your project to be prepared for string-ts@v2:

// Prior to string-ts v1.3
import { toCamelCase, toDelimiterCase, toLowerCase } from 'string-ts'

const data = "Hello-World..."
const a = toCamelCase(data) // "helloWorld"
const b = toLowerCase(data) // "hello-world..."
const c = toDelimiterCase(data, '@') // "Hello@World"
const d = toLowerCase(toDelimiterCase(data, ' ')) // "hello world"

// From string-ts v1.3+
import { camelCase, delimiterCase, toLowerCase, lowerCase } from 'string-ts'

const data = "Hello-World..."
const a = camelCase(data) // "helloWorld"
const b = toLowerCase(data) // "hello-world..."
const c = delimiterCase(data, '@') // "Hello@World"
const d = lowerCase(data, ' ') // "hello world"

⬇️ PRs

New Contributors

Full Changelog: v1.2.0...v1.3.0

v1.2.0 - A bunch of other native string methods πŸ“

06 Oct 15:58
4a89d8f
Compare
Choose a tag to compare

New features 🎁

More methods: as we approach 800⭐️ (!!!) we are actively developing strongly-typed counterparts of native string functions.

This versions adds padStart, padEnd, includes, startsWith, endsWith, and our own truncate method.
Is there any method you'd like to see added to this library? Check the section below.

Roadmap πŸ—ΊοΈ

We setup a list in our roadmap and that list is close to completion. Now there are other methods we might implement or not, so make sure you join the discussion if you want to see some of the ❓ methods implemented!

Fixes 🐞

  • The replace now will accept a Regex but if you do it, the resulting type is gonna be loosened to string as TS doesn't do Regex yet.
  • The casing methods, such as toCamelCase, toDelimiterCase, will strip out more separators. Even though it is breaking we consider it a bugfix as toCamelCase('hello [world]') would previously result in "hello[World]" and now it will be "helloWorld"
  • The slice method is not a partial implementation anymore! Now we support the whole native API so you can send positive and negative indexes to both startIndex and endIndex parameters.

PR list πŸ“ˆ

New contributor 🫢

@p9f had already contributed to the library but now he is an official contributor.

Full Changelog: v1.1.0...v1.2.0

v1.1.0 - More strongly-typed string methods 🎁

04 Oct 19:27
0a5f51f
Compare
Choose a tag to compare

What's Changed

This version adds a few more strongly-typed alternatives to the native string methods and by doing so we were able to simplify a lot of the internal methods' implementations.

With a lot of low level properly-typed utilities we can keep both type and runtime implementations in sync, like in this example:

// OLD Implementation
type CamelCase<T extends string> = T extends unknown
  ? PascalCase<T> extends `${infer first}${infer rest}`
    ? `${Lowercase<first>}${rest}`
    : T
  : never

function toCamelCase<T extends string>(str: T) {
  const res = toPascalCase(str)
  return (res.slice(0, 1).toLowerCase() + res.slice(1)) as CamelCase<T> // we needed to cast this type
}

// === πŸͺ„ ===

// NEW Implementation
type CamelCase<T extends string> = Uncapitalize<PascalCase<T>>

function toCamelCase<T extends string>(str: T): CamelCase<T> {
  return uncapitalize(toPascalCase(str)) // type-checks without type casting
}

These changes aim to achieve the goal of this library which is the perfect synchrony between type-level and runtime string functions ❀️.

Support for older JS runtimes

We are now also able to run replaceAll in older browsers that don't yet support it with a very simple polyfill .

Pull requests

Full Changelog: v1.0.0...v1.1.0

v1.0.0 πŸŽ‰

03 Oct 18:04
49fcd88
Compare
Choose a tag to compare

string-ts is trending!

This library got a lot of traffic (+570⭐️ and counting) after @mattpocock 's tweet about it yesterday!
That was the motivation I needed to fix some issues, add some methods, improve the docs, and so on.

The repo also got new contributors with new reported issues and new PR's.
It is now also been actively used in the development of 2 frameworks (AFAIK).

Thank you to all! I'm thrilled about the recognition and I hope you guys are able to make the best out of your literal types!

What's Changed

New Contributors

What makes me even more happy about the recent success of this library is to have received awesome new contributors to it!

  • @jly36963 🧠 became an official contributor to the project ❀️
  • @mattpocock πŸ§™πŸΏβ€β™‚οΈ made their first contribution in #11
  • @iamandrewluca πŸ“¦ made their first contribution in #12
  • @p9f 🎁 made their first contribution in #16

Full Changelog: v0.5.1...v1.0.0