npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tech-spec

v1.0.58

Published

[![npm version](https://badge.fury.io/js/tech-spec.svg)](https://badge.fury.io/js/tech-spec) ![CI](https://github.com/Voldemat/tech-spec/actions/workflows/packages.js.yaml/badge.svg) [![codecov](https://codecov.io/gh/Voldemat/tech-spec/branch/main/graph/b

Downloads

44

Readme

Tech-Spec

npm version CI codecov Maintainability Test Coverage https://nodei.co/npm/tech-spec.png?downloads=true&downloadRank=true&stars=true

Installation

npm install -g tech-spec

Usage example

techs-spec/some-feature.tech-spec.yaml

type: feature
metadata:
  name: somrt
spec:
  someting:
    type: date
    value: '2023-02-01'
  another:
    type: link
    value: https://google.com
  asd:
    type: string
    value: 'test string'

tech-spec/login.field.tech-spec.yaml

type: field
metadata:
  name: login
spec:
    type: string
    regex: '^[\w_]{4,100}$'

tech-spec/password.field.tech-spec.yaml

type: field
metadata:
  name: password
spec:
  type: string
  regex: '^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]){5;150}$'

tech-spec/registration.form.tech-spec.yaml

type: form
metadata:
  name: Registration
spec:
  login:
    required: true
    fieldRef: login
    helperMessage: null
    errorMessage: null

  password:
    required: true
    fieldRef: password
    errorMessage: 'Invalid'
    helperMessage: null

Command:

techspec generate tech-spec output
❇️  Code is successfully generated

output/form.ts

export const RegistrationForm = {
  login: {
    required: true,
    fieldRef: "login",
    helperMessage: null,
    errorMessage: null,
    field: {
      type: "string",
      regex: new RegExp("^[\\w_]4,100}$")
    }
  },
  password: {
    required: true,
    fieldRef: "password",
    errorMessage: "Invalid",
    helperMessage: null,
    field: {
      type: "string",
      regex: new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]){5;150}$")
    }
  }
};

output/features.ts

export const somrtFeature = {
  someting: {
    type: "date",
    value: new Date("2023-02-01")
  },
  another: {
    type: "link",
    value: new URL("https://google.com")
  },
  asd: {
    type: "string",
    value: "adsa"
  }
};

In your client code:

import { buildValidators, FormValidators, ValidatorError } from 'tech-spec'
import { RegistrationForm } from '<output-dir>/form'

const validators: FormValidators<typeof RegistrationForm> = buildValidators(RegistrationForm)
const result: ValidatorError = validators.login('asd') // login has less characters than required in spec
if (!result.isValid) {
    throw new Error(result.errorMessage)
}

Yaml Parsing Errors Examples

tech-spec/light.theme.tech-spec.yaml

type: theme
metadata:
  name: light
  asd
spec:
  colors:
    check: rgba(255, 255, 255, 255)
techspec validate tech-spec
🚨 YamlParsingError: tech-spec/registration.form.tech-spec.yaml

Reason: bad indentation of a mapping entry

4 | spec:
5 |   login:
6 |     asdasd
7 |     required: true
-----------------^
8 |     fieldRef: login
9 |     helperMessage: null

Types of spec

  • form
  • field
  • DesignSystem
  • feature

Form

type: form

Metadata fields:

  • name: string

Each key in spec mapping represents name of field.

Field mapping keys:

  • required: boolean
  • errorMessage: string | null
  • helperMessage: string | null
  • fieldRef: string (must be the same as field.metadata.name)

Example:

type: form
metadata:
  name: Registration
spec:
  login:
    required: true
    fieldRef: login
    helperMessage: null
    errorMessage: null

  password:
    required: true
    fieldRef: password
    errorMessage: 'Invalid'
    helperMessage: null

Field

type: field

Metadata fields:

  • name: string

Each key in spec mapping represents name of field.

Spec fields:

  • type: 'string'
  • regex: string (valid regex string)

Example:

type: field
metadata:
  name: login
spec:
  type: string
  regex: '^[\w_]4,100}$'

Feature

type: feature

Metadata fields:

  • name: string

Each key in spec mapping represents name of field.

Different types have different configuration options.

Field types and their spec fields

  • type: string

    value: string (any string)

  • type: uint

    value: number (unsigned integer number)

  • type: int

    value: number (signed integer number)

  • type: float

    value: number (number with floating point)

  • type: link

    value: string (http link)

  • type: email

    value: string

  • type: regex

    value: string (valid regex string)

  • type: date

    value: string (date string according to RFC3339)

  • type: time

    value: string (time string according to RFC3339)

  • type: datetime

    value: string (date-time string according to RFC3339)

  • type: duration

    value: string (duration string according to RFC3339)

  • type: uuid

    value: string (valid uuid string according to RFC4122)

Example:

type: feature
metadata:
  name: somrt
spec:
  someting:
    type: date
    value: '2023-02-01'
  another:
    type: link
    value: https://google.com
  asd:
    type: string
    value: 'test string'