GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - NeaByteLab/TypeScript-Starter: An uncompromisingly strict TypeScript starter template enforcing maximum code quality, type safety, and development best practices.

BranchesTags
Open more actions menu

Latest commit

 

History

9 Commits
9 Commits

Folders and files

NameName
Last commit message
Last commit date
docs
docs
 
 
examples
examples
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.prettierignore
.prettierignore
 
 
.prettierrc
.prettierrc
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
eslint.config.js
eslint.config.js
 
 
jest.config.js
jest.config.js
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

๐Ÿ”ง TypeScript Starter

Node.js TypeScript License

TypeScript Starter - A starter template with TypeScript rules, tooling, and configuration for Node.js projects.


๐ŸŽฏ Strict Coding Rules (Enforced)

TypeScript Rules

// โœ… ENFORCED: Strict mode with comprehensive type checking
// โœ… ENFORCED: No implicit any types
// โœ… ENFORCED: No unused variables or parameters
// โœ… ENFORCED: All code paths must return
// โœ… ENFORCED: Explicit type annotations required
// โœ… ENFORCED: No unreachable code
// โœ… ENFORCED: Exact optional property types
// โœ… ENFORCED: No unchecked indexed access

// โŒ This will fail:
function badFunction(input) {  // implicit any
  if (condition) return value  // not all paths return
  const unused = "never used"  // unused variable
}

// โœ… This passes:
function goodFunction: (input: string) => string = (input: string): string => {
  if (condition) {
    return value
  }
  return defaultValue
}

Code Style Rules

// โœ… ENFORCED: Single quotes, no semicolons
// โœ… ENFORCED: 2-space indentation
// โœ… ENFORCED: No trailing commas
// โœ… ENFORCED: Required curly braces
// โœ… ENFORCED: Spaces inside object braces
// โœ… ENFORCED: No spaces inside array brackets
// โœ… ENFORCED: Consistent naming conventions

// โŒ This will fail:
const obj = {a: 1, b: 2,};   // trailing comma
const arr = [ 1, 2, 3 ];     // spaces in array
if(condition) return value;  // no curly braces, semicolon

// โœ… This passes:
const obj = { a: 1, b: 2 }
const arr = [1, 2, 3]
if (condition) {
  return value
}

Best Practices Rules

// โœ… ENFORCED: Prefer const over let/var
// โœ… ENFORCED: Arrow functions for callbacks
// โœ… ENFORCED: Template literals over concatenation
// โœ… ENFORCED: Object destructuring where applicable
// โœ… ENFORCED: No inline comments
// โœ… ENFORCED: Cognitive complexity โ‰ค 15
// โœ… ENFORCED: No duplicate code
// โœ… ENFORCED: Prefer immediate returns

// โŒ This will fail:
var oldWay = "string" + variable;  // var, concatenation
function callback() { return value; }  // function instead of arrow
// inline comment  // inline comment

// โœ… This passes:
const newWay = `string ${variable}`
const callback = () => value
// Block comment for complex logic

Quality Rules

// โœ… ENFORCED: No duplicate strings
// โœ… ENFORCED: No identical functions
// โœ… ENFORCED: No redundant boolean expressions
// โœ… ENFORCED: Prefer immediate returns
// โœ… ENFORCED: No one-iteration loops
// โœ… ENFORCED: No unused variables
// โœ… ENFORCED: No unreachable code

// โŒ This will fail:
const message = "Hello"
const greeting = "Hello"   // duplicate string

if (condition === true) {  // redundant boolean
  return value
}

// โœ… This passes:
const MESSAGES = {
  GREETING: "Hello"
} as const

if (condition) {
  return value
}

๐Ÿš€ Quick Start

Installation

# Clone and start coding
git clone https://github.com/NeaByteLab/TypeScript-Starter.git my-project
cd my-project
npm install
npm run dev

Development Commands

# Development
npm run dev                # TypeScript watch mode
npm run build              # Build for production
npm run clean              # Clean build directory

# Code Quality
npm run lint               # ESLint with strict rules
npm run lint:fix           # Auto-fix ESLint violations
npm run format             # Prettier formatting
npm run type-check         # TypeScript type checking

# Testing
npm run test               # Run tests with Jest
npm run test:watch         # Watch mode for TDD
npm run test:coverage      # Run tests with coverage

# Documentation
npm run docs               # Generate TypeDoc documentation

# Quality Assurance
npm run check-all          # Run all checks

๐Ÿ“ Project Structure

TypeScript-Starter/
โ”œโ”€โ”€ src/                      # Source code
โ”‚   โ”œโ”€โ”€ types/                # Type definitions
โ”‚   โ”‚   โ””โ”€โ”€ index.ts          # Common types: ConfigOptions, Result<T>, EventHandler, etc.
โ”‚   โ”œโ”€โ”€ utils/                # Utility functions
โ”‚   โ”‚   โ””โ”€โ”€ index.ts          # Helper functions: isNotEmpty, createSuccessResult, etc.
โ”‚   โ””โ”€โ”€ index.ts              # Main entry point - exports all public APIs
โ”œโ”€โ”€ tests/                    # Test files
โ”‚   โ”œโ”€โ”€ setup.ts              # Jest test setup and global configurations
โ”‚   โ””โ”€โ”€ example.test.ts       # Test suite for all functions
โ”œโ”€โ”€ examples/                 # Example usage
โ”‚   โ””โ”€โ”€ basic-usage.ts        # Usage examples with async support
โ”œโ”€โ”€ dist/                     # Build output (ESM + type definitions)
โ”œโ”€โ”€ docs/                     # Auto-generated TypeDoc documentation
โ”œโ”€โ”€ coverage/                 # Test coverage reports (HTML + LCOV)
โ””โ”€โ”€ Configuration Files       # Strict rules enforced
    โ”œโ”€โ”€ tsconfig.json         # TypeScript configuration (all strict options enabled)
    โ”œโ”€โ”€ eslint.config.js      # ESLint configuration (200+ rules)
    โ”œโ”€โ”€ jest.config.js        # Jest testing configuration with TypeScript
    โ””โ”€โ”€ package.json          # Dependencies and scripts

