# string-saw

> provides an easy way to string together match/replacement operations in an error-free manner

Latest version **0.1.0** (published 2025-11-06) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2025-11-06 |
| First published | 2014-09-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 64 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Chad Scira |
| Maintainers | icodeforlove |

## Links

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

## Recent versions

- 0.1.0 (latest) — 2025-11-06
- 0.0.46 — 2021-06-25
- 0.0.45 — 2021-04-20
- 0.0.44 — 2020-02-07
- 0.0.43 — 2020-01-16
- 0.0.42 — 2019-07-12
- 0.0.41 — 2019-07-10
- 0.0.40 — 2019-07-10
- 0.0.39 — 2019-07-10
- 0.0.38 — 2019-05-25
- 0.0.37 — 2019-05-15
- 0.0.36 — 2019-04-03
- 0.0.35 — 2018-12-11
- 0.0.34 — 2018-11-22
- 0.0.33 — 2018-08-25
- … 31 more at https://npm.io/package/string-saw/versions

## README

## string-saw

Provides an easy way to string together match/replacement operations in an error-free manner.

### Install

```bash
npm install string-saw
```

### Usage (ESM)

```ts
import saw from 'string-saw';

const value = saw('one two three four five six hello 323423 hello')
	.remove(/\d+/g, 'hello')
	.split(' ')
	.slice(3,4)
	.toString(); // "four"
```

CommonJS consumers can use `require('string-saw').default`.

### Single-file browser include (IIFE)

```html
<script src="https://cdn.jsdelivr.net/npm/string-saw@0.0.46/dist/browser/saw.js"></script>
<script>
  // global function: window.stringSaw
  const out = stringSaw('one two').split(' ').join('-').toString();
  console.log(out); // "one-two"
  // or locally alias:
  const saw = window.stringSaw;
  console.log(saw('hello world').match('hello').toBoolean()); // true
</script>
```

### Methods

- match (Array/String/Function/RegExp) -> Saw
- matchAll (RegExp) -> [Array|Object]
- replace (Array|RegExp|String match, String|Function replacement) -> Saw
- remove (String|RegExp [match]) -> Saw
- map (Function func) -> Saw
- item (Integer index) -> Saw
- itemFromRight (Integer offset) -> Saw
- first () -> Saw
- last () -> Saw
- trim () -> Saw
- uniq () -> Saw
- join (String separator|Function separator) -> Saw
- each (Function func) -> Saw
- find (String|RegExp|Function match) -> Saw
- filter (String|RegExp|Function match) -> Saw
- filterNot (String|RegExp|Function match) -> Saw
- reduce (Function func) -> Saw
- slice (Integer start, Integer end) -> Saw
- split (String|RegExp match) -> Saw
- transform (Function context) -> Saw
- upperCase () -> Saw
- lowerCase () -> Saw
- prepend (String) -> Saw
- append (String) -> Saw
- capitalize () -> Saw
- reverse () -> Saw
- sort (Function func) -> Saw
- length () -> Integer
- has (String|RegExp|Function match) -> Boolean
- startsWith (String|[String]) -> Boolean
- endsWith (String|[String]) -> Boolean
- toString () -> String
- toArray () -> Array
- toNumber () -> Integer (0 if no match)
- toInt () -> Integer (can return NaN)
- toFloat () -> Float
- toBoolean () -> Boolean
- toObject () -> Object
- indexOf (String|RegExp|Function match) -> Integer
- indexesOf (String|RegExp|Function match) -> [Integer]

### Examples

```ts
import saw from 'string-saw';

saw('1 2 3')
	.match(/\d+$/)
	.toNumber(); // 3

saw('joe:56, bob:57')
	.matchAll(/(?<name>(\S+)):(?<age>(\d+))/g)
// [
//   { name: 'joe', age: '56' },
//   { name: 'bob', age: '57' }
// ]

saw('1 2 3 4 5')
	.split(' ')
	.itemFromRight(2)
	.toNumber(); // 3

saw([' one ', ' two ', ' three '])
	.trim()
	.join(',')
	.toString(); // "one,two,three"

saw('John. Smith.')
	.match(/\S+/g)
	.remove('.')
	.toObject('first', 'last'); // { first: "John", last: "Smith" }
```

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