1
0
mirror of https://github.com/dzeiocom/libs.git synced 2025-04-22 02:42:13 +00:00

Merge branch 'master' of github.com:dzeiocom/libs

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2021-04-11 00:37:50 +02:00
commit acd5b781cf
Signed by: Florian Bouillon
GPG Key ID: 50BD648F12C86AB6
20 changed files with 1107 additions and 892 deletions

View File

@ -32,4 +32,4 @@ jobs:
- uses: codecov/codecov-action@v1.0.13
with:
# Comma-separated list of files to upload
files: ./packages/url-manager/coverage/coverage-final.json,./packages/object-util/coverage/coverage-final.json # optional
files: ./packages/url-manager/coverage/coverage-final.json,./packages/object-util/coverage/coverage-final.json,./packages/easy-sitemap/coverage/coverage-final.json # optional

View File

@ -6,3 +6,4 @@ src
tsconfig.*
webpack.config.js
yarn-error.log
.cache

View File

@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [1.3.0] - 2021-02-08
### Added
- function to add child .appendChild
- Autocompletion for .style
## [1.2.3] - 2020-12-17
### Fixed
- Setting .text to '' dont set text to nothing #6
- t.data('test', null) return the value of test #7
## [1.2.2] - 2020-10-20
### Changed
@ -38,6 +52,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added base Manager
[1.3.0]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fdom-manager%401.3.0
[1.2.2]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fdom-manager%401.2.3
[1.2.2]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fdom-manager%401.2.2
[1.2.1]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fdom-manager%401.2.1
[1.2.0]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Fdom-manager%401.2.0

View File

