Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
olehmisar committed Dec 18, 2024
0 parents commit 5681b70
Show file tree
Hide file tree
Showing 19 changed files with 1,954 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.sol]
indent_size = 4

[*.nr]
indent_size = 4

[*.rs]
indent_size = 4
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint Test

on: [push]

jobs:
build:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version: [20]
steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v4
with:
version: 9

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Run lint test
run: pnpm test
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.DS_Store
node_modules
build
dist
.vercel
package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

.vscode/settings.json

codegenCache.json

artifacts
cache

**/target/*.bak
18 changes: 18 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.DS_Store
node_modules
/build
dist
/package
.env
.env.*
!.env.example

vite.config.js.timestamp-*
vite.config.ts.timestamp-*

target/

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Contributing

## Requirements

- Node.js: recommended to use [nvm](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating)
- pnpm: `npm install -g pnpm`

### Project structure

- `apps/` - Applications
- `packages/` - Packages

### Common scripts

Scripts follow the same pattern in all `apps/` and `packages/`:

- `pnpm dev` - Start in development mode
- `pnpm build` - Build for production
- `pnpm test:lint` - Type-check and lint code
- `pnpm test` - Run tests and `pnpm test:lint`
- `pnpm compile` - If available, compile contracts
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Shield Labs Monorepo

Utils and other packages for Shield Labs projects.

## Contributing

[Contributing guide](./CONTRIBUTING.md)
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@repo/monorepo",
"type": "module",
"private": true,
"scripts": {
"test": "pnpm _chore && pnpm -r --parallel test",
"release": "pnpm changeset version && git add . && git commit -m\"chore: release\" && pnpm changeset publish && git push && git push --tags",
"_chore": "pnpm i"
},
"devDependencies": {
"@changesets/cli": "^2.27.10",
"typescript": "^5.6.3"
}
}
1 change: 1 addition & 0 deletions packages/utils/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
7 changes: 7 additions & 0 deletions packages/utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @shield-labs/utils

## 0.1.0

### Minor Changes

- e349915: fix: actually build js
38 changes: 38 additions & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@shield-labs/utils",
"version": "0.1.0",
"type": "module",
"main": "src/index.ts",
"module": "src/index.ts",
"publishConfig": {
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"access": "public"
},
"files": [
"dist",
"src"
],
"scripts": {
"dev": "pnpm _chore && tsc -w",
"build": "pnpm _chore && rm -rf dist && tsc",
"test": "pnpm test:lint && pnpm test:unit",
"test:unit": "pnpm _chore && vitest run",
"test:lint": "tsc --noEmit --emitDeclarationOnly false && prettier --check .",
"test:lint:fix": "pnpm _chore && prettier --write . && eslint . --fix",
"prepublishOnly": "pnpm test && pnpm build",
"_chore": "pnpm i"
},
"dependencies": {
"ms": "^2.1.3",
"ts-essentials": "^9.4.1",
"ufo": "^1.5.4"
},
"devDependencies": {
"@types/ms": "^0.7.34",
"prettier": "^3.2.5",
"typescript": "^5.5.2",
"vitest": "^2.1.3"
}
}
1 change: 1 addition & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as utils from "./utils.js";
10 changes: 10 additions & 0 deletions packages/utils/src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, expect, test } from "vitest";
import { utils } from "./index.js";

describe(utils.arrayPadEnd, () => {
test("pads array", () => {
expect(utils.arrayPadEnd([1, 2, 3], 5, 0)).toEqual([1, 2, 3, 0, 0]);
expect(utils.arrayPadEnd([1, 2, 3], 5, 1)).toEqual([1, 2, 3, 1, 1]);
expect(utils.arrayPadEnd([1, 2, 3], 5, 2)).toEqual([1, 2, 3, 2, 2]);
});
});
69 changes: 69 additions & 0 deletions packages/utils/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import ms from "ms";
import { assert } from "ts-essentials";

export { joinURL as joinUrl } from "ufo";

export function sleep(duration: number | string) {
const durationMs = typeof duration === "number" ? duration : ms(duration);
return new Promise<void>((resolve) => setTimeout(resolve, durationMs));
}

export function iife<T>(fn: () => T): T {
return fn();
}

export function arrayPadEnd<T>(
array: T[],
targetLength: number,
padValue: T,
): T[] {
assert(array.length <= targetLength, "arrayPadEnd: array too long");
const newArray = array.slice();
while (newArray.length < targetLength) {
newArray.push(padValue);
}
return newArray;
}

export function shortAddress(address: string) {
return `${address.slice(0, 6)}...${address.slice(-4)}`;
}

export function assertConnected(account: unknown): asserts account {
assert(account, "account is not connected");
}

export function lazyValue<T>(value: () => T): () => T {
let initialized = false;
let result: T;
return () => {
if (!initialized) {
initialized = true;
result = value();
}
return result;
};
}

export function isAddressEqual(a: string, b: string) {
return a.toLowerCase() === b.toLowerCase();
}

/**
* Prefer this over `value.toString()` because it's typesafe(you can't accidentally call .toString() on another type when refactoring)
*/
export function bigIntToString(value: bigint) {
return value.toString();
}

export function errorToString(error: any) {
return String(error?.message || error);
}

export function removePrefixOrThrow(str: string, prefix: string) {
if (!str.startsWith(prefix)) {
throw new Error(`string does not start with "${prefix}"`);
}

return str.slice(prefix.length);
}
6 changes: 6 additions & 0 deletions packages/utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
}
}
Loading

0 comments on commit 5681b70

Please sign in to comment.