text-is-upper-case
Version:
Returns `true` if text is upper case only.
277 lines (196 loc) โข 7.13 kB
Markdown
[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]
[![Bundle size][bundlephobia-image]][bundlephobia-url]
[](https://opensource.org/licenses/MIT)
[](http://www.typescriptlang.org/)
> Check if a string is in **UPPERCASE** format.
- **Lightweight** - Only ~200B minified + gzipped
- **Type-safe** - Full TypeScript support with comprehensive type definitions
- **Zero dependencies** - No external dependencies
- **Tree-shakeable** - ES modules support
- **Universal** - Works in browsers, Node.js, and serverless environments
- **Well-tested** - Comprehensive test suite with edge cases
```bash
npm install text-is-upper-case
yarn add text-is-upper-case
pnpm add text-is-upper-case
bun add text-is-upper-case
```
```javascript
import { isUpperCase } from "text-is-upper-case";
console.log(isUpperCase("HELLO WORLD")); // true
console.log(isUpperCase("Hello World")); // false
console.log(isUpperCase("hello world")); // false
```
```javascript
import { isUpperCase } from "text-is-upper-case";
console.log(isUpperCase("HELLO")); // true
```
```javascript
const { isUpperCase } = require("text-is-upper-case");
console.log(isUpperCase("HELLO")); // true
```
```typescript
import { isUpperCase } from "text-is-upper-case";
const result: boolean = isUpperCase("HELLO WORLD");
console.log(result); // true
```
```javascript
import { isUpperCase } from "text-is-upper-case";
// Valid uppercase
isUpperCase("HELLO"); // true
isUpperCase("HELLO WORLD"); // true
isUpperCase("TEST123"); // true
isUpperCase("USER_NAME"); // true
isUpperCase("API-KEY"); // true
// Invalid (not uppercase)
isUpperCase("Hello"); // false
isUpperCase("hello"); // false
isUpperCase("Hello World"); // false
isUpperCase("camelCase"); // false
isUpperCase("PascalCase"); // false
```
```javascript
import { isUpperCase } from "text-is-upper-case";
// Numbers and symbols
isUpperCase("123"); // true
isUpperCase("HELLO123"); // true
isUpperCase("TEST@EMAIL.COM"); // true
isUpperCase("USER_123"); // true
// Empty and whitespace
isUpperCase(""); // true
isUpperCase(" "); // true
isUpperCase("\n\t"); // true
// Special characters
isUpperCase("HELLO-WORLD"); // true
isUpperCase("TEST_CASE"); // true
isUpperCase("FILE.TXT"); // true
```
```javascript
import { isUpperCase } from "text-is-upper-case";
function validateEnvVarName(name) {
if (!isUpperCase(name)) {
return "Environment variable names should be uppercase";
}
return null;
}
console.log(validateEnvVarName("DATABASE_URL")); // null (valid)
console.log(validateEnvVarName("databaseUrl")); // "Environment variable names should be uppercase"
```
```javascript
import { isUpperCase } from "text-is-upper-case";
function validateConstantName(name) {
if (!isUpperCase(name)) {
return "Constants should be uppercase";
}
return null;
}
console.log(validateConstantName("MAX_RETRIES")); // null
console.log(validateConstantName("maxRetries")); // "Constants should be uppercase"
```
```javascript
import { isUpperCase } from "text-is-upper-case";
function validateHeaderMethod(method) {
if (!isUpperCase(method)) {
return "HTTP methods should be uppercase";
}
return null;
}
console.log(validateHeaderMethod("GET")); // null
console.log(validateHeaderMethod("get")); // "HTTP methods should be uppercase"
```
```javascript
import { isUpperCase } from "text-is-upper-case";
function validateConfigConstants(config) {
const invalidKeys = Object.keys(config).filter(
(key) => key.startsWith("CONST_") && !isUpperCase(key),
);
if (invalidKeys.length > 0) {
return `Invalid constant keys (must be uppercase): ${invalidKeys.join(", ")}`;
}
return null;
}
const config1 = { CONST_MAX_SIZE: 100, normalKey: "value" };
const config2 = { CONST_max_size: 100, normalKey: "value" };
console.log(validateConfigConstants(config1)); // null
console.log(validateConfigConstants(config2)); // "Invalid constant keys..."
```
Checks if a string is in uppercase format.
- **`input`** (`string`): The string to check
- **`boolean`**: `true` if the string is uppercase, `false` otherwise
This package is optimized for minimal bundle size:
- **Minified**: ~200B
- **Gzipped**: ~150B
- **Tree-shakeable**: Yes
- **Side effects**: None
- **Modern browsers**: ES2015+ (Chrome 51+, Firefox 54+, Safari 10+)
- **Node.js**: 12+
- **TypeScript**: 4.0+
- **Bundle formats**: UMD, ESM, CommonJS
```bash
pnpm test
pnpm test --watch
pnpm test --coverage
pnpm typecheck
pnpm lint
```
- [`text-camel-case`](https://www.npmjs.com/package/text-camel-case) - Convert to camelCase
- [`text-capital-case`](https://www.npmjs.com/package/text-capital-case) - Convert to Capital Case
- [`text-constant-case`](https://www.npmjs.com/package/text-constant-case) - Convert to CONSTANT_CASE
- [`text-dot-case`](https://www.npmjs.com/package/text-dot-case) - Convert to dot.case
- [`text-header-case`](https://www.npmjs.com/package/text-header-case) - Convert to Header-Case
- [`text-case`](https://www.npmjs.com/package/text-case) - All case transformations in one package
[](LICENSE) ยฉ [Dmitry Selikhov](https://github.com/idimetrix)
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## ๐ Support
- ๐ง **Email**: [selikhov.dmitrey@gmail.com](mailto:selikhov.dmitrey@gmail.com)
- ๐ **Issues**: [GitHub Issues](https://github.com/idimetrix/text-case/issues)
- ๐ฌ **Discussions**: [GitHub Discussions](https://github.com/idimetrix/text-case/discussions)
- ๐ **Documentation**: [Full Documentation](https://github.com/idimetrix/text-case#readme)
---
**Made with โค๏ธ by [Dmitry Selikhov](https://github.com/idimetrix)**
[npm-image]: https://img.shields.io/npm/v/text-is-upper-case.svg?style=flat
[npm-url]: https://npmjs.org/package/text-is-upper-case
[downloads-image]: https://img.shields.io/npm/dm/text-is-upper-case.svg?style=flat
[downloads-url]: https://npmjs.org/package/text-is-upper-case
[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/text-is-upper-case.svg
[bundlephobia-url]: https://bundlephobia.com/result?p=text-is-upper-case