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

@achingbrain/chai-string

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@achingbrain/chai-string

strings comparison matchers for chai

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
157
increased by460.71%
Maintainers
1
Weekly downloads
 
Created
Source

Fork of chai-string

  • Published as ESM
  • Compatible with Chai 5
  • Removes chai.string.XXX, only supports expect/assert style assertions

chai-string

Matchers for chai to help with common string comparison assertions.

Build Status Downloads

Usage

Browser

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

Server

import * as chai from 'chai'
import string from '@achingbrain/chai-string'

chai.use(require('chai-string'))

Assertions

  • startsWith/startWith
  • endsWith/endWith
  • equalIgnoreCase
  • equalIgnoreSpaces
  • containIgnoreSpaces
  • containIgnoreCase
  • 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.

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

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

startsWith/startWith

assert.startsWith('abcdef', 'abc');
expect('abcdef').to.startsWith('abc');
'abcdef'.should.startWith('abc');

endsWith/endWith

assert.endsWith('abcdef', 'def');
expect('abcdef').to.endsWith('def');
'abcdef'.should.endWith('def');

equalIgnoreCase

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

equalIgnoreSpaces

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

containIgnoreSpaces

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

containIgnoreCase

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

singleLine

assert.singleLine('abcdef');
expect('abcdef').to.be.singleLine();

reverseOf

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

palindrome

assert.palindrome('abccba');
expect('abccba').to.be.palindrome();

entriesCount

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

indexOf

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

Thanks

Thanks to the chai-datetime module for giving me an idea for how to structure and test a chai plugin.

Keywords

FAQs

Package last updated on 01 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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