Skip to content

Commit

Permalink
init repo
Browse files Browse the repository at this point in the history
  • Loading branch information
florob95 committed Apr 2, 2024
1 parent 7adb2d0 commit 06b1de2
Show file tree
Hide file tree
Showing 16 changed files with 373 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .eslintrc.cjs
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',
},
}
135 changes: 135 additions & 0 deletions .gitignore
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
14 changes: 14 additions & 0 deletions .prettierrc
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"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# forge
# loadout
31 changes: 31 additions & 0 deletions build.js
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'],
},
}),
],
})
4 changes: 4 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
}
Empty file added package-lock.json
Empty file.
46 changes: 46 additions & 0 deletions package.json
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"
}
}
59 changes: 59 additions & 0 deletions src/array/index.test.ts
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)
})
})
})
22 changes: 22 additions & 0 deletions src/array/index.ts
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
3 changes: 3 additions & 0 deletions src/index.ts
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'
9 changes: 9 additions & 0 deletions src/object/index.test.ts
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)
})
})
})
4 changes: 4 additions & 0 deletions src/object/index.ts
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))
12 changes: 12 additions & 0 deletions src/type.ts
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
14 changes: 14 additions & 0 deletions tsconfig.json
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"]
}
1 change: 1 addition & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "./tsconfig.json", "exclude": ["node_modules", "build"] }

0 comments on commit 06b1de2

Please sign in to comment.