Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
skwee357 committed Mar 10, 2023
0 parents commit 3ed92a2
Show file tree
Hide file tree
Showing 163 changed files with 7,104 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
lib
.eslintrc.js
29 changes: 29 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
"root": true,
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier"
],
"plugins": [
"@typescript-eslint"
],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"tsconfigRootDir": __dirname,
"project": [
"./tsconfig.json"
]
},
"rules": {
"@typescript-eslint/explicit-function-return-type": "error"
}
}
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
lib/

node_modules/

npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

.DS_Store
5 changes: 5 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
semi: true,
tabWidth: 4,
singleQuote: true,
};
675 changes: 675 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SwitchDB
A database, and DSL, of mechanical keyboard switches. Served as a website at [https://anyswitch.xyz](https://anyswitch.xyz)

## Contributing
Know of a switch that we've missed? Found an error in one of the switches? Don't worry! You can easily contribute to this project.

In order to contribute, you will have to fork this project and submit a PR.

## Acknowledgments & License
This project is meant entertainment purposes only. It is **not** meant to provide official specification of mechanical key switches. Always refer to the official data sheets / manufacturer website for official specifications.

All brand and manufacturer logos, mentions, product names and images are property of their respective owners, unless otherwise stated.

Refer to [LICENSE](./LICENSE) file for license for this project.
45 changes: 45 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "switchdb",
"version": "0.0.1",
"description": "An, collaborative database of mechanical key switches",
"keywords": [
"keyboard switch",
"mechanical key switch",
"mechanical switch database",
"cherry",
"kailh",
"gateron"
],
"files": [
"lib"
],
"homepage": "https://anyswitch.xyz",
"bugs": {
"url": "https://github.com/skwee356/switchdb/issues"
},
"license": "GPL-3.0",
"author": {
"name": "Dmitry (skwee357) Kudryavtsev",
"url": "https://kudmitry.com"
},
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"build": "tsc",
"lint": "eslint src",
"prettier": "prettier src --check"
},
"repository": {
"type": "git",
"url": "https://github.com/skwee357/switchdb"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.7.0",
"prettier": "^2.8.4",
"ts-node": "^10.9.1",
"typescript": "*"
}
}
16 changes: 16 additions & 0 deletions src/collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { type Brand, type Manufacturer, type Switch } from './switch';

export interface MechanicalKeySwitch {
readonly id: string;
readonly brand: Brand;
readonly manufacturer: Manufacturer;
readonly spec: Switch;
}

export interface CollectionInterface {
add: (manufacturer: Manufacturer) => void;

items: () => MechanicalKeySwitch[];

getById: (id: string) => MechanicalKeySwitch | null;
}
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { CollectionInterface } from './collection';
import { Brand, Manufacturer, Switch } from './switch';
import collection from './switches';

export { collection, CollectionInterface, Switch, Brand, Manufacturer };
205 changes: 205 additions & 0 deletions src/switch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
import type { Color, Force, Travel } from './types';

interface ForceSpec {
readonly actuation: Force | undefined;
readonly bottom: Force | undefined;
}

interface TactileForceSpec extends ForceSpec {
readonly tactile: Force | undefined;
}

interface TravelSpec {
readonly pre: Travel | undefined;
readonly total: Travel | undefined;
}

interface TactileTravelSpec extends TravelSpec {
readonly pressure: Travel | undefined;
}

export type MaterialType =
| 'pom'
| 'pc'
| 'nylon'
| 'nylon_pa66'
| 'reinforced_nylon'
| 'clear_plastic'
| 'pa12'
| 'proprietary_ink';

export class Material {
private constructor(
public readonly type?: MaterialType,
public readonly color?: Color
) {}

public static Unspecified(color?: Color): Material {
return new Material(undefined, color);
}

public static POM(color?: Color): Material {
return new Material('pom', color);
}

public static PC(color?: Color): Material {
return new Material('pc', color);
}

public static Nylon(color?: Color): Material {
return new Material('nylon', color);
}

public static ReinforcedNylon(color?: Color): Material {
return new Material('reinforced_nylon', color);
}

public static NylonPA66(color?: Color): Material {
return new Material('nylon_pa66', color);
}

public static ClearPlastic(color?: Color): Material {
return new Material('clear_plastic', color);
}

public static PA12(color?: Color): Material {
return new Material('pa12', color);
}

public static ProprietaryInk(color?: Color): Material {
return new Material('proprietary_ink', color);
}
}

interface StemBase {
readonly type: string;
}

