@symbo.ls/utils 2.11.73 → 2.11.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/index.js +6 -3
- package/src/navigation.js +0 -66
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/utils",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.84",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"author": "symbo.ls",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@domql/utils": "latest"
|
|
9
9
|
},
|
|
10
|
-
"gitHead": "
|
|
10
|
+
"gitHead": "51cf490aa9b1d763ed5befb62de7412b44b28061"
|
|
11
11
|
}
|
package/src/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import { isString, isObject, isArray } from '@domql/utils'
|
|
4
4
|
|
|
5
|
-
export * from './navigation'
|
|
6
5
|
export * from './scaling'
|
|
7
6
|
export * from './date'
|
|
8
7
|
|
|
@@ -30,8 +29,12 @@ export const toTitleCase = str => str.replace(
|
|
|
30
29
|
)
|
|
31
30
|
|
|
32
31
|
export const toDashCase = val => val
|
|
33
|
-
.replace(/[
|
|
34
|
-
.
|
|
32
|
+
.replace(/[^a-zA-Z0-9]/g, ' ') // Replace non-alphanumeric characters with spaces
|
|
33
|
+
.trim() // Remove leading and trailing spaces
|
|
34
|
+
.toLowerCase() // Convert to lowercase
|
|
35
|
+
.replace(/\s+/g, '-') // Replace spaces with dashes
|
|
36
|
+
.replace(/-+/g, '-') // Replace consecutive dashes with a single dash
|
|
37
|
+
.replace(/^-|-$/g, '') // Remove leading and trailing dashes
|
|
35
38
|
|
|
36
39
|
export const toDescriptionCase = str => {
|
|
37
40
|
const result = str.replace(/([A-Z])/g, ' $1')
|
package/src/navigation.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
export const filterHrefs = (sitemap) => {
|
|
4
|
-
return Object.values(sitemap)
|
|
5
|
-
.map(({ href, sub_links }) => // eslint-disable-line
|
|
6
|
-
[href, sub_links.map(({ href }) => href) // eslint-disable-line
|
|
7
|
-
.filter(v => v.indexOf('#') === -1)]
|
|
8
|
-
.filter(v => v.length > 0)
|
|
9
|
-
)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const findCurrentIndex = (sitemap) => { // eslint-disable-line
|
|
13
|
-
const { pathname } = window.location
|
|
14
|
-
const hrefArray = filterHrefs(sitemap)
|
|
15
|
-
let index
|
|
16
|
-
|
|
17
|
-
hrefArray.forEach((v, k) => {
|
|
18
|
-
if (v[0] === pathname) index = k
|
|
19
|
-
if (v[1] && v[1].indexOf(pathname) > -1) {
|
|
20
|
-
const i = v[1].indexOf(pathname)
|
|
21
|
-
index = `${k}.${i}`
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
return { active: index }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/** Parses sitemap and detects current, active, and previous pages from current url path */
|
|
29
|
-
export const setPaginationNames = (sitemap) => {
|
|
30
|
-
const { pathname } = window.location
|
|
31
|
-
const hrefArray = filterHrefs(sitemap)
|
|
32
|
-
const state = {}
|
|
33
|
-
|
|
34
|
-
hrefArray.forEach((v, k) => {
|
|
35
|
-
const categoryRoute = v[0]
|
|
36
|
-
const subcategoryRoutes = v[1]
|
|
37
|
-
const previousCat = sitemap[k - 1]
|
|
38
|
-
const activeCat = sitemap[k]
|
|
39
|
-
const nextCat = sitemap[k + 1]
|
|
40
|
-
|
|
41
|
-
const isRootCategory = categoryRoute === pathname
|
|
42
|
-
const isSubcategory = subcategoryRoutes && subcategoryRoutes.indexOf(pathname) > -1
|
|
43
|
-
|
|
44
|
-
if (isRootCategory) {
|
|
45
|
-
const previousSubcat = hrefArray[k - 1] && hrefArray[k - 1][1] && previousCat.sub_links[previousCat.sub_links.length - 1]
|
|
46
|
-
const nextSubcat = subcategoryRoutes && activeCat.sub_links[0]
|
|
47
|
-
|
|
48
|
-
state.previous = previousSubcat || previousCat
|
|
49
|
-
state.active = activeCat
|
|
50
|
-
state.next = nextSubcat || nextCat
|
|
51
|
-
state.moveOn = nextSubcat && nextCat
|
|
52
|
-
} else if (isSubcategory) {
|
|
53
|
-
const i = subcategoryRoutes.indexOf(pathname)
|
|
54
|
-
const activeSubcat = activeCat.sub_links[i]
|
|
55
|
-
const previousSubcat = subcategoryRoutes[i - 1] && activeCat.sub_links[i - 1]
|
|
56
|
-
const nextSubcat = subcategoryRoutes[i + 1] && activeCat.sub_links[i + 1]
|
|
57
|
-
|
|
58
|
-
state.previous = previousSubcat || activeCat
|
|
59
|
-
state.active = activeSubcat
|
|
60
|
-
state.next = nextSubcat || nextCat
|
|
61
|
-
state.moveOn = nextSubcat && nextCat
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
return state
|
|
66
|
-
}
|