-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
373 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
root: true, | ||
plugins: ['@typescript-eslint', 'import', 'prettier'], | ||
extends: [ | ||
'airbnb-typescript/base', | ||
'prettier', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:import/typescript', | ||
], | ||
parser: '@typescript-eslint/parser', | ||
rules: { | ||
'@typescript-eslint/explicit-function-return-type': 'error', | ||
'@typescript-eslint/no-unused-vars': 'error', | ||
}, | ||
parserOptions: { | ||
project: './tsconfig.test.json', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
### Node template | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
build | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
# macOs | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"printWidth": 80, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": false, | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"bracketSpacing": true, | ||
"jsxSingleQuote": false, | ||
"arrowParens": "always", | ||
"proseWrap": "never", | ||
"htmlWhitespaceSensitivity": "strict", | ||
"endOfLine": "lf" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# forge | ||
# loadout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { build } from 'esbuild' | ||
import copy from 'esbuild-plugin-copy' | ||
|
||
const sharedConfig = { | ||
entryPoints: ['src/index.ts'], | ||
bundle: true, | ||
minify: false, | ||
tsconfig: 'tsconfig.json', | ||
} | ||
|
||
build({ | ||
...sharedConfig, | ||
platform: 'node', // for CJS | ||
outfile: 'build/index.js', | ||
}) | ||
|
||
build({ | ||
...sharedConfig, | ||
outfile: 'build/index.esm.js', | ||
platform: 'neutral', // for ESM | ||
format: 'esm', | ||
plugins: [ | ||
copy({ | ||
resolveFrom: 'cwd', | ||
assets: { | ||
from: ['./package.json'], | ||
to: ['./build/package.json'], | ||
}, | ||
}), | ||
], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"type": "module", | ||
"name": "@awfl-team/loadout", | ||
"version": "0.0.1", | ||
"description": "", | ||
"files": [ | ||
"build/*" | ||
], | ||
"module": "build/index.esm.js", | ||
"main": "build/index.js", | ||
"typings": "build/index.d.ts", | ||
"scripts": { | ||
"build": "node build.js", | ||
"build:type": "npm-dts generate -o ./build/index.d.ts", | ||
"lint": "eslint --fix ./src --ignore-path .gitignore && prettier --write .", | ||
"test": "jest --config jest.config.cjs" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/awfl-team/loadout.git" | ||
}, | ||
"author": "Florian Robert", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/awfl-team/loadout/issues" | ||
}, | ||
"homepage": "https://github.com/awfl-team/loadout#readme", | ||
"devDependencies": { | ||
"@types/jest": "^29.5.12", | ||
"@typescript-eslint/eslint-plugin": "^5.55.0", | ||
"@typescript-eslint/parser": "^5.55.0", | ||
"esbuild": "^0.19.11", | ||
"esbuild-plugin-copy": "^2.1.1", | ||
"eslint": "^8.36.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-airbnb-typescript": "^17.0.0", | ||
"eslint-config-prettier": "^8.7.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"jest": "^29.7.0", | ||
"npm-dts": "^1.3.12", | ||
"prettier": "^2.8.4", | ||
"ts-jest": "^29.1.2", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
cleanPrimitiveDuplicate, | ||
compact, | ||
concat, | ||
convertToMap, | ||
isEmpty, | ||
} from './index' | ||
|
||
describe('array', () => { | ||
describe('concat', () => { | ||
it('should concat two arrays', () => { | ||
expect(concat([1], [2])).toEqual([1, 2]) | ||
}) | ||
}) | ||
|
||
describe('cleanPrimitiveDuplicate', () => { | ||
it('should clean duplicate', () => { | ||
expect(cleanPrimitiveDuplicate([1, 1, 1])).toEqual([1]) | ||
}) | ||
}) | ||
|
||
describe('convertToMap', () => { | ||
it('should transform array to map', () => { | ||
expect( | ||
convertToMap([{ id: 1 }, { id: 2 }, { id: 3 }], (o) => o.id) | ||
).toEqual( | ||
new Map([ | ||
[1, { id: 1 }], | ||
[2, { id: 2 }], | ||
[3, { id: 3 }], | ||
]) | ||
) | ||
}) | ||
}) | ||
|
||
describe('compact', () => { | ||
it('should clean all falsy value', () => { | ||
expect(compact([false, null, 0, '', undefined, NaN])).toEqual([]) | ||
}) | ||
|
||
it('should return undefined with maybe value', () => { | ||
expect(compact(undefined)).toEqual(undefined) | ||
}) | ||
}) | ||
|
||
describe('isEmpty', () => { | ||
it('should true on empty array', () => { | ||
expect(isEmpty([])).toEqual(true) | ||
}) | ||
|
||
it('should return false on not empty array', () => { | ||
expect(isEmpty([1])).toEqual(false) | ||
}) | ||
|
||
it('should return true on undefined array', () => { | ||
expect(isEmpty(undefined)).toEqual(true) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Maybe, Primitive } from '../type' | ||
|
||
export const convertToMap = <T, KEY>( | ||
toMap: Maybe<T[]>, | ||
keyOfElement: (toMapElement: T) => Maybe<KEY> | ||
): Map<KEY, T> | undefined => { | ||
return toMap?.reduce((map, obj) => { | ||
const key = keyOfElement(obj) | ||
|
||
return key !== undefined && key !== null ? map.set(key, obj) : map | ||
}, new Map<KEY, T>()) | ||
} | ||
export const cleanPrimitiveDuplicate = ( | ||
array: Primitive[] | undefined | ||
): Primitive[] => [...new Set(array)] | ||
|
||
export const concat = <T>(arr1: T[], arr2: T[]): T[] => [...arr1, ...arr2] | ||
|
||
export const compact = <T>(arr: Maybe<T[]>): T[] | undefined => | ||
arr?.filter((value) => !!value) | ||
|
||
export const isEmpty = <T>(arr: Maybe<T[]>): boolean => !arr?.length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './array/index' | ||
export * from './object/index' | ||
export * from './type' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { isEmptyObject } from './index' | ||
|
||
describe('object', () => { | ||
describe('isEmptyObject', () => { | ||
it('should return true on empty object', () => { | ||
expect(isEmptyObject({})).toEqual(true) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const isEmptyObject = <T extends Record<string, unknown>>( | ||
toTest?: T | null | undefined | ||
): toTest is T => | ||
!(!!toTest && Object.values(toTest).some((value) => value != null)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export type Primitive = | ||
| number | ||
| null | ||
| string | ||
| boolean | ||
| symbol | ||
| bigint | ||
| undefined | ||
|
||
export type Maybe<T> = T | Nullish | ||
|
||
export type Nullish = undefined | null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./build", | ||
"target": "es2022", | ||
"module": "esnext", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"resolveJsonModule": true | ||
}, | ||
"exclude": ["node_modules", "build", "**/*.test.ts"], | ||
"include": ["./src", "package.json"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "./tsconfig.json", "exclude": ["node_modules", "build"] } |