export class StemMX implements StemBase {
public readonly type = 'mx';

private constructor(
public readonly design: 'regular' | 'box' | 'partial_box' | 'circular',
public readonly material: Material
) {}

public static Regular(material: Material): StemMX {
return new StemMX('regular', material);
}

public static Box(material: Material): StemMX {
return new StemMX('box', material);
}

public static PartialBox(material: Material): StemMX {
return new StemMX('partial_box', material);
}

public static Circular(material: Material): StemMX {
return new StemMX('circular', material);
}
}

interface SpringBase {
readonly material: string;
}

type StainlessSteelSpringForm =
| 'regular'
| 'short'
| 'long'
| 'thick'
| 'double_stage';
type StainlessSteelSpringCoating = 'gold' | 'black';

export class SpringStainlessSteel implements SpringBase {
public readonly material = 'stainless_steel';

private constructor(
public readonly form: StainlessSteelSpringForm,
public readonly coating?: StainlessSteelSpringCoating
) {}

public static Regular(
coating?: StainlessSteelSpringCoating
): SpringStainlessSteel {
return new SpringStainlessSteel('regular', coating);
}

public static Short(
coating?: StainlessSteelSpringCoating
): SpringStainlessSteel {
return new SpringStainlessSteel('short', coating);
}

public static Long(
coating?: StainlessSteelSpringCoating
): SpringStainlessSteel {
return new SpringStainlessSteel('long', coating);
}

public static Thick(
coating?: StainlessSteelSpringCoating
): SpringStainlessSteel {
return new SpringStainlessSteel('thick', coating);
}

public static DoubleStage(
coating?: StainlessSteelSpringCoating
): SpringStainlessSteel {
return new SpringStainlessSteel('double_stage', coating);
}
}

export type Stem = StemMX;
export type Profile = 'regular' | 'low';
export type SwitchType = 'linear' | 'tactile' | 'clicky';
export type Spring = SpringStainlessSteel;
export type VolumeLevel = 'silent' | 'low' | 'medium' | 'loud' | undefined;
export type Mount = '3pin' | '5pin' | 'both' | undefined;
export type Lubrication = 'factory' | 'self' | 'slight' | 'none';
export type Lighting = 'in_switch' | 'smd' | 'both' | 'none' | undefined;
export type ForceProperty = ForceSpec | TactileForceSpec;
export type TravelProperty = TravelSpec | TactileTravelSpec;

interface BaseSwitch<F extends ForceProperty, T extends TravelProperty> {
readonly type: SwitchType;
readonly model: string;
readonly variation?: string;
readonly stem: Stem;
readonly profile: Profile;
readonly spring: Spring | undefined;
readonly volume: VolumeLevel;
readonly mount: Mount;
readonly lubrication: Lubrication;
readonly lifetime: number | undefined;
readonly datasheet: string | undefined;
readonly lighting: Lighting;
readonly housing: {
readonly upper: Material;
readonly lower: Material;
};
readonly force: F;
readonly travel: T;
}

export interface LinearSwitch extends BaseSwitch<ForceSpec, TravelSpec> {
readonly type: 'linear';
}

export interface TactileSwitch
extends BaseSwitch<TactileForceSpec, TactileTravelSpec> {
readonly type: 'tactile' | 'clicky';
}

export type Switch = LinearSwitch | TactileSwitch;

export interface Brand {
readonly name: string;
readonly switches: Array<Switch>;
}

export interface Manufacturer {
readonly name: string;
readonly brands: Array<Brand>;
}
8 changes: 8 additions & 0 deletions src/switches/candy/candy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Brand } from '../../../switch';
import jadeGreen55g from './jade-green-55g';
import jadeGreen62g from './jade-green-62g';

export default {
name: 'Candy',
switches: [jadeGreen55g, jadeGreen62g],
} satisfies Brand;
34 changes: 34 additions & 0 deletions src/switches/candy/candy/jade-green-55g.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
Material,
StemMX,
SpringStainlessSteel,
type Switch,
} from '../../../switch';
import { Color, Force, Tolerance, Travel } from '../../../types';

export default {
model: 'Jade Green',
variation: '55g',
profile: 'regular',
stem: StemMX.Regular(Material.POM(Color.Opaque('#95E790'))),
mount: '5pin',
type: 'linear',
lifetime: 50,
lighting: 'both',
lubrication: 'none',
datasheet: undefined,
volume: undefined,
spring: SpringStainlessSteel.Regular('gold'),
housing: {
upper: Material.PC(Color.Transparent('#5C8683')),
lower: Material.PC(Color.Transparent('#5C8683')),
},
force: {
bottom: undefined,
actuation: Force.GramForce(55),
},
travel: {
pre: Travel.Millimeter(2.0, Tolerance.PlusMinus(0.2)),
total: undefined,
},
} satisfies Switch;
Loading

0 comments on commit 3ed92a2

Please sign in to comment.