@alloc/sqlstring
TypeScript icon, indicating that this package has built-in type declarations

2.3.3 • Public • Published

@alloc/sqlstring

The sqlstring@2.3.3 package with:

  • TypeScript typings
  • new toJSON option

 

The toJSON option

Pass { toJSON: true } to any of the following methods…

  • escape
  • format
  • objectAsValues
  • arrayToList

…and any objects with a toJSON method will be coerced to a JSON string with it.

import { format } from "@alloc/sqlstring";

const arr = [1, 2];
arr.toJSON = () => arr;

// toJSON=false
let sql = format("?", [arr]);
assert.equal(sql, `1, 2`);

// toJSON=true
sql = format("?", [arr]);
assert.equal(sql, `'[1,2]'`);

Package Sidebar

Install

npm i @alloc/sqlstring

Weekly Downloads

2

Version

2.3.3

License

MIT

Unpacked Size

11.4 kB

Total Files

7

Last publish

Collaborators

  • aleclarson