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

sql-formatter

Package Overview
Dependencies
Maintainers
2
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql-formatter - npm Package Compare versions

Comparing version 12.0.4 to 12.0.5

24

lib/formatter/formatCommaPositions.js

@@ -26,3 +26,3 @@ import { maxLength } from '../utils.js';

* ' foo,',
* ' bar,',
* ' bar, --comment',
* ' baz',

@@ -36,3 +36,3 @@ * 'FROM'

* ['SELECT'],
* [' foo,', ' bar,', ' baz'],
* [' foo,', ' bar, --comment', ' baz'],
* ['FROM']

@@ -50,3 +50,3 @@ * ]

while (lines[i].match(/.*,$/)) {
while (lines[i].match(/.*,(\s*(--.*)?$)/)) {
i++;

@@ -64,4 +64,4 @@ group.push(lines[i]);

function formatTabular(commaLines) {
const maxLineLength = maxLength(commaLines);
return trimTrailingCommas(commaLines).map((line, i) => {
const commaPosition = maxLength(trimTrailingComments(commaLines)) - 1;
return commaLines.map((line, i) => {
if (i === commaLines.length - 1) {

@@ -71,6 +71,12 @@ return line; // do not add comma for last item

return line + ' '.repeat(maxLineLength - line.length - 1) + ',';
return indentComma(line, commaPosition);
});
}
function indentComma(line, commaPosition) {
const [, code, comment] = line.match(/^(.*?),(\s*--.*)?$/) || [];
const spaces = ' '.repeat(commaPosition - code.length);
return `${code}${spaces},${comment ?? ''}`;
}
function formatBefore(commaLines, indent) {

@@ -93,4 +99,8 @@ return trimTrailingCommas(commaLines).map((line, i) => {

function trimTrailingCommas(lines) {
return lines.map(line => line.replace(/,$/, ''));
return lines.map(line => line.replace(/,(\s*(--.*)?$)/, '$1'));
}
function trimTrailingComments(lines) {
return lines.map(line => line.replace(/\s*--.*/, ''));
}
//# sourceMappingURL=formatCommaPositions.js.map
{
"name": "sql-formatter",
"version": "12.0.4",
"version": "12.0.5",
"description": "Format whitespace in a SQL query to make it more readable",

@@ -5,0 +5,0 @@ "license": "MIT",

<a href='https://github.com/sql-formatter-org/sql-formatter'><img src="static/prettier-sql-clean.svg" width="128"/></a>
# SQL Formatter [![NPM version](https://img.shields.io/npm/v/sql-formatter.svg)](https://npmjs.com/package/sql-formatter) ![Build status](https://img.shields.io/github/workflow/status/sql-formatter-org/sql-formatter/coveralls/master?label=Build&logo=Github) [![Coverage Status](https://coveralls.io/repos/github/sql-formatter-org/sql-formatter/badge.svg?branch=master)](https://coveralls.io/github/sql-formatter-org/sql-formatter?branch=master)
# SQL Formatter [![NPM version](https://img.shields.io/npm/v/sql-formatter.svg)](https://npmjs.com/package/sql-formatter) ![Build status](https://img.shields.io/github/actions/workflow/status/sql-formatter-org/sql-formatter/coveralls.yaml) [![Coverage Status](https://coveralls.io/repos/github/sql-formatter-org/sql-formatter/badge.svg?branch=master)](https://coveralls.io/github/sql-formatter-org/sql-formatter?branch=master)

@@ -5,0 +5,0 @@ **SQL Formatter** is a JavaScript library for pretty-printing SQL queries.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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