mirror of
https://github.com/dzeiocom/libs.git
synced 2025-06-06 16:19:56 +00:00
Merge branch 'master' into make-functions-use-null-23
This commit is contained in:
commit
88522608c2
@ -9,3 +9,7 @@ insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{yaml|yml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
186
.eslintrc.json
186
.eslintrc.json
@ -1,188 +1,6 @@
|
||||
{
|
||||
"root": true,
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended"
|
||||
"./packages/config/eslint/react-typescript"
|
||||
],
|
||||
"globals": {
|
||||
"Atomics": "readonly",
|
||||
"SharedArrayBuffer": "readonly"
|
||||
},
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"project": "tsconfig.json",
|
||||
"ecmaFeatures": {
|
||||
"jsx": true
|
||||
},
|
||||
"ecmaVersion": 2018,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
"indent": [
|
||||
"error",
|
||||
"tab",
|
||||
{"SwitchCase": 1}
|
||||
],
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"unix"
|
||||
],
|
||||
|
||||
"quotes": "off",
|
||||
|
||||
"semi": "off",
|
||||
|
||||
"no-unused-expressions": "off",
|
||||
"@typescript-eslint/no-unused-expressions": ["error", { "allowTernary": true }],
|
||||
|
||||
"@typescript-eslint/adjacent-overload-signatures": "error",
|
||||
"@typescript-eslint/array-type": [
|
||||
"error",
|
||||
{
|
||||
"default": "generic"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/ban-types": "error",
|
||||
"@typescript-eslint/consistent-type-assertions": "error",
|
||||
"@typescript-eslint/consistent-type-definitions": "error",
|
||||
"@typescript-eslint/explicit-member-accessibility": [
|
||||
"error",
|
||||
{
|
||||
"accessibility": "explicit"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/interface-name-prefix": "off",
|
||||
"@typescript-eslint/member-delimiter-style": [
|
||||
"error",
|
||||
{
|
||||
"multiline": {
|
||||
"delimiter": "none",
|
||||
"requireLast": true
|
||||
},
|
||||
"singleline": {
|
||||
"delimiter": "comma",
|
||||
"requireLast": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/member-ordering": "error",
|
||||
"@typescript-eslint/no-empty-function": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-parameter-properties": "off",
|
||||
"@typescript-eslint/no-use-before-define": "off",
|
||||
"@typescript-eslint/prefer-for-of": "error",
|
||||
"@typescript-eslint/prefer-function-type": "error",
|
||||
"@typescript-eslint/prefer-namespace-keyword": "error",
|
||||
"@typescript-eslint/quotes": [
|
||||
"error",
|
||||
"single",
|
||||
{
|
||||
"avoidEscape": true
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/semi": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"@typescript-eslint/triple-slash-reference": "error",
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unified-signatures": "error",
|
||||
"arrow-body-style": "error",
|
||||
"arrow-parens": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
|
||||
"camelcase": ["error", {
|
||||
"properties": "never",
|
||||
"allow": ["^[A-Za-z][a-zA-Za-z]+_[A-Za-z]+$"]
|
||||
}],
|
||||
"complexity": "off",
|
||||
"constructor-super": "error",
|
||||
"curly": "error",
|
||||
"dot-notation": "error",
|
||||
"eol-last": "error",
|
||||
"eqeqeq": [
|
||||
"error",
|
||||
"smart"
|
||||
],
|
||||
"guard-for-in": "error",
|
||||
"id-blacklist": [
|
||||
"error",
|
||||
"any",
|
||||
"Number",
|
||||
"number",
|
||||
"String",
|
||||
"string",
|
||||
"Boolean",
|
||||
"boolean",
|
||||
"Undefined"
|
||||
],
|
||||
"id-match": "error",
|
||||
"max-classes-per-file": [
|
||||
"error",
|
||||
1
|
||||
],
|
||||
"max-len": [
|
||||
"warn",
|
||||
{
|
||||
"code": 120
|
||||
}
|
||||
],
|
||||
"new-parens": "error",
|
||||
"no-bitwise": "error",
|
||||
"no-caller": "error",
|
||||
"no-cond-assign": "error",
|
||||
"no-debugger": "error",
|
||||
"no-empty": "error",
|
||||
"no-eval": "error",
|
||||
"no-fallthrough": "off",
|
||||
"no-invalid-this": "off",
|
||||
"no-multiple-empty-lines": "error",
|
||||
"no-new-wrappers": "error",
|
||||
"no-shadow": [
|
||||
"error",
|
||||
{
|
||||
"hoist": "all"
|
||||
}
|
||||
],
|
||||
"no-throw-literal": "error",
|
||||
"no-trailing-spaces": "error",
|
||||
"no-undef-init": "error",
|
||||
"no-unsafe-finally": "error",
|
||||
"no-unused-labels": "error",
|
||||
"no-unused-vars": "off",
|
||||
"no-var": "error",
|
||||
"object-shorthand": "error",
|
||||
"one-var": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"prefer-const": "error",
|
||||
"quote-props": [
|
||||
"error",
|
||||
"consistent-as-needed"
|
||||
],
|
||||
|
||||
"space-before-function-paren": "off",
|
||||
"@typescript-eslint/space-before-function-paren": ["error", {
|
||||
"asyncArrow": "always",
|
||||
"anonymous": "never",
|
||||
"named": "never"
|
||||
}],
|
||||
"spaced-comment": "error",
|
||||
"use-isnan": "error",
|
||||
"valid-typeof": "off"
|
||||
}
|
||||
"root": true
|
||||
}
|
||||
|
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -1,2 +1 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
* text=auto eol=lf
|
||||
|
8
.github/dependabot.yml
vendored
8
.github/dependabot.yml
vendored
@ -5,7 +5,13 @@
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "nom" # See documentation for possible values
|
||||
- package-ecosystem: "npm" # See documentation for possible values
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
||||
- package-ecosystem: "github-actions"
|
||||
# Workflow files stored in the
|
||||
# default location of `.github/workflows`
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
|
42
.github/workflows/node.js.yml
vendored
42
.github/workflows/node.js.yml
vendored
@ -16,20 +16,42 @@ jobs:
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [10.x, 12.x, 14.x]
|
||||
node-version: [12.x, 14.x, 16.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v2.4.1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- run: yarn
|
||||
- run: yarn workspaces run build
|
||||
- run: yarn workspaces run test
|
||||
# You may pin to the exact commit or the version.
|
||||
# uses: codecov/codecov-action@6004246f47ab62d32be025ce173b241cd84ac58e
|
||||
- uses: codecov/codecov-action@v1.0.13
|
||||
|
||||
- name: Upgrade NPM
|
||||
run: npm -g install npm
|
||||
|
||||
- name: Install packages
|
||||
run: npm i && npm i --workspaces
|
||||
|
||||
- name: Build packages
|
||||
run: npm run build --workspaces --if-present
|
||||
|
||||
- name: Test packages
|
||||
run: npm run test --workspaces --if-present
|
||||
|
||||
- uses: sonarsource/sonarcloud-github-action@master
|
||||
if: matrix.node-version == '16.x'
|
||||
with:
|
||||
# Comma-separated list of files to upload
|
||||
files: ./packages/url-manager/coverage/coverage-final.json,./packages/object-util/coverage/coverage-final.json,./packages/easy-sitemap/coverage/coverage-final.json # optional
|
||||
args: >
|
||||
-Dsonar.organization=dzeio
|
||||
-Dsonar.projectKey=dzeiocom_libs
|
||||
-Dsonar.javascript.lcov.reportPaths=packages/**/coverage/lcov.info
|
||||
-Dsonar.testExecutionReportPaths=packages/easy-sitemap/test-report.xml,packages/object-util/test-report.xml,packages/url-manager/test-report.xml
|
||||
-Dsonar.sources=packages
|
||||
-Dsonar.exclusions=packages/**/__tests__,packages/**/dist,node_modules,packages/**/coverage
|
||||
-Dsonar.tests=packages/easy-sitemap/__tests__,packages/object-util/__tests__,packages/url-manager/__tests__
|
||||
-Dsonar.test.inclusions=packages/**/*.test.ts
|
||||
-Dsonar.sourceEncoding=UTF-8
|
||||
-Dsonar.verbose=true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ yarn-error.log
|
||||
dist
|
||||
.cache
|
||||
coverage
|
||||
test-report.xml
|
||||
|
34
README.md
34
README.md
@ -1,3 +1,35 @@
|
||||
# Libs
|
||||
|
||||
Multi Packages repo containing libraries used through our websites
|
||||
Collection of libraries for differents usages
|
||||
|
||||
[](https://codecov.io/gh/dzeiocom/libs)
|
||||
|
||||
## Libraries
|
||||
|
||||
### DOM Manager
|
||||
|
||||
Library to manage the browser DOM easier
|
||||
|
||||
### Easy Sitemap
|
||||
|
||||
Sitemap Builder
|
||||
|
||||
### Listener
|
||||
|
||||
Custom implementation of the NodeJS Listener
|
||||
|
||||
### Logger
|
||||
|
||||
A nicer `console` with support for theming and prefixes
|
||||
|
||||
### Object Util
|
||||
|
||||
Functions that make it easier to manipulate objects
|
||||
|
||||
### Queue
|
||||
|
||||
A `async` Queue system to do heavy work quicker
|
||||
|
||||
### URL Manager
|
||||
|
||||
A complete URL parser/serializer
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"transform": {
|
||||
"^.+\\.tsx?$": "ts-jest"
|
||||
}
|
||||
"preset": "ts-jest",
|
||||
"testEnvironment": "node",
|
||||
"testResultsProcessor": "jest-sonar-reporter"
|
||||
}
|
||||
|
15
lerna.json
15
lerna.json
@ -1,15 +0,0 @@
|
||||
{
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"npmClient": "yarn",
|
||||
"useWorkspaces": true,
|
||||
"version": "independent",
|
||||
"command": {
|
||||
"publish": {
|
||||
"npmClient": "npm",
|
||||
"allowBranch": ["master"],
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
}
|
||||
}
|
||||
}
|
29858
package-lock.json
generated
Normal file
29858
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
32
package.json
32
package.json
@ -1,19 +1,23 @@
|
||||
{
|
||||
"name": "components",
|
||||
"name": "@dzeio/libs",
|
||||
"private": true,
|
||||
"workspaces": {
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"nohoist": [
|
||||
"**/@types/**"
|
||||
]
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/config",
|
||||
"packages/dom-manager",
|
||||
"packages/easy-sitemap",
|
||||
"packages/listener",
|
||||
"packages/logger",
|
||||
"packages/object-util",
|
||||
"packages/queue",
|
||||
"packages/url-manager"
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"lerna": "^3.22.1"
|
||||
},
|
||||
"scripts": {
|
||||
"lerna": "lerna publish"
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.0.2",
|
||||
"jest": "^27.2.3",
|
||||
"jest-sonar-reporter": "^2.0.0",
|
||||
"ts-jest": "^27.0.5",
|
||||
"ts-node": "^10.2.1",
|
||||
"typescript": "^4.4.3"
|
||||
}
|
||||
}
|
||||
|
1
packages/config/.gitignore
vendored
Normal file
1
packages/config/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
next.config.js
|
6
packages/config/.npmignore
Normal file
6
packages/config/.npmignore
Normal file
@ -0,0 +1,6 @@
|
||||
.gitignore
|
||||
.npmignore
|
||||
package-lock.json
|
||||
package.json
|
||||
next.config.ts
|
||||
tsconfig.json
|
9
packages/config/LICENSE
Normal file
9
packages/config/LICENSE
Normal file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Dzeio
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
45
packages/config/README.md
Normal file
45
packages/config/README.md
Normal file
@ -0,0 +1,45 @@
|
||||
# Dzeio Config
|
||||
|
||||
thoses are base configuration files for multiple items
|
||||
|
||||
## ESLint
|
||||
|
||||
Depending on your configuration add a `.eslintrc.json` to your repository and add the following code (remove the comments if you keep it a a json file)
|
||||
|
||||
```json
|
||||
{
|
||||
"extends": [
|
||||
// Note: add only one file as they calls each ones out
|
||||
|
||||
// Base configuration for javascript
|
||||
"./node_modules/@dzeio/config/eslint/base",
|
||||
|
||||
// React configuration
|
||||
"./node_modules/@dzeio/config/eslint/react",
|
||||
|
||||
// Typescript configuration
|
||||
"./node_modules/@dzeio/config/eslint/typescript",
|
||||
|
||||
// Typescript AND React configuration
|
||||
"./node_modules/@dzeio/config/eslint/react-typescript",
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Typescript
|
||||
|
||||
```json
|
||||
{
|
||||
// Note: Only include one file
|
||||
|
||||
// Base Typescript configuration
|
||||
"extends": "@dzeio/config/tsconfig.base.json",
|
||||
|
||||
// Base NextJS configuration
|
||||
"extends": "@dzeio/config/tsconfig.nextjs.json",
|
||||
}
|
||||
```
|
||||
|
||||
## Copy-paste
|
||||
|
||||
files under the folder `copy-paste` are configurations that can't be extended so you'll have to copy/paste them into your repository
|
196
packages/config/eslint/base.json
Normal file
196
packages/config/eslint/base.json
Normal file
@ -0,0 +1,196 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended"
|
||||
],
|
||||
"globals": {
|
||||
"Atomics": "readonly",
|
||||
"SharedArrayBuffer": "readonly"
|
||||
},
|
||||
"plugins": [],
|
||||
"rules": {
|
||||
"arrow-body-style": "error",
|
||||
"arrow-parens": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"complexity": "off",
|
||||
"constructor-super": "error",
|
||||
"curly": "error",
|
||||
"dot-notation": "error",
|
||||
"eol-last": "error",
|
||||
"eqeqeq": [
|
||||
"error",
|
||||
"smart"
|
||||
],
|
||||
"for-direction": "error",
|
||||
"getter-return": "error",
|
||||
"guard-for-in": "error",
|
||||
"id-blacklist": [
|
||||
"error",
|
||||
"any",
|
||||
"Number",
|
||||
"number",
|
||||
"String",
|
||||
"string",
|
||||
"Boolean",
|
||||
"boolean",
|
||||
"Undefined"
|
||||
],
|
||||
"id-length": [
|
||||
"warn",
|
||||
{
|
||||
"exceptions": [
|
||||
"_",
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
"p"
|
||||
]
|
||||
}
|
||||
],
|
||||
"id-match": "error",
|
||||
"indent": [
|
||||
"error",
|
||||
"tab",
|
||||
{
|
||||
"SwitchCase": 1
|
||||
}
|
||||
],
|
||||
"init-declration": "off",
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"unix"
|
||||
],
|
||||
"max-classes-per-file": [
|
||||
"error",
|
||||
1
|
||||
],
|
||||
"max-len": [
|
||||
"warn",
|
||||
{
|
||||
"code": 200
|
||||
}
|
||||
],
|
||||
"new-parens": "error",
|
||||
"no-async-promise-executor": "error",
|
||||
"no-await-in-loop": "warn",
|
||||
"no-bitwise": "error",
|
||||
"no-caller": "error",
|
||||
"no-compare-neg-zero": "error",
|
||||
"no-cond-assign": "error",
|
||||
"no-console": "off",
|
||||
"no-constant-condition": "error",
|
||||
"no-control-regex": "warn",
|
||||
"no-debugger": "error",
|
||||
"no-delete-var": "error",
|
||||
"no-dupe-args": "error",
|
||||
"no-dupe-else-if": "error",
|
||||
"no-dupe-keys": "error",
|
||||
"no-duplicate-case": "error",
|
||||
"no-empty": [
|
||||
"error",
|
||||
{
|
||||
"allowEmptyCatch": true
|
||||
}
|
||||
],
|
||||
"no-empty-character-class": "error",
|
||||
"no-eval": "error",
|
||||
"no-ex-assign": "error",
|
||||
"no-extra-boolean-cast": "error",
|
||||
"no-extra-parens": [
|
||||
"error",
|
||||
"all",
|
||||
{
|
||||
"ignoreJSX": "multi-line"
|
||||
}
|
||||
],
|
||||
"no-extra-semi": "error",
|
||||
"no-fallthrough": "off",
|
||||
"no-func-assign": "error",
|
||||
"no-import-assign": "error",
|
||||
"no-inner-declarations": "error",
|
||||
"no-invalid-regexp": "error",
|
||||
"no-invalid-this": "off",
|
||||
"no-irregular-whitespace": "error",
|
||||
"no-label-var": "error",
|
||||
"no-loss-of-precision": "error",
|
||||
"no-misleading-character-class": "error",
|
||||
"no-multiple-empty-lines": "error",
|
||||
"no-new-wrappers": "error",
|
||||
"no-obj-calls": "error",
|
||||
"no-promise-executor-return": "error",
|
||||
"no-prototype-builtins": "error",
|
||||
"no-regex-spaces": "error",
|
||||
"no-restricted-globals": "off",
|
||||
"no-setter-return": "error",
|
||||
"no-shadow": [
|
||||
"error",
|
||||
{
|
||||
"builtinGlobals": false,
|
||||
"hoist": "all"
|
||||
}
|
||||
],
|
||||
"no-shadow-restricted-names": "error",
|
||||
"no-sparse-arrays": "error",
|
||||
"no-template-curly-in-string": "warn",
|
||||
"no-throw-literal": "error",
|
||||
"no-trailing-spaces": "error",
|
||||
"no-undef": "error",
|
||||
"no-undef-init": "error",
|
||||
"no-underscore-dangle": "off",
|
||||
"no-unexpected-multiline": "error",
|
||||
"no-unreachable": "warn",
|
||||
"no-unreachable-loop": "warn",
|
||||
"no-unsafe-finally": "error",
|
||||
"no-unsafe-negation": "error",
|
||||
"no-unsafe-optional-chaining": "error",
|
||||
"no-unused-expressions": [
|
||||
"error",
|
||||
{
|
||||
"allowTernary": true
|
||||
}
|
||||
],
|
||||
"no-unused-labels": "error",
|
||||
"no-unused-vars": "warn",
|
||||
"no-var": "error",
|
||||
"object-shorthand": "error",
|
||||
"one-var": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"prefer-const": "error",
|
||||
"quote-props": [
|
||||
"error",
|
||||
"consistent-as-needed"
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single",
|
||||
{
|
||||
"avoidEscape": true
|
||||
}
|
||||
],
|
||||
"radix": "error",
|
||||
"require-atomic-updates": "error",
|
||||
"semi": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"space-before-function-paren": [
|
||||
"error",
|
||||
{
|
||||
"anonymous": "never",
|
||||
"asyncArrow": "always",
|
||||
"named": "never"
|
||||
}
|
||||
],
|
||||
"spaced-comment": "error",
|
||||
"use-isnan": "error",
|
||||
"valid-typeof": "warn"
|
||||
}
|
||||
}
|
6
packages/config/eslint/react-typescript.json
Normal file
6
packages/config/eslint/react-typescript.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": [
|
||||
"./react",
|
||||
"./typescript"
|
||||
]
|
||||
}
|
15
packages/config/eslint/react.json
Normal file
15
packages/config/eslint/react.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": [
|
||||
"./base",
|
||||
"plugin:react/recommended"
|
||||
],
|
||||
"settings": {
|
||||
"react": {
|
||||
"version": "detect"
|
||||
}
|
||||
},
|
||||
"plugins": [
|
||||
"react"
|
||||
],
|
||||
"rules": {}
|
||||
}
|
115
packages/config/eslint/typescript.json
Normal file
115
packages/config/eslint/typescript.json
Normal file
@ -0,0 +1,115 @@
|
||||
{
|
||||
"extends": [
|
||||
"./base",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"overrides": [
|
||||
{
|
||||
"files": [
|
||||
"*.ts",
|
||||
"*.tsx"
|
||||
],
|
||||
"rules": {
|
||||
"no-extra-parens": "off",
|
||||
"no-unused-expressions": "off",
|
||||
"no-shadow": "off",
|
||||
"quotes": "off",
|
||||
"semi": "off",
|
||||
"space-before-function-paren": "off"
|
||||
}
|
||||
}
|
||||
],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
"jsx": true
|
||||
},
|
||||
"ecmaVersion": 2018,
|
||||
"project": "tsconfig.json",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/adjacent-overload-signatures": "error",
|
||||
"@typescript-eslint/array-type": [
|
||||
"error",
|
||||
{
|
||||
"default": "generic"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/ban-types": "error",
|
||||
"@typescript-eslint/consistent-type-assertions": "error",
|
||||
"@typescript-eslint/consistent-type-definitions": "error",
|
||||
"@typescript-eslint/explicit-member-accessibility": [
|
||||
"error",
|
||||
{
|
||||
"accessibility": "explicit"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||
"@typescript-eslint/interface-name-prefix": "off",
|
||||
"@typescript-eslint/member-delimiter-style": [
|
||||
"error",
|
||||
{
|
||||
"multiline": {
|
||||
"delimiter": "none",
|
||||
"requireLast": true
|
||||
},
|
||||
"singleline": {
|
||||
"delimiter": "comma",
|
||||
"requireLast": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/member-ordering": "error",
|
||||
"@typescript-eslint/no-empty-function": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-extra-parens": [
|
||||
"error",
|
||||
"all",
|
||||
{
|
||||
"ignoreJSX": "all"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-inferrable-types": "off",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-parameter-properties": "off",
|
||||
"@typescript-eslint/no-shadow": "error",
|
||||
"@typescript-eslint/no-unused-expressions": [
|
||||
"error",
|
||||
{
|
||||
"allowTernary": true
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-use-before-define": "off",
|
||||
"@typescript-eslint/prefer-for-of": "error",
|
||||
"@typescript-eslint/prefer-function-type": "error",
|
||||
"@typescript-eslint/prefer-namespace-keyword": "error",
|
||||
"@typescript-eslint/quotes": [
|
||||
"error",
|
||||
"single",
|
||||
{
|
||||
"avoidEscape": true
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/semi": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"@typescript-eslint/space-before-function-paren": [
|
||||
"error",
|
||||
{
|
||||
"anonymous": "never",
|
||||
"asyncArrow": "always",
|
||||
"named": "never"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/triple-slash-reference": "error",
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unified-signatures": "error"
|
||||
}
|
||||
}
|
130
packages/config/next.config.ts
Normal file
130
packages/config/next.config.ts
Normal file
@ -0,0 +1,130 @@
|
||||
import { NextConfig, defaultConfig } from 'next/dist/server/config-shared'
|
||||
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants'
|
||||
// @ts-expect-error next-pre-css has no typing available
|
||||
import preCSS from 'next-pre-css'
|
||||
|
||||
/**
|
||||
* Return a default NextJS hardened configuration with experimental features enabled and headers preset
|
||||
*/
|
||||
export const config = (additionnalHost: string): typeof defaultConfig & NextConfig => ({
|
||||
// Experimentals
|
||||
experimental: {
|
||||
plugins: true,
|
||||
profiling: process.env.NODE_ENV === 'developpment',
|
||||
isrFlushToDisk: true,
|
||||
|
||||
// Bugged
|
||||
// https://github.com/vercel/next.js/issues/18913
|
||||
// reactRoot: true,
|
||||
workerThreads: true,
|
||||
|
||||
pageEnv: true,
|
||||
optimizeImages: true,
|
||||
optimizeCss: true,
|
||||
|
||||
scrollRestoration: true,
|
||||
|
||||
stats: process.env.NODE_ENV === 'developpment',
|
||||
externalDir: true,
|
||||
conformance: true,
|
||||
disableOptimizedLoading: false,
|
||||
gzipSize: process.env.NODE_ENV === 'developpment',
|
||||
craCompat: false,
|
||||
|
||||
|
||||
|
||||
},
|
||||
|
||||
excludeDefaultMomentLocales: true,
|
||||
trailingSlash: false,
|
||||
cleanDistDir: true,
|
||||
generateEtags: true,
|
||||
compress: false,
|
||||
// Non experimental config
|
||||
// target: 'serverless',
|
||||
poweredByHeader: false,
|
||||
reactStrictMode: true,
|
||||
|
||||
// Futures
|
||||
future: {
|
||||
strictPostcssConfiguration: true,
|
||||
},
|
||||
|
||||
// Headers and rewrites
|
||||
async headers() {
|
||||
// CSS no CSP, x-xss-protection
|
||||
const CSP = {
|
||||
key: 'Content-Security-Policy',
|
||||
value:
|
||||
// default-src is set to self because prefetch-src is not working propelly see: https://bugs.chromium.org/p/chromium/issues/detail?id=801561
|
||||
"default-src 'self'; " +
|
||||
"frame-ancestors 'none'; " +
|
||||
"form-action 'self'; " +
|
||||
"manifest-src 'self'; " +
|
||||
"prefetch-src 'self'; " +
|
||||
`script-src 'self' 'unsafe-inline' 'unsafe-eval' ${additionnalHost}; ` +
|
||||
"style-src 'self' 'unsafe-inline'; " +
|
||||
"img-src data: 'self'; " +
|
||||
"font-src 'self'; " +
|
||||
`connect-src 'self' ${additionnalHost}; ` +
|
||||
"base-uri 'self';"
|
||||
}
|
||||
const XXssProtection = {
|
||||
key: 'X-XSS-Protection',
|
||||
value: '1; mode=block'
|
||||
}
|
||||
// JS no x-xss-protection
|
||||
|
||||
const headers = [{
|
||||
key: 'X-Frame-Options',
|
||||
value: 'DENY'
|
||||
}, {
|
||||
key: 'X-Content-Type-Options',
|
||||
value: 'nosniff'
|
||||
}, {
|
||||
key: 'Referrer-Policy',
|
||||
value: 'strict-origin-when-cross-origin'
|
||||
}, {
|
||||
key: 'Permissions-Policy',
|
||||
value: 'geolocation=(), microphone=(), interest-cohort=()'
|
||||
}, {
|
||||
key: 'Strict-Transport-Security',
|
||||
value: 'max-age=63072000; includeSubDomains; preload'
|
||||
}, {
|
||||
key: 'X-Download-Options',
|
||||
value: 'noopen'
|
||||
}, {
|
||||
key: 'Expect-CT',
|
||||
value: 'max-age=86400, enforce'
|
||||
}]
|
||||
const excludedExtensions = ['js', 'css', 'json', 'ico', 'png']
|
||||
.map((ext) => `(?!\\.${ext}$)`).join('|')
|
||||
return [{
|
||||
source: `/:path*((?!^\\/_next\\/image)|${excludedExtensions})`,
|
||||
headers: [...headers, XXssProtection, CSP]
|
||||
}, {
|
||||
source: '/',
|
||||
headers: [...headers, XXssProtection, CSP]
|
||||
}, {
|
||||
// No CSP, XXssProtection
|
||||
source: `/:path*(\\.${excludedExtensions}$)`,
|
||||
headers: headers
|
||||
}, {
|
||||
// No CSP, XXssProtection
|
||||
source: '/_next/image:path*',
|
||||
headers: headers
|
||||
}]
|
||||
},
|
||||
})
|
||||
|
||||
export const plugins = [preCSS, {
|
||||
cssModules: true,
|
||||
cssLoaderOptions: {
|
||||
localIdentName: "[hash:base64:6]",
|
||||
},
|
||||
[PHASE_DEVELOPMENT_SERVER]: {
|
||||
cssLoaderOptions: {
|
||||
localIdentName: "[path][name]__[local]"
|
||||
}
|
||||
}
|
||||
}]
|
36
packages/config/package.json
Normal file
36
packages/config/package.json
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "@dzeio/config",
|
||||
"version": "1.1.4",
|
||||
"description": "global configuration files for programming",
|
||||
"author": "Avior",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dzeiocom/libs.git",
|
||||
"directory": "packages/config"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.10.1",
|
||||
"next": "^11.1.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@typescript-eslint/parser": "^4.28.2",
|
||||
"next": "^11.1.2",
|
||||
"next-pre-css": "^1.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"next": {
|
||||
"optional": true
|
||||
},
|
||||
"next-pre-css": {
|
||||
"optional": true
|
||||
},
|
||||
"@typescript-eslint/parser": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "tsc",
|
||||
"build": "tsc --noEmit"
|
||||
}
|
||||
}
|
36
packages/config/tsconfig.base.json
Normal file
36
packages/config/tsconfig.base.json
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Compilation
|
||||
"target": "ES2019", // Follow NodeJS oldest supported LTS and use version from https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping
|
||||
"module": "commonjs",
|
||||
"resolveJsonModule": true,
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"skipLibCheck": true,
|
||||
"allowJs": true,
|
||||
"pretty": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
|
||||
// Type Checking
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
|
||||
"alwaysStrict": true,
|
||||
"strict": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictBindCallApply": true,
|
||||
"strictPropertyInitialization": true,
|
||||
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
6
packages/config/tsconfig.esm.json
Normal file
6
packages/config/tsconfig.esm.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"module": "ES2015"
|
||||
}
|
||||
}
|
8
packages/config/tsconfig.json
Normal file
8
packages/config/tsconfig.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"files": ["./next.config.ts"],
|
||||
"extends": "./tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./",
|
||||
"rootDir": "./"
|
||||
}
|
||||
}
|
15
packages/config/tsconfig.nextjs.json
Normal file
15
packages/config/tsconfig.nextjs.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"target": "ES5",
|
||||
"lib": [
|
||||
"DOM",
|
||||
"DOM.Iterable",
|
||||
"ESNext"
|
||||
],
|
||||
"noEmit": true,
|
||||
"module": "ESNext",
|
||||
"jsx": "preserve",
|
||||
"isolatedModules": true
|
||||
}
|
||||
}
|
@ -12,13 +12,10 @@
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"devDependencies": {
|
||||
"parcel": "^1.12.4",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.3"
|
||||
"parcel": "1.12.3"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "yarn build",
|
||||
"build": "parcel build src/browser.ts --out-file browser.js --experimental-scope-hoisting && tsc",
|
||||
"test": "tsc --noEmit"
|
||||
"build": "parcel build src/browser.ts --out-file browser.js --experimental-scope-hoisting && tsc"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
@ -6,13 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]()
|
||||
|
||||
## [1.1.0] - 2021-03-16
|
||||
|
||||
### Added
|
||||
|
||||
- Support for `image:image` elements
|
||||
|
||||
### Changed
|
||||
|
||||
- Simplified Warning messages
|
||||
|
||||
## [1.0.0] - 2021-01-20
|
||||
|
||||
### Added
|
||||
|
||||
- The sitemap is ready !
|
||||
|
||||
|
||||
[1.0.4]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fobject-util%401.0.4
|
||||
[1.0.2]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fobject-util%401.0.2
|
||||
[1.0.1]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fobject-util%401.0.1
|
||||
[1.0.0]: https://github.com/dzeiocom/libs/releases/tag/%40easy-sitemap%401.0.0
|
||||
[1.1.0]: https://github.com/dzeiocom/libs/releases/tag/easy-sitemap%401.1.0
|
||||
[1.0.0]: https://github.com/dzeiocom/libs/releases/tag/easy-sitemap%401.0.0
|
||||
|
@ -2,6 +2,10 @@
|
||||
|
||||
A very easy to use sitemap generator
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
## Usage
|
||||
|
||||
- Import easy-sitemap
|
||||
@ -30,12 +34,21 @@ const sitemap = new Sitemap('https://www.example.com', {
|
||||
```typescript
|
||||
sitemap.addEntry('/path')
|
||||
|
||||
// you can also add optionnal elements
|
||||
// you can also add optional elements
|
||||
sitemap.addEntry('/path', {
|
||||
// each one are optionnal and they don't all need to be added
|
||||
// each one are optional and they don't all need to be added
|
||||
changefreq: 'always', // webpage change freq
|
||||
lastmod: new Date('2021-01-20'), // webpage lastmod Date
|
||||
priority: 1 // crawler priority
|
||||
priority: 1, // crawler priority,
|
||||
images: [{
|
||||
location: '/path', // Location can be a path as well as a complete url
|
||||
// Optional parameters in Image object
|
||||
caption: 'Image Caption',
|
||||
geoLocation: 'Image Geolocation',
|
||||
title: 'Image Title',
|
||||
license: 'Image License URL',
|
||||
|
||||
}]
|
||||
})
|
||||
```
|
||||
|
||||
|
@ -1,19 +1,19 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Basic Sitemap Tests should not add changefreq if value is incorrect 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" image:xmlns=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc></url></urlset>"`;
|
||||
exports[`Basic Sitemap Tests should not add changefreq if value is incorrect 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc></url></urlset>"`;
|
||||
|
||||
exports[`Basic Sitemap Tests should not add priority when it is incorrect 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" image:xmlns=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc></url></urlset>"`;
|
||||
exports[`Basic Sitemap Tests should not add priority when it is incorrect 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc></url></urlset>"`;
|
||||
|
||||
exports[`Basic Sitemap Tests should return a basic sitemap 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" image:xmlns=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc></url><url><loc>https://www.example.com/</loc></url></urlset>"`;
|
||||
exports[`Basic Sitemap Tests should return a basic sitemap 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc></url><url><loc>https://www.example.com/</loc></url></urlset>"`;
|
||||
|
||||
exports[`Basic Sitemap Tests should return a sitemap 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" image:xmlns=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc><changefreq>always</changefreq><lastmod>2021-01-20T00:00:00.000Z</lastmod><priority>1</priority></url><url><loc>https://www.example.com/</loc></url></urlset>"`;
|
||||
exports[`Basic Sitemap Tests should return a sitemap 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc><changefreq>always</changefreq><lastmod>2021-01-20T00:00:00.000Z</lastmod><priority>1</priority></url><url><loc>https://www.example.com/</loc></url></urlset>"`;
|
||||
|
||||
exports[`Basic Sitemap Tests should return an empty sitemap 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" image:xmlns=\\"http://www.google.com/schemas/sitemap-image/1.1\\"></urlset>"`;
|
||||
exports[`Basic Sitemap Tests should return an empty sitemap 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\"></urlset>"`;
|
||||
|
||||
exports[`image:image tests should build corretcly with multiple image:image 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" image:xmlns=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc><image:image><image:loc>https://www.example.com/test</image:loc><image:caption>Image Caption</image:caption><image:geo_location>Nantes</image:geo_location><image:title>Title</image:title><image:license>Example license url</image:license></image:image><image:image><image:loc>https://www.example.com/test-2</image:loc><image:caption>Image Caption2</image:caption><image:geo_location>Paris</image:geo_location><image:title>Title2</image:title><image:license>Example license url</image:license></image:image></url></urlset>"`;
|
||||
exports[`image:image tests should build corretcly with multiple image:image 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc><image:image><image:loc>https://www.example.com/test</image:loc><image:caption>Image Caption</image:caption><image:geo_location>Nantes</image:geo_location><image:title>Title</image:title><image:license>Example license url</image:license></image:image><image:image><image:loc>https://www.example.com/test-2</image:loc><image:caption>Image Caption2</image:caption><image:geo_location>Paris</image:geo_location><image:title>Title2</image:title><image:license>Example license url</image:license></image:image></url></urlset>"`;
|
||||
|
||||
exports[`image:image tests should build corretcly with single image:image 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" image:xmlns=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc><image:image><image:loc>https://www.example.com/test</image:loc><image:caption>Image Caption</image:caption><image:geo_location>Nantes</image:geo_location><image:title>Title</image:title><image:license>Example license url</image:license></image:image></url></urlset>"`;
|
||||
exports[`image:image tests should build corretcly with single image:image 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc><image:image><image:loc>https://www.example.com/test</image:loc><image:caption>Image Caption</image:caption><image:geo_location>Nantes</image:geo_location><image:title>Title</image:title><image:license>Example license url</image:license></image:image></url></urlset>"`;
|
||||
|
||||
exports[`image:image tests should skip image:image if no location is set 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" image:xmlns=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc></url></urlset>"`;
|
||||
exports[`image:image tests should skip image:image if no location is set 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc></url></urlset>"`;
|
||||
|
||||
exports[`image:image tests should skip image:image if there is more than 1000 images 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" image:xmlns=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc></url></urlset>"`;
|
||||
exports[`image:image tests should skip image:image if there is more than 1000 images 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\"><url><loc>https://www.example.com/path</loc></url></urlset>"`;
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "easy-sitemap",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.2",
|
||||
"description": "A very easy sitemap maker library",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -12,13 +12,6 @@
|
||||
"license": "MIT",
|
||||
"main": "./dist/Sitemap.js",
|
||||
"types": "./dist/Sitemap.d.ts",
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.2.12",
|
||||
"@types/jest": "^26.0.10",
|
||||
"jest": "^26.4.2",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.2"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "yarn build",
|
||||
"build": "tsc",
|
||||
|
@ -4,7 +4,7 @@ export default class Sitemap {
|
||||
|
||||
private static allowedChangefreq = ['always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never']
|
||||
|
||||
private datas = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" image:xmlns="http://www.google.com/schemas/sitemap-image/1.1">'
|
||||
private datas = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">'
|
||||
|
||||
public constructor(
|
||||
private domain: string, private options?: {
|
||||
@ -36,12 +36,7 @@ export default class Sitemap {
|
||||
}) {
|
||||
let entryString = '<url>'
|
||||
|
||||
const url = `${this.domain}${path}`
|
||||
.replace(/&/g, '&')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/</g, '<')
|
||||
const url = this.fixText(`${this.domain}${path}`)
|
||||
|
||||
entryString += `<loc>${url}</loc>`
|
||||
if (options) {
|
||||
@ -53,7 +48,7 @@ export default class Sitemap {
|
||||
}
|
||||
}
|
||||
if (options.lastmod) {
|
||||
entryString += `<lastmod>${options.lastmod.toISOString()}</lastmod>`
|
||||
entryString += `<lastmod>${this.fixText(options.lastmod.toISOString())}</lastmod>`
|
||||
}
|
||||
if (options.priority) {
|
||||
if (options.priority <= 1 && options.priority >= 0 && options.priority.toString().length <= 3) {
|
||||
@ -72,7 +67,7 @@ export default class Sitemap {
|
||||
continue
|
||||
}
|
||||
entryString += '<image:image>'
|
||||
entryString += `<image:loc>${image.location.startsWith('/') ? `${this.domain}${image.location}` : image.location}</image:loc>`
|
||||
entryString += `<image:loc>${this.fixText(image.location.startsWith('/') ? `${this.domain}${image.location}` : image.location)}</image:loc>`
|
||||
entryString += this.optionalEntry('image:caption', image.caption)
|
||||
entryString += this.optionalEntry('image:geo_location', image.geoLocation)
|
||||
entryString += this.optionalEntry('image:title', image.title)
|
||||
@ -103,6 +98,14 @@ export default class Sitemap {
|
||||
}
|
||||
|
||||
private optionalEntry(tag: string, entry?: string) {
|
||||
return entry ? `<${tag}>${entry}</${tag}>` : ''
|
||||
return entry ? `<${tag}>${this.fixText(entry)}</${tag}>` : ''
|
||||
}
|
||||
|
||||
private fixText(txt: string): string {
|
||||
return txt.replace(/&/g, '&')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/</g, '<')
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,14 @@ type ItemToArray<T> = {
|
||||
[P in keyof T]?: Array<T[P]>
|
||||
}
|
||||
|
||||
type BuiltInEvents = {
|
||||
newListener: (eventName: string, listener: (...args: Array<any>) => void) => void
|
||||
removeListener: (eventName: string, listener: (...args: Array<any>) => void) => void
|
||||
all: (eventName: string, ...args: Array<any>) => void
|
||||
}
|
||||
|
||||
export default abstract class Listener<
|
||||
T extends Record<string, (...args: Array<any>) => void> = {
|
||||
newListener: (eventName: string, listener: (...args: Array<any>) => void) => void
|
||||
removeListener: (eventName: string, listener: (...args: Array<any>) => void) => void
|
||||
}
|
||||
T extends Record<string, (...args: Array<any>) => void> = BuiltInEvents
|
||||
> {
|
||||
|
||||
private maxListeners = 10
|
||||
|
@ -11,12 +11,8 @@
|
||||
"license": "MIT",
|
||||
"main": "./dist/Listener.js",
|
||||
"types": "./dist/Listener.d.ts",
|
||||
"devDependencies": {
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "yarn build",
|
||||
"build": "tsc",
|
||||
"test": "tsc --noEmit"
|
||||
"build": "tsc"
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@dzeio/logger",
|
||||
"version": "2.0.4",
|
||||
"version": "3.0.0",
|
||||
"description": "My Personnal Logger",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -18,11 +18,10 @@
|
||||
"@typescript-eslint/eslint-plugin": "^4.5.0",
|
||||
"@typescript-eslint/parser": "^4.5.0",
|
||||
"eslint": "^7.4.0",
|
||||
"parcel": "^1.12.4",
|
||||
"typescript": "^4.0.3"
|
||||
"parcel": "1.12.3"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "yarn build",
|
||||
"prepublishOnly": "npm run build",
|
||||
"build": "parcel build src/index.ts --out-file browser.js --experimental-scope-hoisting && tsc",
|
||||
"test": "ts-node test"
|
||||
}
|
||||
|
@ -23,10 +23,12 @@ export default class Logger implements Console {
|
||||
private static loggers: Array<Logger> = []
|
||||
|
||||
/**
|
||||
* Console memory
|
||||
* (IDK what it is)
|
||||
*Define if you want a timestamp with your logs
|
||||
*
|
||||
* @static
|
||||
* @memberof Logger
|
||||
*/
|
||||
public memory = console.memory
|
||||
public static timestamp = false
|
||||
|
||||
// NodeJS console (will be undefined on )
|
||||
/**
|
||||
@ -367,7 +369,16 @@ export default class Logger implements Console {
|
||||
}
|
||||
const res: Array<any> = [
|
||||
`${this.blackOrWhite('[ ')}${spacers[0]}${blue(prefix)}${spacers[1]}${this.blackOrWhite(' ]')}:`
|
||||
].concat(
|
||||
]
|
||||
|
||||
if (Logger.timestamp) {
|
||||
const now = new Date()
|
||||
const h = now.getHours() >= 10 ? now.getHours().toString() : `0${now.getHours()}`
|
||||
const m = now.getMinutes() >= 10 ? now.getMinutes().toString() : `0${now.getMinutes()}`
|
||||
const s = now.getSeconds() >= 10 ? now.getSeconds().toString() : `0${now.getSeconds()}`
|
||||
res.unshift(`${this.blackOrWhite('<')}${yellow(h)}:${yellow(m)}:${yellow(s)}${this.blackOrWhite('>')}`)
|
||||
}
|
||||
return res.concat(
|
||||
message.map((el) => {
|
||||
if (typeof el === 'object') {
|
||||
return el
|
||||
@ -381,7 +392,6 @@ export default class Logger implements Console {
|
||||
return typeof el !== 'string' ? yellow(el.toString()) : green(el)
|
||||
})
|
||||
)
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { logger as console } from '../src/Logger'
|
||||
import Logger, { logger as console } from '../src/Logger'
|
||||
|
||||
Logger.timestamp = true
|
||||
|
||||
/**
|
||||
* This test file is simple :D
|
||||
|
@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.2.0] - 2021-05-21
|
||||
|
||||
### Added
|
||||
|
||||
- `objectValues` - this does the same thing has objectToArray but make the naming better
|
||||
|
||||
### Changed
|
||||
|
||||
- `objectLoop` and `objectMap` now include an index after the key
|
||||
|
||||
### Deprecated
|
||||
|
||||
- `objectToArray` has been renamed to `objectValues`
|
||||
|
||||
## [1.1.1] - 2021-04-11
|
||||
|
||||
### Added
|
||||
@ -60,7 +74,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- objectEqual Function
|
||||
|
||||
|
||||
[1.1.0]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fobject-util%401.1.0
|
||||
[1.2.0]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fobject-util%401.2.0
|
||||
[1.1.1]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fobject-util%401.1.1
|
||||
[1.0.5]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fobject-util%401.0.5
|
||||
[1.0.4]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fobject-util%401.0.4
|
||||
[1.0.2]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fobject-util%401.0.2
|
||||
|
@ -1,33 +1,22 @@
|
||||
# URL Manager
|
||||
# Object Util
|
||||
|
||||
simple to use yet powerful Urls parser and formatter
|
||||
Utility functions to manipulate an object
|
||||
|
||||
## Usage
|
||||
|
||||
- Import URLManager
|
||||
- Import Object Util
|
||||
|
||||
```typescript
|
||||
import ObjectUtil from '@dzeio/object-util'
|
||||
import { objectMap, ... } from '@dzeio/object-util'
|
||||
// or
|
||||
const ObjectUtil = require('@dzeio/object-util').default
|
||||
|
||||
// or you can import each funcitons individually
|
||||
const {objectMap, ...} = require('@dzeio/object-util')
|
||||
```
|
||||
|
||||
- or import it from the browser
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/@dzeio/object-util@1/dist/browser.js"></script>
|
||||
<!-- It will be available as the same variable -->
|
||||
```
|
||||
|
||||
- Create a new instance
|
||||
|
||||
```typescript
|
||||
// Create a new instance
|
||||
const url = new URLManager() // you can have an URL, URLSearchParams Objects or a string as parameter
|
||||
// or
|
||||
const url = URLManager.fromLocation() // Browser only return a new instance from the current location
|
||||
<!-- each functions will be available as window.{objectMap, ...} or {objectMap, ...}-->
|
||||
```
|
||||
|
||||
- explore !
|
||||
@ -35,14 +24,14 @@ const url = URLManager.fromLocation() // Browser only return a new instance from
|
||||
```typescript
|
||||
|
||||
// Does the same as Array.map
|
||||
objectMap(object, (value, key) => {value + "pouet"})
|
||||
objectMap(object, (value, key) => value + "pouet")
|
||||
|
||||
// does the same as Array.forEach with the addon of stopping if false is returned (like break)
|
||||
// and return if loop was finished or not
|
||||
// does the same as Array.forEach with the addition of stopping if false is returned (like break)
|
||||
// and return if loop was stopped or not
|
||||
objectLoop(object, (value, key) => {})
|
||||
|
||||
// return the values of an object as an array
|
||||
objectToArray(object)
|
||||
objectValues(object)
|
||||
|
||||
// return the keys of an object as an array
|
||||
ObjectKeys(object)
|
||||
@ -61,9 +50,20 @@ objectSort(object, ['key2', 'key1']) // => {key2: value, key1: value, key3: valu
|
||||
cloneObject(object)
|
||||
|
||||
// deeply set an object value while creating empty childs if necessary
|
||||
//ex: this will return {path1, [{path3: 'value'}]} if object is an empty object
|
||||
//ex: this will set {path1, [{path3: 'value'}]} if object is an empty object
|
||||
objectSet(object, ['path1', 0, 'path3'], 'value')
|
||||
|
||||
// deeply compare two objects
|
||||
objectEqual(object, object2)
|
||||
|
||||
// deeply clean an object from undefined, null variables
|
||||
objectClean(object, /* optionnal, defaults */{cleanUndefined: true, cleanNull: false, deep: true})
|
||||
|
||||
// clone (not deeply) an object and remove the keys from the object, 'a' and 'b' for this one
|
||||
objectOmit(object, 'a', 'b')
|
||||
|
||||
// check if a variable is an object
|
||||
isObject(object)
|
||||
```
|
||||
|
||||
_note: with the exception of isObject, every function will throw an error if the object is not an object_
|
||||
|
37
packages/object-util/__tests__/deprecated.test.ts
Normal file
37
packages/object-util/__tests__/deprecated.test.ts
Normal file
@ -0,0 +1,37 @@
|
||||
/// <reference types="jest" />
|
||||
|
||||
import { cloneObject, objectToArray } from "../src/ObjectUtil"
|
||||
|
||||
describe('Object To Array Tests', () => {
|
||||
it('Should Works', () => {
|
||||
const obj = {
|
||||
pouet: 'first',
|
||||
toto: 'second'
|
||||
}
|
||||
expect(objectToArray(obj)).toEqual(['first', 'second'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('Object Clone Tests', () => {
|
||||
it('should clone the object', () => {
|
||||
const obj = {
|
||||
pouet: 'first',
|
||||
toto: 'second'
|
||||
}
|
||||
const clone = cloneObject(obj)
|
||||
expect(clone).toEqual(obj)
|
||||
clone.pouet = 'third'
|
||||
expect(clone).not.toEqual(obj)
|
||||
})
|
||||
|
||||
it('should deeply clone the object', () => {
|
||||
const obj = {
|
||||
pouet: {is: 'first'},
|
||||
toto: 'second'
|
||||
}
|
||||
const clone = cloneObject(obj)
|
||||
expect(clone).toEqual(obj)
|
||||
clone.toto = 'third'
|
||||
expect(clone).not.toEqual(obj)
|
||||
})
|
||||
})
|
@ -1,6 +1,13 @@
|
||||
/// <reference types="jest" />
|
||||
|
||||
import { objectSize, objectToArray, objectMap, objectSort, cloneObject, objectEqual, objectKeys, objectSet, objectLoop, objectClone } from '../src/ObjectUtil'
|
||||
import { objectSize, objectMap, objectSort, objectEqual, objectKeys, objectSet, objectLoop, objectClone, objectValues, objectClean, isObject, objectOmit } from '../src/ObjectUtil'
|
||||
|
||||
describe('Throw if parameter is not an object', () => {
|
||||
it('should works', () => {
|
||||
// @ts-ignore
|
||||
expect(objectKeys).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Object Map tests', () => {
|
||||
it('should works', () => {
|
||||
@ -38,7 +45,7 @@ describe('Object To Array Tests', () => {
|
||||
pouet: 'first',
|
||||
toto: 'second'
|
||||
}
|
||||
expect(objectToArray(obj)).toEqual(['first', 'second'])
|
||||
expect(objectValues(obj)).toEqual(['first', 'second'])
|
||||
})
|
||||
})
|
||||
|
||||
@ -96,6 +103,21 @@ describe('Object sort Tests', () => {
|
||||
d: 'fourth'
|
||||
})
|
||||
})
|
||||
it('should sort by the specified key', () => {
|
||||
const obj = {
|
||||
b: 'first',
|
||||
a: 'second',
|
||||
c: 'zero',
|
||||
d: 'fourth'
|
||||
}
|
||||
// @ts-expect-error
|
||||
expect(objectSort(obj, ['c', 'a', 'e'])).toEqual({
|
||||
c: 'zero',
|
||||
a: 'second',
|
||||
b: 'first',
|
||||
d: 'fourth'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Object Clone Tests', () => {
|
||||
@ -104,7 +126,7 @@ describe('Object Clone Tests', () => {
|
||||
pouet: 'first',
|
||||
toto: 'second'
|
||||
}
|
||||
const clone = cloneObject(obj)
|
||||
const clone = objectClone(obj)
|
||||
expect(clone).toEqual(obj)
|
||||
clone.pouet = 'third'
|
||||
expect(clone).not.toEqual(obj)
|
||||
@ -115,38 +137,26 @@ describe('Object Clone Tests', () => {
|
||||
pouet: {is: 'first'},
|
||||
toto: 'second'
|
||||
}
|
||||
const clone = cloneObject(obj)
|
||||
const clone = objectClone(obj)
|
||||
expect(clone).toEqual(obj)
|
||||
clone.toto = 'third'
|
||||
expect(clone).not.toEqual(obj)
|
||||
})
|
||||
|
||||
it('Should keep types', () => {
|
||||
const obj = {
|
||||
a: [],
|
||||
b: '10',
|
||||
c: 10,
|
||||
d: {},
|
||||
e: [10],
|
||||
f: {g: 10}
|
||||
}
|
||||
it('should clone an Array', () => {
|
||||
const obj = ['one', 'two']
|
||||
const clone = objectClone(obj)
|
||||
expect(clone).toEqual(obj)
|
||||
clone[0] = 'three'
|
||||
expect(clone).not.toEqual(obj)
|
||||
})
|
||||
|
||||
it ('Should clone any types', () => {
|
||||
const obj = {
|
||||
a: [],
|
||||
b: '10',
|
||||
c: 10,
|
||||
d: {},
|
||||
e: [10],
|
||||
f: {g: 10}
|
||||
}
|
||||
objectLoop(obj, (subObj) => {
|
||||
const clone = objectClone(subObj)
|
||||
expect(clone).toEqual(subObj)
|
||||
})
|
||||
it('should deeply clone an Array', () => {
|
||||
const obj = ['one', 'two', ['three']]
|
||||
const clone = objectClone(obj)
|
||||
expect(clone).toEqual(obj)
|
||||
;(clone[2][0] as string) = 'zero'
|
||||
expect(clone).not.toEqual(obj)
|
||||
})
|
||||
})
|
||||
|
||||
@ -221,3 +231,62 @@ describe('Object Equal Test', () => {
|
||||
})).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Object Clean Tests', () => {
|
||||
it('should clean undefined by default', () => {
|
||||
const obj = {a: '', b: null, c: undefined}
|
||||
objectClean(obj)
|
||||
expect(obj).toEqual({a: '', b: null})
|
||||
|
||||
const obj2 = {a: '', b: null, c: undefined}
|
||||
objectClean(obj2, {cleanUndefined: false})
|
||||
expect(obj2).toEqual({a: '', b: null, c: undefined})
|
||||
})
|
||||
it('should clean null when set', () => {
|
||||
const obj = {a: '', b: null, c: undefined}
|
||||
objectClean(obj, {cleanNull: true})
|
||||
expect(obj).toEqual({a: ''})
|
||||
})
|
||||
it('should clean deep by default', () => {
|
||||
const obj = {a: '', b: null, c: undefined, d: {da: '', db: null, dc: undefined}}
|
||||
objectClean(obj)
|
||||
expect(obj).toEqual({a: '', b: null, d: {da: '', db: null}})
|
||||
})
|
||||
it('should clean deep when set', () => {
|
||||
const obj = {a: '', b: null, c: undefined, d: {da: '', db: null, dc: undefined}}
|
||||
objectClean(obj, {deep: true})
|
||||
expect(obj).toEqual({a: '', b: null, d: {da: '', db: null}})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Object Omit Tests', () => {
|
||||
it('should omit certain elements', () => {
|
||||
const obj = {a: 'a', b: 'c', c: 'b'}
|
||||
expect(objectOmit(obj, 'b')).toEqual({a: 'a', c: 'b'})
|
||||
})
|
||||
it('should not care when key to omit is not present', () => {
|
||||
const obj = {a: 'a', b: 'c', c: 'b'}
|
||||
expect(objectOmit(obj, 'b', 'd')).toEqual({a: 'a', c: 'b'})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Is Object Tests', () => {
|
||||
it('null is not an "object"', () => {
|
||||
expect(isObject(null)).toBe(false)
|
||||
})
|
||||
it('boolean is not an "object"', () => {
|
||||
expect(isObject(true)).toBe(false)
|
||||
})
|
||||
it('undefined is not an "object"', () => {
|
||||
expect(isObject(undefined)).toBe(false)
|
||||
})
|
||||
it('string is not an "object"', () => {
|
||||
expect(isObject("null")).toBe(false)
|
||||
})
|
||||
it('number is not an "object"', () => {
|
||||
expect(isObject(0)).toBe(false)
|
||||
})
|
||||
it('object is an "object"', () => {
|
||||
expect(isObject({})).toBe(true)
|
||||
})
|
||||
})
|
||||
|
@ -1,27 +1,25 @@
|
||||
{
|
||||
"name": "@dzeio/object-util",
|
||||
"version": "1.1.1",
|
||||
"description": "some Function to make work on objects easier",
|
||||
"version": "1.4.1",
|
||||
"description": "Utility functions to manipulate an object",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dzeiocom/libs.git",
|
||||
"directory": "packages/object-util"
|
||||
},
|
||||
"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/chai": "^4.2.12",
|
||||
"@types/jest": "^26.0.10",
|
||||
"jest": "^26.4.2",
|
||||
"parcel": "^1.12.4",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.2"
|
||||
"esbuild": "^0.13.2"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "yarn build",
|
||||
"build": "parcel build src/index.ts --out-file browser.js --experimental-scope-hoisting && tsc",
|
||||
"prepublishOnly": "npm run build",
|
||||
"build": "esbuild src/index.ts --outfile=dist/browser.js --minify --bundle --target=es6 && tsc && tsc --project tsconfig.esm.json",
|
||||
"test": "jest --coverage"
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,14 @@
|
||||
* @param obj the object to remap
|
||||
* @param fn the function to run for each key: value pairs
|
||||
*/
|
||||
export function objectMap<T = any, J = any>(obj: Record<string, T>, fn: (value: T, key: string) => J): Array<J> {
|
||||
export function objectMap<T = any, J = any>(
|
||||
obj: Record<string, T>,
|
||||
fn: (value: T, key: string, index: number) => J
|
||||
): Array<J> {
|
||||
mustBeObject(obj)
|
||||
const list: Array<J> = []
|
||||
objectLoop(obj, (item, key) => {
|
||||
list.push(fn(item, key))
|
||||
objectLoop(obj, (item, key, index) => {
|
||||
list.push(fn(item, key, index))
|
||||
})
|
||||
return list
|
||||
}
|
||||
@ -18,10 +22,15 @@ export function objectMap<T = any, J = any>(obj: Record<string, T>, fn: (value:
|
||||
* @param obj the object to loop through
|
||||
* @param fn the function to run for each childs
|
||||
*/
|
||||
export function objectLoop<T = any>(obj: Record<string, T>, fn: (value: T, key: string) => boolean | void): boolean {
|
||||
export function objectLoop<T = any>(
|
||||
obj: Record<string, T>,
|
||||
fn: (value: T, key: string, index: number) => boolean | void
|
||||
): boolean {
|
||||
mustBeObject(obj)
|
||||
const keys = objectKeys(obj)
|
||||
for (const key of keys) {
|
||||
const stop = fn(obj[key], key)
|
||||
for (let index = 0; index < keys.length; index++) {
|
||||
const key = keys[index]
|
||||
const stop = fn(obj[key], key, index)
|
||||
if (stop === false) {
|
||||
return false
|
||||
}
|
||||
@ -30,18 +39,28 @@ export function objectLoop<T = any>(obj: Record<string, T>, fn: (value: T, key:
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform an object to an array removing the keys
|
||||
* Transform an object to an array of its values
|
||||
* @param obj the object to transform
|
||||
*/
|
||||
export function objectToArray<T = any>(obj: Record<string, T>): Array<T> {
|
||||
export function objectValues<T = any>(obj: Record<string, T>): Array<T> {
|
||||
mustBeObject(obj)
|
||||
return Object.values(obj)
|
||||
}
|
||||
|
||||
/**
|
||||
* return the keys of th object
|
||||
* @deprecated use `objectValues`
|
||||
*/
|
||||
export function objectToArray<T = any>(obj: Record<string, T>): Array<T> {
|
||||
mustBeObject(obj)
|
||||
return objectValues(obj)
|
||||
}
|
||||
|
||||
/**
|
||||
* return the keys of the object
|
||||
* @param obj the object
|
||||
*/
|
||||
export function objectKeys(obj: Record<string, any>): Array<string> {
|
||||
mustBeObject(obj)
|
||||
return Object.keys(obj)
|
||||
}
|
||||
|
||||
@ -64,6 +83,7 @@ export function objectSort<T extends Record<string, any> = Record<string, any>>(
|
||||
obj: T,
|
||||
fn?: Array<keyof T> | ((a: keyof T, b: keyof T) => number)
|
||||
): T {
|
||||
mustBeObject(obj)
|
||||
const ordered: any = {}
|
||||
let sortedKeys: Array<keyof T> = []
|
||||
if (Array.isArray(fn)) {
|
||||
@ -78,9 +98,7 @@ export function objectSort<T extends Record<string, any> = Record<string, any>>(
|
||||
}
|
||||
|
||||
/**
|
||||
* Deeply clone an object
|
||||
* @param obj the object to clone
|
||||
* @deprecated Replace with objectClone
|
||||
* @deprecated use `objectClone`
|
||||
*/
|
||||
export function cloneObject<T = Record<string, any>>(obj: T): T {
|
||||
return objectClone(obj)
|
||||
@ -89,16 +107,18 @@ export function cloneObject<T = Record<string, any>>(obj: T): T {
|
||||
/**
|
||||
* Deeply clone an object
|
||||
* @param obj the object to clone
|
||||
* @returns the clone of the object
|
||||
*/
|
||||
export function objectClone<T = Record<string, any>>(obj: T): T {
|
||||
if (typeof obj !== 'object') {
|
||||
const v = obj
|
||||
return v
|
||||
}
|
||||
mustBeObject(obj)
|
||||
if (Array.isArray(obj)) {
|
||||
const arr: Array<any> = []
|
||||
for (const item of obj) {
|
||||
arr.push(objectClone(item))
|
||||
if (isObject(item)) {
|
||||
arr.push(objectClone(item))
|
||||
} else {
|
||||
arr.push(item)
|
||||
}
|
||||
}
|
||||
return arr as unknown as T
|
||||
}
|
||||
@ -124,6 +144,7 @@ export function objectClone<T = Record<string, any>>(obj: T): T {
|
||||
* @param value the value
|
||||
*/
|
||||
export function objectSet(obj: Record<string, any>, path: Array<string | number>, value: any): void {
|
||||
mustBeObject(obj)
|
||||
let pointer = obj
|
||||
for (let index = 0; index < path.length; index++) {
|
||||
const key = path[index]
|
||||
@ -155,6 +176,8 @@ export function objectSet(obj: Record<string, any>, path: Array<string | number>
|
||||
* @param y the second object
|
||||
*/
|
||||
export function objectEqual(x: Record<string, any>, y: Record<string, any>): boolean {
|
||||
mustBeObject(x)
|
||||
mustBeObject(y)
|
||||
if (objectSize(x) !== objectSize(y)) {
|
||||
return false
|
||||
}
|
||||
@ -174,6 +197,70 @@ export function objectEqual(x: Record<string, any>, y: Record<string, any>): boo
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* deeply clean an object from having {key: undefined}
|
||||
* @param obj the object to clean
|
||||
* @param {boolean?} options.cleanUndefined (default: true) clean undefined from the object
|
||||
* @param {boolean?} options.cleanNull clean null frrom the object
|
||||
* @param {boolean?} options.deep (default: true) deeply clean the object
|
||||
*/
|
||||
export function objectClean(obj: Record<string, any>, options?: {cleanUndefined?: boolean, cleanNull?: boolean, deep?: boolean}): void {
|
||||
mustBeObject(obj)
|
||||
objectLoop(obj, (item, key) => {
|
||||
if ((typeof options?.cleanUndefined === 'undefined' || options?.cleanUndefined) && item === undefined) {
|
||||
delete obj[key]
|
||||
}
|
||||
|
||||
if (options?.cleanNull && item === null) {
|
||||
delete obj[key]
|
||||
}
|
||||
|
||||
if ((typeof options?.deep === 'undefined' || options?.deep) && isObject(item)) {
|
||||
return objectClean(item, options)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* clone the object (not deeply) and emit some keys from cloning
|
||||
* @param obj the object to clone
|
||||
* @param keys the keys to emit
|
||||
* @returns the cloned object
|
||||
*/
|
||||
export function objectOmit<T extends Record<string, any> = Record<string, any>>(obj: T, ...keys: Array<string>): T {
|
||||
const cloned = obj
|
||||
for (const key of keys) {
|
||||
if (key in cloned) {
|
||||
delete cloned[key]
|
||||
}
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
/**
|
||||
* return if an item is an object
|
||||
* @param item the item to check
|
||||
* @returns {boolean} the item is an object
|
||||
*/
|
||||
export function isObject(item: any): item is Record<any, any> {
|
||||
return typeof item === 'object' && item !== null
|
||||
}
|
||||
|
||||
/**
|
||||
* Strict check for an object
|
||||
*
|
||||
* @internal
|
||||
* @param item the item to check
|
||||
* @returns {boolean} throw an error is the item is not an item
|
||||
*/
|
||||
function mustBeObject(item: any): item is Record<any, any> {
|
||||
if (isObject(item)) {
|
||||
return true
|
||||
} else {
|
||||
throw new Error("Input is not an object!")
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
objectMap,
|
||||
objectLoop,
|
||||
@ -184,5 +271,8 @@ export default {
|
||||
cloneObject,
|
||||
objectClone,
|
||||
objectSet,
|
||||
objectEqual
|
||||
objectEqual,
|
||||
objectClean,
|
||||
objectOmit,
|
||||
isObject
|
||||
}
|
||||
|
11
packages/object-util/tsconfig.esm.json
Normal file
11
packages/object-util/tsconfig.esm.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "../config/tsconfig.esm.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist/esm",
|
||||
"declaration": false,
|
||||
"declarationDir": null
|
||||
},
|
||||
"files": [
|
||||
"src/ObjectUtil.ts"
|
||||
]
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist"
|
||||
"outDir": "dist/cjs",
|
||||
"declarationDir": "dist/types"
|
||||
},
|
||||
"files": [
|
||||
"src/ObjectUtil.ts"
|
||||
|
@ -11,12 +11,8 @@
|
||||
"license": "MIT",
|
||||
"main": "./dist/Queue.js",
|
||||
"types": "./dist/Queue.d.ts",
|
||||
"devDependencies": {
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "yarn build",
|
||||
"build": "tsc",
|
||||
"test": "tsc --noEmit"
|
||||
"build": "tsc"
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@dzeio/url-manager",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.6",
|
||||
"description": "A simple to use yet complete Urls parser and serializer",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -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",
|
||||
@ -21,17 +22,14 @@
|
||||
"serializer"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.2.12",
|
||||
"@types/jest": "^26.0.10",
|
||||
"jest": "^26.4.2",
|
||||
"parcel": "^1.12.4",
|
||||
"ts-jest": "^26.4.4",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.2"
|
||||
"esbuild": "^0.13.2"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublishOnly": "yarn build",
|
||||
"build": "parcel build src/index.ts --out-file browser.js --experimental-scope-hoisting && tsc",
|
||||
"prepublishOnly": "npm run build",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { objectLoop } from '@dzeio/object-util'
|
||||
|
||||
/**
|
||||
* Easy URLs manager
|
||||
*/
|
||||
@ -331,13 +333,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}`
|
||||
}
|
||||
@ -345,24 +343,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++) {
|
||||
@ -372,7 +363,7 @@ export default class URLManager {
|
||||
}
|
||||
result += `${key}=${val}`
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (!result) {
|
||||
return undefined
|
||||
|
11
packages/url-manager/tsconfig.esm.json
Normal file
11
packages/url-manager/tsconfig.esm.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "../config/tsconfig.esm.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist/esm",
|
||||
"declaration": false,
|
||||
"declarationDir": null
|
||||
},
|
||||
"files": [
|
||||
"src/URLManager.ts"
|
||||
]
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist"
|
||||
"outDir": "dist/cjs",
|
||||
"declarationDir": "dist/types"
|
||||
},
|
||||
"files": [
|
||||
"src/URLManager.ts"
|
||||
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base",
|
||||
":preserveSemverRanges"
|
||||
]
|
||||
}
|
@ -1,26 +1,7 @@
|
||||
{
|
||||
"extends": "./packages/config/tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"allowUnreachableCode": false,
|
||||
"allowUnusedLabels": false,
|
||||
"declaration": true,
|
||||
"declarationMap": false,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitReturns": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"pretty": true,
|
||||
"skipLibCheck": true,
|
||||
"sourceMap": false,
|
||||
"strict": true,
|
||||
"target": "ES2017" // Follow NodeJS oldest supported LTS and compare with https://node.green
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user