1
0
mirror of https://github.com/dzeiocom/libs.git synced 2025-06-12 19:09:18 +00:00

Add modules (#41)

* Added modules for object-utils
+ moved from parcel to esbuild

Signed-off-by: Avior <github@avior.me>

* Moved url-manager

Signed-off-by: Avior <github@avior.me>

* Fixed codacy error

Signed-off-by: Avior <github@avior.me>
This commit is contained in:
2021-09-29 10:12:53 +02:00
committed by GitHub
parent 329f1ee06d
commit b7b604e11f
10 changed files with 435 additions and 32 deletions

View File

@ -28,7 +28,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noFallthroughCasesInSwitch": true
},
"exclude": [
"node_modules"

View File

@ -0,0 +1,6 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "ES2015"
}
}

View File

@ -10,19 +10,21 @@
"homepage": "https://github.com/dzeiocom/libs/tree/master/packages/object-util",
"author": "Aviortheking",
"license": "MIT",
"main": "./dist/ObjectUtil.js",
"types": "./dist/ObjectUtil.d.ts",
"main": "./dist/cjs/ObjectUtil.js",
"module": "./dist/esm/ObjectUtil.js",
"types": "./dist/types/ObjectUtil.d.ts",
"sideEffects": false,
"devDependencies": {
"@types/jest": "^27.0.0",
"esbuild": "^0.13.2",
"jest": "^27.0.0",
"parcel": "1.12.3",
"ts-jest": "^27.0.0",
"ts-node": "^10.2.1",
"typescript": "^4.0.2"
},
"scripts": {
"prepublishOnly": "npm run build",
"build": "parcel build src/index.ts --out-file browser.js --experimental-scope-hoisting && tsc",
"build": "esbuild src/index.ts --outfile=dist/browser.js --minify --bundle --target=es6 && tsc && tsc --project tsconfig.esm.json",
"test": "jest --coverage"
}
}

View File

@ -0,0 +1,11 @@
{
"extends": "../config/tsconfig.esm.json",
"compilerOptions": {
"outDir": "dist/esm",
"declaration": false,
"declarationDir": null
},
"files": [
"src/ObjectUtil.ts"
]
}

View File

@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist"
"outDir": "dist/cjs",
"declarationDir": "dist/types"
},
"files": [
"src/ObjectUtil.ts"

View File

@ -10,7 +10,8 @@
"homepage": "https://github.com/dzeiocom/libs/tree/master/packages/url-manager#readme",
"author": "Aviortheking",
"license": "MIT",
"main": "./dist/URLManager.js",
"main": "./dist/cjs/URLManager.js",
"module": "./dist/esm/URLManager.js",
"types": "./dist/URLManager.d.ts",
"keywords": [
"url",
@ -23,15 +24,18 @@
"devDependencies": {
"@types/chai": "^4.2.12",
"@types/jest": "^26.0.10",
"esbuild": "^0.13.2",
"jest": "^26.4.2",
"parcel": "1.12.3",
"ts-jest": "^26.4.4",
"ts-node": "^10.2.1",
"typescript": "^4.0.2"
},
"scripts": {
"prepublishOnly": "yarn build",
"build": "parcel build src/index.ts --out-file browser.js --experimental-scope-hoisting && tsc",
"build": "esbuild src/index.ts --bundle --outfile=dist/browser.js --minify --target=es6 && tsc && tsc --project tsconfig.esm.json",
"test": "jest --coverage"
},
"dependencies": {
"@dzeio/object-util": "^1.4.0"
}
}

View File

@ -1,3 +1,5 @@
import { objectLoop } from '@dzeio/object-util'
/**
* Easy URLs manager
*/
@ -314,13 +316,9 @@ export default class URLManager {
return undefined
}
if (format) {
for (const key in format) {
if (!(key in format)) {
continue
}
const replacing = format[key]
path = path.replace(`[${key}]`, replacing)
}
objectLoop(format, (replacing, key) => {
path = path?.replace(`[${key}]`, replacing)
})
}
return `${(path.startsWith('/') ? '' : '/')}${path}`
}
@ -328,24 +326,17 @@ export default class URLManager {
private formatQuery(options?: { queryArrayJoin?: string }) {
let result = ''
const queryTmp = this.query()
for (const key in queryTmp) {
if (!Object.prototype.hasOwnProperty.call(queryTmp, key)) {
continue
}
const element = queryTmp[key]
objectLoop(queryTmp, (element, key) => {
result += result.length === 0 ? '?' : '&'
if (typeof element !== 'object') {
result += `${key}=${element}`
continue
return
}
if (options?.queryArrayJoin) {
result += `${key}=${element.join(options.queryArrayJoin)}`
continue
return
}
for (let i = 0; i < element.length; i++) {
@ -355,7 +346,7 @@ export default class URLManager {
}
result += `${key}=${val}`
}
}
})
if (!result) {
return undefined

View File

@ -0,0 +1,11 @@
{
"extends": "../config/tsconfig.esm.json",
"compilerOptions": {
"outDir": "dist/esm",
"declaration": false,
"declarationDir": null
},
"files": [
"src/URLManager.ts"
]
}

View File

@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist"
"outDir": "dist/cjs",
"declarationDir": "dist/types"
},
"files": [
"src/URLManager.ts"