How to use the @ts-morph/common.StringUtils.isNullOrWhitespace function in @ts-morph/common

To help you get started, we’ve selected a few @ts-morph/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dsherret / ts-morph / packages / ts-morph / src / structurePrinters / class / ClassDeclarationStructurePrinter.ts View on Github external
private printHeader(writer: CodeBlockWriter, structure: OptionalKind) {
        this.factory.forModifierableNode().printText(writer, structure);
        writer.write(`class`);
        // can be null, ex. `export default class { ... }`
        if (!StringUtils.isNullOrWhitespace(structure.name))
            writer.space().write(structure.name);
        this.factory.forTypeParameterDeclaration().printTextsWithBrackets(writer, structure.typeParameters);
        writer.space();

        writer.hangingIndent(() => {
            if (structure.extends != null) {
                const extendsText = this.getText(writer, structure.extends);
                if (!StringUtils.isNullOrWhitespace(extendsText))
                    writer.write(`extends ${extendsText} `);
            }

            if (structure.implements != null) {
                const implementsText = structure.implements instanceof Array
                    ? structure.implements.map(i => this.getText(writer, i)).join(", ")
                    : this.getText(writer, structure.implements);
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / module / ImportSpecifier.ts View on Github external
renameAlias(alias: string) {
        if (StringUtils.isNullOrWhitespace(alias)) {
            this.removeAliasWithRename();
            return this;
        }

        let aliasIdentifier = this.getAliasNode();
        if (aliasIdentifier == null) {
            // trick is to insert an alias with the same name, then rename the alias. TS compiler will take care of the rest.
            this.setAlias(this.getName());
            aliasIdentifier = this.getAliasNode()!;
        }
        aliasIdentifier.rename(alias);
        return this;
    }
github dsherret / ts-morph / packages / ts-morph / src / structurePrinters / base / ReturnTypedNodeStructurePrinter.ts View on Github external
printText(writer: CodeBlockWriter, structure: ReturnTypedNodeStructure) {
        let { returnType } = structure;
        if (returnType == null && this.alwaysWrite === false)
            return;

        returnType = returnType ?? "void";

        const returnTypeText = this.getText(writer, returnType);
        if (!StringUtils.isNullOrWhitespace(returnTypeText)) {
            writer.hangingIndent(() => {
                writer.write(`: ${returnTypeText}`);
            });
        }
    }
}
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / module / ExportSpecifier.ts View on Github external
setAlias(alias: string) {
        if (StringUtils.isNullOrWhitespace(alias)) {
            this.removeAlias();
            return this;
        }

        const aliasIdentifier = this.getAliasNode();
        if (aliasIdentifier == null) {
            insertIntoParentTextRange({
                insertPos: this.getNameNode().getEnd(),
                parent: this,
                newText: ` as ${alias}`
            });
        }
        else {
            aliasIdentifier.replaceWithText(alias);
        }
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / class / ClassDeclaration.ts View on Github external
function getDefaultExtractedName(name: string | undefined, classDec: ClassDeclaration) {
    name = StringUtils.isNullOrWhitespace(name) ? undefined : name;
    return name || classDec.getName() || classDec.getSourceFile().getBaseNameWithoutExtension().replace(/[^a-zA-Z0-9_$]/g, "");
}
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / module / ImportSpecifier.ts View on Github external
setAlias(alias: string) {
        if (StringUtils.isNullOrWhitespace(alias)) {
            this.removeAlias();
            return this;
        }

        const aliasIdentifier = this.getAliasNode();
        if (aliasIdentifier == null) {
            insertIntoParentTextRange({
                insertPos: this.getNameNode().getEnd(),
                parent: this,
                newText: ` as ${alias}`
            });
        }
        else {
            aliasIdentifier.replaceWithText(alias);
        }
github dsherret / ts-morph / packages / ts-morph / src / structurePrinters / base / TypedNodeStructurePrinter.ts View on Github external
printText(writer: CodeBlockWriter, structure: TypedNodeStructure) {
        let { type } = structure;
        if (type == null && this.alwaysWrite === false)
            return;

        type = type ?? "any";

        const typeText = this.getText(writer, type);
        if (!StringUtils.isNullOrWhitespace(typeText)) {
            writer.hangingIndent(() => {
                writer.write(`${this.separator} ${typeText}`);
            });
        }
    }
}
github dsherret / ts-morph / packages / ts-morph / src / compiler / ast / jsx / JsxAttribute.ts View on Github external
setInitializer(textOrWriterFunction: string | WriterFunction) {
        const text = getTextFromStringOrWriter(this._getWriterWithQueuedIndentation(), textOrWriterFunction);

        if (StringUtils.isNullOrWhitespace(text)) {
            this.removeInitializer();
            return this;
        }

        const initializer = this.getInitializer();
        if (initializer != null) {
            initializer.replaceWithText(text);
            return this;
        }

        insertIntoParentTextRange({
            insertPos: this.getNameNode().getEnd(),
            parent: this,
            newText: `=${text}`
        });