๐Ÿ“ฆ Core API Reference

Type Definitions

// Configuration options interface
export interface ConfigOptions {
  readonly debug: boolean
  readonly timeout: number
  readonly retries: number
}

// Result type for operations (success/error handling)
export type Result<T> = {
  readonly success: boolean
  readonly data?: T
  readonly error?: string
}

// Event handler type
export type EventHandler<T = unknown> = (event: T) => void

// Async operation type
export type AsyncOperation<T> = () => Promise<T>

// Validation function type
export type Validator<T> = (value: T) => boolean

Utility Functions

// String validation
export const isNotEmpty: (value: string) => boolean

// Result constructors
export const createSuccessResult: <T>(data: T) => Result<T>
export const createErrorResult: <T>(error: string) => Result<T>

// Async utilities
export const delay: (ms: number) => Promise<void>

Main Exports

// Example function (demonstrates strict typing)
export const exampleFunction: (input: string) => string

// Example class (demonstrates OOP with strict rules)
export class ExampleClass {
  constructor(value: string)
  public getValue(): string
  public setValue(newValue: string): void
}

Usage Examples

import {
  exampleFunction,
  ExampleClass,
  isNotEmpty,
  createSuccessResult,
  createErrorResult,
  delay,
  type ConfigOptions,
  type Result
} from 'typescript-starter'

// Function usage
const result = exampleFunction('hello world')
console.log(result) // "HELLO WORLD"

// Class usage
const instance = new ExampleClass('test value')
console.log(instance.getValue()) // "TEST VALUE"

// Utility usage
console.log(isNotEmpty('valid')) // true
console.log(isNotEmpty('')) // false

const success = createSuccessResult({ message: 'OK' })
const error = createErrorResult<string>('Failed')

// Async usage
await delay(1000)
console.log('Delayed execution')

๐Ÿ“Š Code Quality Metrics

Cognitive Complexity Limit: 15

// โŒ Too complex (will fail)
function complexFunction(input: string): string {
  if (condition1) {
    if (condition2) {
      if (condition3) {
        if (condition4) {
          if (condition5) {
            return "too complex"
          }
        }
      }
    }
  }
  return "default"
}

// โœ… Simple and clear (passes)
function simpleFunction(input: string): string {
  if (!condition1) return "default"
  if (!condition2) return "default"
  if (!condition3) return "default"
  return "result"
}

Type Safety

// โŒ These will fail compilation
function badFunction(input) {           // implicit any
  if (condition) return value           // not all paths return
  const unused = "never used"           // unused variable
}

// โœ… These pass strict checking
function goodFunction(input: string): string {
  if (condition) {
    return value
  }
  return defaultValue
}

๐Ÿงช Testing (Required)

Test Structure

// tests/example.test.ts
import { exampleFunction, ExampleClass } from '@/index'

describe('exampleFunction', () => {
  it('should convert string to uppercase', () => {
    const result = exampleFunction('test')
    expect(result).toBe('TEST')
  })
})

describe('ExampleClass', () => {
  let instance: ExampleClass

  beforeEach(() => {
    instance = new ExampleClass('initial')
  })

  it('should set and get values correctly', () => {
    instance.setValue('new value')
    expect(instance.getValue()).toBe('NEW VALUE')
  })
})

Coverage Requirements

  • Lines: 80% minimum
  • Functions: 100% for public APIs
  • Branches: 80% minimum
  • Statements: 80% minimum

Running Tests

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

๐Ÿ“š Documentation (Enforced)

JSDoc Required for Public APIs

/**
 * Example function demonstrating strict rules
 * @param input - Input string to process
 * @returns Processed string in uppercase
 */
export const exampleFunction: (input: string) => string = (input: string): string => {
  return input.toUpperCase()
}

/**
 * Example class with strict typing
 */
export class ExampleClass {
  private value: string

  constructor(initialValue: string) {
    this.value = initialValue.toUpperCase()
  }

  /**
   * Get the current value
   * @returns The current value in uppercase
   */
  public getValue(): string {
    return this.value
  }

  /**
   * Set a new value
   * @param newValue - The new value to set
   */
  public setValue(newValue: string): void {
    this.value = newValue.toUpperCase()
  }
}

๐Ÿ” Path Aliases (Clean Imports)

// โŒ Relative imports (messy)
import { utils } from '../../../utils/helper'

// โœ… Path aliases (clean)
import { utils } from '@/utils/helper'
import { types } from '@types/common'
import { helpers } from '@utils/helpers'

Available Path Aliases

  • @/* โ†’ src/* (main source directory)
  • @types/* โ†’ src/types/* (type definitions)
  • @utils/* โ†’ src/utils/* (utility functions)

๐Ÿ› ๏ธ Development Workflow

1. Start Coding

npm run dev         # Rules are checked

2. Write Tests

npm run test:watch  # TDD approach

3. Quality Check

npm run check-all  # All rules checked

4. Build & Deploy

npm run build      # Production build with minification
npm run docs       # Generate TypeDoc documentation
npm run clean      # Clean build directory

๐Ÿ“„ License

MIT License - see LICENSE file for details.

About

An uncompromisingly strict TypeScript starter template enforcing maximum code quality, type safety, and development best practices.

Topics

developmenteslintformattingjestlintingprettierqualitystandardsstarterstricttemplatetypedoctypescript

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Contributors

Languages

You are visitor 01402503 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.