# @unsass/string

> Composable Sass functions to manipulate, search and trim strings.

Latest version **1.5.0** (published 2026-09-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @unsass/string
pnpm add @unsass/string
yarn add @unsass/string
bun add @unsass/string
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; has provenance; recently updated.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.5.0 |
| Published | 2026-09-20 |
| First published | 2022-09-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=22 |
| Dependencies | 1 |
| Unpacked size | 14.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | Front Factory |
| Maintainers | bdamevin |
| Keywords | sass, scss, string, replace, number, unsass, front-end |

## Links

- npm: https://www.npmjs.com/package/@unsass/string
- Repository: https://github.com/unsass/unsass
- Homepage: https://github.com/unsass/unsass/tree/main/packages/string#readme
- Issues: https://github.com/unsass/unsass/issues
- npm.io page: https://npm.io/package/@unsass/string

## Dependencies (1)

- [@unsass/types](https://npm.io/package/@unsass/types.md) ^1.1.0

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 1.5.0 (latest) — 2026-09-20
- 1.4.4 — 2025-06-13
- 1.4.3 — 2023-03-21
- 1.4.2 — 2023-03-17
- 1.4.1 — 2023-01-30
- 1.4.0 — 2023-01-30
- 1.3.0 — 2022-10-17
- 1.2.0 — 2022-10-13
- 1.1.0 — 2022-10-13
- 1.0.0 — 2022-09-27

## README

# String

[![Version](https://flat.badgen.net/npm/v/@unsass/string)](https://www.npmjs.com/package/@unsass/string)
[![Downloads](https://flat.badgen.net/npm/dt/@unsass/string)](https://www.npmjs.com/package/@unsass/string)
[![License](https://flat.badgen.net/npm/license/@unsass/string)](https://www.npmjs.com/package/@unsass/string)

## Introduction

A small, dependency-free Sass toolkit for manipulating strings. Replace, trim, test and combine strings with concise,
composable functions, and keep the Sass built-in `sass:string` functions available under the same namespace.

<div align="center">

![String](.github/banner.svg)

</div>

## Installing

```shell
npm install @unsass/string
```

## Usage

```scss
@use "@unsass/string";

$slug: string.replace("foo bar", " ", "-"); // "foo-bar"
```

The module also forwards the Sass built-in [`sass:string`](https://sass-lang.com/documentation/modules/string)
functions, so `string.length()`, `string.slice()` and friends are available through the same namespace.

## Functions

### `replace($string, $query, $replace)`

Replaces every occurrence of a substring. `$replace` defaults to an empty string, which removes the substring.

```scss
@use "@unsass/string";

$replaced: string.replace("The quick brown fox jumps over the lazy dog.", "dog", "monkey");
// "The quick brown fox jumps over the lazy monkey."

$removed: string.replace("foo-bar-baz", "-");
// "foobarbaz"
```

### `to-number($value)`

Converts a string of digits to a number.

```scss
@use "@unsass/string";

$number: string.to-number("42"); // 42
```

### `from-number($value)`

Converts a number to a string.

```scss
@use "@unsass/string";

$string: string.from-number(10); // "10"
```

### `starts-with($string, $substring)`

Checks whether a string starts with a substring.

```scss
@use "@unsass/string";

$result: string.starts-with("button-label", "button"); // true
```

### `ends-with($string, $substring)`

Checks whether a string ends with a substring.

```scss
@use "@unsass/string";

$result: string.ends-with("button-label", "label"); // true
```

### `trim-start($string, $target)`

Removes one leading occurrence of `$target`, which defaults to a whitespace.

```scss
@use "@unsass/string";

$string: string.trim-start("--primary-color", "--"); // "primary-color"
```

### `trim-end($string, $target)`

Removes one trailing occurrence of `$target`, which defaults to a whitespace.

```scss
@use "@unsass/string";

$string: string.trim-end("primary-color--", "--"); // "primary-color"
```

### `trim($string, $start, $end)`

Removes one leading and one trailing occurrence. `$start` defaults to a whitespace, and `$end` defaults to `$start`.

```scss
@use "@unsass/string";

$whitespace: string.trim(" foo "); // "foo"
$custom: string.trim("var(--primary-color)", "var(", ")"); // "--primary-color"
```

### `combine($values…)`

Joins strings with a dash. Falsy values (`null`, `false`) are skipped.

```scss
@use "@unsass/string";

$string: string.combine("button", "label"); // "button-label"
$skipped: string.combine("button", null, "label"); // "button-label"
```

---
_Source: https://npm.io/package/@unsass/string · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
