Skip to content

A TypeScript type guard that validates if the given value is a string

License

Notifications You must be signed in to change notification settings

fvilers/is-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@fvilers/is-string

A TypeScript type guard that validates if the given value is a string

Installation

npm install @fvilers/is-string

or

yarn add @fvilers/is-string

ECMAScript module

Starting with version 2.0.0, this library will be published as an ECMAScript module.

Usage

import { isString } from "@fvilers/is-string";

const variable: any = "This is a string";

if (isString(variable)) {
  // From here, variable is strongly typed as a string
  console.log("Variable is a string with length of", variable.length);
} else {
  console.log("Variable is not a string");
}

It will output:

Variable is a string with length of 16

About

A TypeScript type guard that validates if the given value is a string

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project