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

sh-syntax

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sh-syntax - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

12

lib/index.d.ts
import './shim.js';
import '../vendors/wasm_exec.js';
import type { File, ShOptions } from './types.js';
import type { File, ShOptions, ShPrintOptions } from './types.js';
export declare const processor: {
(text: string, options?: ShOptions | undefined): Promise<File>;
(ast: File, options?: ShOptions | undefined): Promise<string>;
(text: string, options?: (ShOptions & {
print: true;
}) | undefined): Promise<string>;
(ast: File, options?: (ShOptions & {
originalText: string;
}) | undefined): Promise<string>;
};
export declare const parse: (text: string, options?: ShOptions | undefined) => Promise<File>;
export declare const print: (ast: File, options?: ShOptions | undefined) => Promise<string>;
export declare function print(text: string, options?: ShOptions): Promise<string>;
export declare function print(ast: File, options?: ShPrintOptions): Promise<string>;
export * from './processor.js';
export * from './types.js';

@@ -13,5 +13,10 @@ import fs from 'fs';

export const parse = (text, options) => processor(text, options);
export const print = (ast, options) => processor(ast, options);
export function print(textOrAst, options) {
if (typeof textOrAst === 'string') {
return processor(textOrAst, Object.assign(Object.assign({}, options), { print: true }));
}
return processor(textOrAst, options);
}
export * from './processor.js';
export * from './types.js';
//# sourceMappingURL=index.js.map

@@ -16,3 +16,8 @@ /// <reference types="web" />

(text: string, options?: ShOptions | undefined): Promise<File>;
(ast: File, options?: ShOptions | undefined): Promise<string>;
(text: string, options?: (ShOptions & {
print: true;
}) | undefined): Promise<string>;
(ast: File, options?: (ShOptions & {
originalText: string;
}) | undefined): Promise<string>;
};

@@ -17,3 +17,3 @@ import { __awaiter } from "tslib";

const decoder = new TextDecoder();
function processor(textOrAst, { filepath, originalText, keepComments = true, stopAt = '', variant = LangVariant.LangBash, useTabs = false, tabWidth = 2, indent = useTabs ? 0 : tabWidth, binaryNextLine = true, switchCaseIndent = true, spaceRedirects = true, keepPadding = false, minify = false, functionNextLine = false, } = {}) {
function processor(textOrAst, { filepath, print = false, originalText, keepComments = true, stopAt = '', variant = LangVariant.LangBash, useTabs = false, tabWidth = 2, indent = useTabs ? 0 : tabWidth, binaryNextLine = true, switchCaseIndent = true, spaceRedirects = true, keepPadding = false, minify = false, functionNextLine = false, } = {}) {
return __awaiter(this, void 0, void 0, function* () {

@@ -26,7 +26,6 @@ if (!wasmFile) {

}
let isAst = false;
if (typeof textOrAst !== 'string') {
isAst = true;
if (typeof textOrAst !== 'string' && !print) {
print = true;
if (originalText == null) {
console.warn('`originalText` is required for now, hope we will find better solution later');
throw new TypeError('`originalText` is required for now, hope we will find better solution later');
}

@@ -43,3 +42,3 @@ }

const filePath = encoder.encode(filepath);
const text = encoder.encode(isAst ? originalText : textOrAst);
const text = encoder.encode(originalText || textOrAst);
const uStopAt = encoder.encode(stopAt);

@@ -52,3 +51,3 @@ const filePathPointer = wasmAlloc(filePath.byteLength);

new Uint8Array(memory.buffer).set(uStopAt, stopAtPointer);
const resultPointer = process(filePathPointer, filePath.byteLength, filePath.byteLength, textPointer, text.byteLength, text.byteLength, isAst, keepComments, stopAtPointer, uStopAt.byteLength, uStopAt.byteLength, variant, indent, binaryNextLine, switchCaseIndent, spaceRedirects, keepPadding, minify, functionNextLine);
const resultPointer = process(filePathPointer, filePath.byteLength, filePath.byteLength, textPointer, text.byteLength, text.byteLength, print, keepComments, stopAtPointer, uStopAt.byteLength, uStopAt.byteLength, variant, indent, binaryNextLine, switchCaseIndent, spaceRedirects, keepPadding, minify, functionNextLine);
wasmFree(filePathPointer);

@@ -67,3 +66,3 @@ wasmFree(textPointer);

}
return isAst ? processedText : file;
return print ? processedText : file;
});

@@ -70,0 +69,0 @@ }

@@ -25,6 +25,8 @@ export declare enum LangVariant {

filepath?: string;
originalText?: string;
useTabs?: boolean;
tabWidth?: number;
}
export interface ShPrintOptions extends ShOptions {
originalText: string;
}
export interface Pos {

@@ -31,0 +33,0 @@ Col: number;

{
"name": "sh-syntax",
"version": "0.2.1",
"version": "0.3.0",
"type": "module",

@@ -36,9 +36,12 @@ "description": "A WASM shell parser and formatter with bash support, based on mvdan/sh",

"devDependencies": {
"@1stg/lib-config": "^6.0.0",
"@1stg/lib-config": "^6.1.1",
"@changesets/changelog-github": "^0.4.4",
"@changesets/cli": "^2.22.0",
"@types/golang-wasm-exec": "^1.15.0",
"@types/jest": "^27.5.0",
"@types/node": "^17.0.31",
"@types/jest": "^27.5.1",
"@types/mvdan-sh": "^0.5.1",
"@types/node": "^17.0.33",
"@types/web": "^0.0.64",
"mvdan-sh": "^0.10.1",
"tinybench": "^1.0.0",
"ts-jest": "^28.0.2",

@@ -82,2 +85,3 @@ "type-coverage": "^2.21.1",

"scripts": {
"benchmark": "node benchmark > benchmark/benchmark.txt",
"build": "run-p build:*",

@@ -84,0 +88,0 @@ "build:r": "r -f cjs",

@@ -514,23 +514,2 @@ // Copyright 2018 The Go Authors. All rights reserved.

}
if (
global.require &&
global.require.main === module &&
global.process &&
global.process.versions &&
!global.process.versions.electron
) {
if (process.argv.length != 3) {
console.error("usage: go_js_wasm_exec [wasm binary] [arguments]");
process.exit(1);
}
const go = new Go();
WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => {
return go.run(result.instance);
}).catch((err) => {
console.error(err);
process.exit(1);
});
}
})();

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 not supported yet

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