@ -1,6 +1,6 @@
{
"name": "@dzeio/dom-manager",
"version": "1.2.3",
"version": "1.3.0",
"description": "JQuery but lighter",
"repository": {
"type": "git",

View File

@ -157,13 +157,15 @@ export default class DOMElement<T extends HTMLElement = HTMLElement> {
public data(key: string): string | null
public data(key: string, value: string | null): this
public data(key: string, value?: string | null): this | string | null {
// @ts-ignore
// @ts-ignore Ignore because data-elements aren't valid attrs for an HTMLElement
return this.attr(`data-${key}`, value)
}
public style(key: string, value?: string | number) {
public style(key: keyof CSSStyleDeclaration): CSSStyleDeclaration[typeof key]
public style(key: keyof CSSStyleDeclaration, value: CSSStyleDeclaration[typeof key]): this
public style(key: keyof CSSStyleDeclaration, value?: CSSStyleDeclaration[typeof key]) {
if (typeof value === 'undefined') {
return this.item.style[key as any]
return this.item.style[key]
}
this.item.style[key as any] = value as string
return this
@ -201,4 +203,11 @@ export default class DOMElement<T extends HTMLElement = HTMLElement> {
return this.placeAsChildOf(item)
}
}
public appendChild(item: DOMElement | HTMLElement) {
if (item instanceof DOMElement) {
item = item.item
}
this.item.appendChild(item)
}
}

View File

@ -1,11 +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\\"><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\\" 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\\"><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 return a basic sitemap 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\"><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\\" 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 sitemap 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\"><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\\" 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 an empty sitemap 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\"></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[`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 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 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 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>"`;

View File

@ -39,5 +39,58 @@ describe('Basic Sitemap Tests', () => {
})
expect(sitemap.build()).toMatchSnapshot()
})
})
describe('image:image tests', () => {
it('should build corretcly with single image:image', () => {
const sitemap = new Sitemap('https://www.example.com')
sitemap.addEntry('/path', {
images: [{
location: '/test',
geoLocation: 'Nantes',
title: 'Title',
caption: 'Image Caption',
license: 'Example license url'
}]
})
expect(sitemap.build()).toMatchSnapshot()
})
it('should skip image:image if no location is set', () => {
const sitemap = new Sitemap('https://www.example.com')
sitemap.addEntry('/path', {
// @ts-expect-error
images: [{
geoLocation: 'Nantes',
}]
})
expect(sitemap.build()).toMatchSnapshot()
})
it('should skip image:image if there is more than 1000 images', () => {
const sitemap = new Sitemap('https://www.example.com')
sitemap.addEntry('/path', {
images: Array.from(new Array(1001)).map(() => ({
location: '/test',
}))
})
expect(sitemap.build()).toMatchSnapshot()
})
it('should build corretcly with multiple image:image', () => {
const sitemap = new Sitemap('https://www.example.com')
sitemap.addEntry('/path', {
images: [{
location: '/test',
geoLocation: 'Nantes',
title: 'Title',
caption: 'Image Caption',
license: 'Example license url'
}, {
location: '/test-2',
geoLocation: 'Paris',
title: 'Title2',
caption: 'Image Caption2',
license: 'Example license url'
}]
})
expect(sitemap.build()).toMatchSnapshot()
})
})

View File

@ -1,12 +1,13 @@
{
"name": "easy-sitemap",
"version": "1.0.0",
"version": "1.1.0",
"description": "A very easy sitemap maker library",
"repository": {
"type": "git",
"url": "https://github.com/dzeiocom/libs.git",
"directory": "packages/easy-sitemap"
},
"homepage": "https://github.com/dzeiocom/libs/tree/master/packages/easy-sitemap#readme",
"author": "Aviortheking",
"license": "MIT",
"main": "./dist/Sitemap.js",
@ -25,6 +26,11 @@
},
"keywords": [
"sitemap",
"sitemap.xml"
"sitemap.xml",
"xml",
"easy-sitemap",
"generator",
"SEO",
"search-engine"
]
}

View File

@ -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">'
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">'
public constructor(
private domain: string, private options?: {
@ -17,10 +17,22 @@ export default class Sitemap {
}
}
/**
* Add a new Entry into the Sitemap
* @param path the url path
* @param options aditional datas you want in the sitemap for the `path`
*/
public addEntry(path: string, options?: {
changefreq?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never'
lastmod?: Date
priority?: 1 | 0.9 | 0.8 | 0.7 | 0.6 | 0.5 | 0.4 | 0.3 | 0.2 | 0.1 | 0
images?: Array<{
location: string
caption?: string
geoLocation?: string
title?: string
license?: string
}>
}) {
let entryString = '<url>'
@ -35,7 +47,7 @@ export default class Sitemap {
if (options) {
if (options.changefreq) {
if (!Sitemap.allowedChangefreq.includes(options.changefreq)) {
console.warn(`changefreq is not one of the allowed words (${options.changefreq})\nChangeFreq won't be added`)
console.warn(`changefreq is not valid (${options.changefreq})`)
} else {
entryString += `<changefreq>${options.changefreq}</changefreq>`
}
@ -47,7 +59,26 @@ export default class Sitemap {
if (options.priority <= 1 && options.priority >= 0 && options.priority.toString().length <= 3) {
entryString += `<priority>${options.priority}</priority>`
} else {
console.warn(`Priority is not between 0 and 1 and only containing one decimal (${options.priority})\nPriority won't be added`)
console.warn(`Priority is not valid (${options.priority})`)
}
}
if (options.images) {
if (options.images.length > 1000) {
console.warn('image cant have more than 1000 images, skipping')
} else {
for (const image of options.images) {
if (!image.location) {
console.warn('Images need a Location')
continue
}
entryString += '<image:image>'
entryString += `<image:loc>${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)
entryString += this.optionalEntry('image:license', image.license)
entryString += '</image:image>'
}
}
}
}
@ -59,6 +90,9 @@ export default class Sitemap {
}
}
/**
* Finish the Sitemap
*/
public build(): string {
if (this.options?.response) {
this.options.response.write('</urlset>')
@ -67,4 +101,8 @@ export default class Sitemap {
}
return this.datas + '</urlset>'
}
private optionalEntry(tag: string, entry?: string) {
return entry ? `<${tag}>${entry}</${tag}>` : ''
}
}

View File

@ -1,6 +1,6 @@
{
"name": "@dzeio/listener",
"version": "1.0.0",
"version": "1.0.1",
"description": "A NodeJS Listener implementation",
"repository": {
"type": "git",

View File

@ -5,4 +5,5 @@ test
.eslintrc.js
.gitignore
webpack.config.js
tsconfig.*
tsconfig.*
.cache

View File

@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [2.0.4] - 2021-02-08
### Removed
- initConsole Function as it break the Console object (#17)
## [2.0.2] - 2020-10-20
### Changed
@ -60,6 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Basic Logger with log and urgent functions
[2.0.3]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Flogger%402.0.3
[2.0.2]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Flogger%402.0.2
[2.0.1]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Flogger%402.0.1
[2.0.0]: https://github.com/dzeiocom/libs/releases/tag/%40dzeio%2Flogger%402.0.0

View File

@ -1,6 +1,6 @@
{
"name": "@dzeio/logger",
"version": "2.0.2",
"version": "2.0.4",
"description": "My Personnal Logger",
"repository": {
"type": "git",

View File

@ -9,6 +9,8 @@ import Logger from './Logger'
// @ts-expect-error
window.Logger = Logger
// @ts-expect-error
window.logger = new Logger('Console')
// @ts-expect-error
window.initConsole = function() {
window.console = new Logger('Console')
console.log('// @deprecated Now use window.logger to get the correct logger')
}

View File

@ -11,3 +11,4 @@ yarn-error.log
coverage
__tests__
jest.config.js
.cache

View File

@ -1,6 +1,6 @@
/// <reference types="jest" />
import { objectSize, objectToArray, objectMap, objectSort, cloneObject, objectEqual, objectKeys, objectSet, objectLoop } from '../src/ObjectUtil'
import { objectSize, objectToArray, objectMap, objectSort, cloneObject, objectEqual, objectKeys, objectSet, objectLoop, objectClone } from '../src/ObjectUtil'
describe('Object Map tests', () => {
it('should works', () => {
@ -120,6 +120,34 @@ describe('Object Clone Tests', () => {
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}
}
const clone = objectClone(obj)
expect(clone).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)
})
})
})
describe('Object Set Tests', () => {
@ -185,4 +213,11 @@ describe('Object Equal Test', () => {
it('should not be differently equal', () => {
expect(objectEqual({pouet: true}, {})).toBe(false)
})
it('should handle every types', () => {
expect(objectEqual({
a: [10, {b: 'c'}], d: '1', e: 2, f: true, g: null, h: undefined
}, {
a: [10, {b: 'c'}], d: '1', e: 2, f: true, g: null, h: undefined
})).toBe(true)
})
})

View File

@ -19,10 +19,8 @@ export function objectMap<T = any, J = any>(obj: Record<string, T>, fn: (value:
* @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 {
for (const key in obj) {
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
continue
}
const keys = objectKeys(obj)
for (const key of keys) {
const stop = fn(obj[key], key)
if (stop === false) {
return false
@ -93,6 +91,17 @@ export function cloneObject<T = Record<string, any>>(obj: T): T {
* @param obj the object to clone
*/
export function objectClone<T = Record<string, any>>(obj: T): T {
if (typeof obj !== 'object') {
const v = obj
return v
}
if (Array.isArray(obj)) {
const arr: Array<any> = []
for (const item of obj) {
arr.push(objectClone(item))
}
return arr as unknown as T
}
const clone: Partial<T> = {}
objectLoop(obj, (value, key) => {
if (typeof value === 'object' && value != null) {

View File

@ -11,3 +11,4 @@ yarn-error.log
coverage
__tests__
jest.config.js
.cache

View File

@ -1,6 +1,6 @@
{
"name": "@dzeio/url-manager",
"version": "1.0.4",
"version": "1.0.5",
"description": "Manage URL",
"repository": "https://github.com/dzeiocom/libs.git",
"homepage": "https://github.com/dzeiocom/libs/tree/master/packages/url-manager#readme",

1760
yarn.lock

File diff suppressed because it is too large Load Diff