# es-set-tostringtag

> A helper to optimistically set Symbol.toStringTag, when possible.

Latest version **2.1.0** (published 2025-01-02) · MIT license · 0 weekly downloads

> **Better alternative:** Use Object.defineProperty(target, Symbol.toStringTag, { value, configurable: true }) — Consider using a lighter alternative

## Install

```sh
npm install es-set-tostringtag
pnpm add es-set-tostringtag
yarn add es-set-tostringtag
bun add es-set-tostringtag
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2025-01-02 |
| First published | 2022-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 0.4 |
| Dependencies | 4 |
| Unpacked size | 14.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Jordan Harband |
| Maintainers | ljharb |

## Links

- npm: https://www.npmjs.com/package/es-set-tostringtag
- Repository: https://github.com/es-shims/es-set-tostringtag
- Homepage: https://github.com/es-shims/es-set-tostringtag#readme
- Issues: https://github.com/es-shims/es-set-tostringtag/issues
- npm.io page: https://npm.io/package/es-set-tostringtag

## Dependencies (4)

- [hasown](https://npm.io/package/hasown.md) ^2.0.2
- [es-errors](https://npm.io/package/es-errors.md) ^1.3.0
- [get-intrinsic](https://npm.io/package/get-intrinsic.md) ^1.2.6
- [has-tostringtag](https://npm.io/package/has-tostringtag.md) ^1.0.2

## Recent versions

- 2.1.0 (latest) — 2025-01-02
- 2.0.3 — 2024-02-20
- 2.0.2 — 2023-10-21
- 2.0.1 — 2023-01-05
- 2.0.0 — 2022-12-21
- 1.0.0 — 2022-12-21

## README

# es-set-tostringtag <sup>[![Version Badge][npm-version-svg]][package-url]</sup>

[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][npm-badge-png]][package-url]

A helper to optimistically set Symbol.toStringTag, when possible.

## Example
Most common usage:
```js
var assert = require('assert');
var setToStringTag = require('es-set-tostringtag');

var obj = {};

assert.equal(Object.prototype.toString.call(obj), '[object Object]');

setToStringTag(obj, 'tagged!');

assert.equal(Object.prototype.toString.call(obj), '[object tagged!]');
```

## Options
An optional options argument can be provided as the third argument. The available options are:

### `force`
If the `force` option is set to `true`, the toStringTag will be set even if it is already set.

### `nonConfigurable`
If the `nonConfigurable` option is set to `true`, the toStringTag will be defined as non-configurable when possible.

## Tests
Simply clone the repo, `npm install`, and run `npm test`

[package-url]: https://npmjs.com/package/es-set-tostringtag
[npm-version-svg]: https://versionbadg.es/es-shims/es-set-tostringtag.svg
[deps-svg]: https://david-dm.org/es-shims/es-set-tostringtag.svg
[deps-url]: https://david-dm.org/es-shims/es-set-tostringtag
[dev-deps-svg]: https://david-dm.org/es-shims/es-set-tostringtag/dev-status.svg
[dev-deps-url]: https://david-dm.org/es-shims/es-set-tostringtag#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/es-set-tostringtag.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/es-set-tostringtag.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/es-set-tostringtag.svg
[downloads-url]: https://npm-stat.com/charts.html?package=es-set-tostringtag
[codecov-image]: https://codecov.io/gh/es-shims/es-set-tostringtag/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/es-shims/es-set-tostringtag/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/es-set-tostringtag
[actions-url]: https://github.com/es-shims/es-set-tostringtag/actions

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