# chai-string

> strings comparison matchers for chai

Latest version **1.6.0** (published 2025-03-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install chai-string
pnpm add chai-string
yarn add chai-string
bun add chai-string
```

## Health

**Score 48/100 (D)** — status: stable.

Positive: has types package; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2025-03-07 |
| First published | 2014-09-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/chai-string) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 35.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Oleg Nechiporenko |
| Maintainers | onechiporenko |
| Keywords | chai, testing, string, chai-plugin, browser |

## Links

- npm: https://www.npmjs.com/package/chai-string
- Repository: https://github.com/onechiporenko/chai-string
- Homepage: https://github.com/onechiporenko/chai-string#readme
- Issues: https://github.com/onechiporenko/chai-string/issues
- npm.io page: https://npm.io/package/chai-string

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 1.6.0 (latest) — 2025-03-07
- 2.0.0 — 2025-02-26
- 1.5.0 — 2018-09-01
- 1.4.0 — 2017-06-13
- 1.3.0 — 2016-11-10
- 1.2.0 — 2016-02-26
- 1.1.6 — 2015-12-24
- 1.1.4 — 2015-11-13
- 1.1.3 — 2015-09-28
- 1.1.2 — 2015-06-09
- 1.1.1 — 2014-12-26
- 1.1.0 — 2014-09-11
- 1.0.0 — 2014-09-02

## README

# chai-string

Matchers for chai to help with common string comparison assertions.

[![Build Status](https://travis-ci.org/onechiporenko/chai-string.png?branch=master)](https://travis-ci.org/onechiporenko/chai-string)
[![Downloads](http://img.shields.io/npm/dm/chai-string.svg)](http://img.shields.io/npm/dm/chai-string.svg)

## Usage

### Browser

```html
<script src="chai.js"></script>
<script src="chai-string.js"></script>
```

### Server

```javascript
var chai = require('chai');
chai.use(require('chai-string'));
```

## Assertions

* startsWith/startWith
* endsWith/endWith
* equalIgnoreCase
* equalIgnoreSpaces
* containIgnoreSpaces
* singleLine
* reverseOf
* palindrome
* entriesCount
* indexOf

All assertions are defined for both the BDD and TDD syntax but some aliases exist to make the assertions look good with both styles.

```javascript
var d1 = 'abcdef',
    d2 = 'abc';

d1.should.startWith.d2
expect(d1).to.startsWith(d2)
assert.startsWith(d1, d2)
```

### startsWith/startWith
```javascript
assert.startsWith('abcdef', 'abc');
expect('abcdef').to.startsWith('abc');
'abcdef'.should.startWith('abc');
```

### endsWith/endWith
```javascript
assert.endsWith('abcdef', 'def');
expect('abcdef').to.endsWith('def');
'abcdef'.should.endWith('def');
```

### equalIgnoreCase
```javascript
assert.equalIgnoreCase('abcdef', 'AbCdEf');
expect('abcdef').to.equalIgnoreCase('AbCdEf');
```

### equalIgnoreSpaces
```javascript
assert.equalIgnoreSpaces('abcdef', 'a\nb\tc\r d  ef');
expect('abcdef').to.equalIgnoreSpaces('a\nb\tc\r d  ef');
```

### containIgnoreSpaces
```javascript
assert.containIgnoreSpaces('abcdefgh', 'a\nb\tc\r d  ef');
expect('abcdefgh').to.containIgnoreSpaces('a\nb\tc\r d  ef');
```

### containIgnoreCase
```javascript
assert.containIgnoreCase('abcdefgh', 'AbcDefGH'); 
expect('abcdefgh').to.containIgnoreCase('AbcDefGH');
'abcdef'.should.containIgnoreCase('cDe');
```

### singleLine
```javascript
assert.singleLine('abcdef');
expect('abcdef').to.be.singleLine();
```

### reverseOf
```javascript
assert.reverseOf('abcdef', 'fedcba');
expect('abcdef').to.be.reverseOf('fedcba');
```

### palindrome
```javascript
assert.palindrome('abccba');
expect('abccba').to.be.palindrome();
```

### entriesCount
```javascript
assert.entriesCount('abcabd', 'ab', 2);
expect('abcabd').to.have.entriesCount('ab', 2);
```

### indexOf
```javascript
assert.indexOf('abcabd', 'ab', 0);
expect('abcabd').to.have.indexOf('ab', 0);
```

## Thanks

Thanks to the [chai-datetime](https://github.com/gaslight/chai-datetime) module for giving me an idea for how to structure and test a chai plugin.

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