aneka 0.1.5 → 0.2.1
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/CHANGES.md +6 -0
- package/LICENSE +21 -21
- package/README.md +0 -0
- package/index.js +34 -32
- package/package.json +29 -29
- package/src/arrange-array.js +18 -18
- package/src/defaults-deep.js +14 -14
- package/src/delay.js +10 -10
- package/src/extract-text.js +15 -15
- package/src/get-index.js +6 -0
- package/src/get-key-by-value.js +5 -5
- package/src/includes.js +11 -11
- package/src/is-class.js +7 -7
- package/src/is-set.js +5 -5
- package/src/log.js +19 -19
- package/src/paginate.js +29 -29
- package/src/pascal-case.js +8 -8
- package/src/round.js +6 -6
- package/src/sec-to-hms.js +20 -20
- package/src/titleize.js +26 -26
package/CHANGES.md
ADDED
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Ardhi Lukianto
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Ardhi Lukianto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
File without changes
|
package/index.js
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
import arrangeArray from './src/arrange-array.js'
|
|
2
|
-
import defaultsDeep from './src/defaults-deep.js'
|
|
3
|
-
import delay from './src/delay.js'
|
|
4
|
-
import extractText from './src/extract-text.js'
|
|
5
|
-
import getKeyByValue from './src/get-key-by-value.js'
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
import arrangeArray from './src/arrange-array.js'
|
|
2
|
+
import defaultsDeep from './src/defaults-deep.js'
|
|
3
|
+
import delay from './src/delay.js'
|
|
4
|
+
import extractText from './src/extract-text.js'
|
|
5
|
+
import getKeyByValue from './src/get-key-by-value.js'
|
|
6
|
+
import getIndex from './src/get-index.js'
|
|
7
|
+
import includes from './src/includes.js'
|
|
8
|
+
import isClass from './src/is-class.js'
|
|
9
|
+
import isSet from './src/is-set.js'
|
|
10
|
+
import { log, logError } from './src/log.js'
|
|
11
|
+
import paginate from './src/paginate.js'
|
|
12
|
+
import pascalCase from './src/pascal-case.js'
|
|
13
|
+
import round from './src/round.js'
|
|
14
|
+
import secToHms from './src/sec-to-hms.js'
|
|
15
|
+
import titleize from './src/titleize.js'
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
arrangeArray,
|
|
19
|
+
defaultsDeep,
|
|
20
|
+
delay,
|
|
21
|
+
extractText,
|
|
22
|
+
getIndex,
|
|
23
|
+
getKeyByValue,
|
|
24
|
+
includes,
|
|
25
|
+
isClass,
|
|
26
|
+
isSet,
|
|
27
|
+
log,
|
|
28
|
+
logError,
|
|
29
|
+
paginate,
|
|
30
|
+
pascalCase,
|
|
31
|
+
round,
|
|
32
|
+
secToHms,
|
|
33
|
+
titleize
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "aneka",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"type": "module",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "jest"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+https://github.com/ardhi/aneka.git"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"aneka",
|
|
16
|
-
"miscellaneous",
|
|
17
|
-
"functions"
|
|
18
|
-
],
|
|
19
|
-
"author": "Ardhi Lukianto <ardhi.lukianto@gmail.com>",
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"bugs": {
|
|
22
|
-
"url": "https://github.com/ardhi/aneka/issues"
|
|
23
|
-
},
|
|
24
|
-
"homepage": "https://github.com/ardhi/aneka#readme",
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"lodash-es": "^4.17.21",
|
|
27
|
-
"sprintf-js": "^1.1.3"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "aneka",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Some usefull function helper for daily use",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jest"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/ardhi/aneka.git"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"aneka",
|
|
16
|
+
"miscellaneous",
|
|
17
|
+
"functions"
|
|
18
|
+
],
|
|
19
|
+
"author": "Ardhi Lukianto <ardhi.lukianto@gmail.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/ardhi/aneka/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/ardhi/aneka#readme",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"lodash-es": "^4.17.21",
|
|
27
|
+
"sprintf-js": "^1.1.3"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/arrange-array.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import trim from 'lodash-es/trim.js'
|
|
2
|
-
|
|
3
|
-
function arrangeArray (inputs = [], trimItem = true) {
|
|
4
|
-
const first = []
|
|
5
|
-
const last = []
|
|
6
|
-
|
|
7
|
-
const items = inputs.filter(item => {
|
|
8
|
-
if (trimItem) item = trim(item)
|
|
9
|
-
if (item[0] === '^') first.push(item.slice(1))
|
|
10
|
-
else if (item[0] === '$') last.push(item.slice(1))
|
|
11
|
-
return !['^', '$'].includes(item[0])
|
|
12
|
-
})
|
|
13
|
-
items.unshift(...first)
|
|
14
|
-
items.push(...last)
|
|
15
|
-
return items
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default arrangeArray
|
|
1
|
+
import trim from 'lodash-es/trim.js'
|
|
2
|
+
|
|
3
|
+
function arrangeArray (inputs = [], trimItem = true) {
|
|
4
|
+
const first = []
|
|
5
|
+
const last = []
|
|
6
|
+
|
|
7
|
+
const items = inputs.filter(item => {
|
|
8
|
+
if (trimItem) item = trim(item)
|
|
9
|
+
if (item[0] === '^') first.push(item.slice(1))
|
|
10
|
+
else if (item[0] === '$') last.push(item.slice(1))
|
|
11
|
+
return !['^', '$'].includes(item[0])
|
|
12
|
+
})
|
|
13
|
+
items.unshift(...first)
|
|
14
|
+
items.push(...last)
|
|
15
|
+
return items
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default arrangeArray
|
package/src/defaults-deep.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import mergeWith from 'lodash-es/mergeWith.js'
|
|
2
|
-
import isArray from 'lodash-es/isArray.js'
|
|
3
|
-
|
|
4
|
-
function defaultsDeep (...args) {
|
|
5
|
-
const output = {}
|
|
6
|
-
args.reverse().forEach(function (item) {
|
|
7
|
-
mergeWith(output, item, function (objectValue, sourceValue) {
|
|
8
|
-
return isArray(sourceValue) ? sourceValue : undefined
|
|
9
|
-
})
|
|
10
|
-
})
|
|
11
|
-
return output
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default defaultsDeep
|
|
1
|
+
import mergeWith from 'lodash-es/mergeWith.js'
|
|
2
|
+
import isArray from 'lodash-es/isArray.js'
|
|
3
|
+
|
|
4
|
+
function defaultsDeep (...args) {
|
|
5
|
+
const output = {}
|
|
6
|
+
args.reverse().forEach(function (item) {
|
|
7
|
+
mergeWith(output, item, function (objectValue, sourceValue) {
|
|
8
|
+
return isArray(sourceValue) ? sourceValue : undefined
|
|
9
|
+
})
|
|
10
|
+
})
|
|
11
|
+
return output
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default defaultsDeep
|
package/src/delay.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
function delay (ms = 1000) {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
const timer = setTimeout(() => {
|
|
4
|
-
if (timer) clearTimeout(timer)
|
|
5
|
-
resolve()
|
|
6
|
-
}, ms)
|
|
7
|
-
})
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default delay
|
|
1
|
+
function delay (ms = 1000) {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
const timer = setTimeout(() => {
|
|
4
|
+
if (timer) clearTimeout(timer)
|
|
5
|
+
resolve()
|
|
6
|
+
}, ms)
|
|
7
|
+
})
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default delay
|
package/src/extract-text.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
function extractText (text, patternStart, patternEnd) {
|
|
2
|
-
let result = ''
|
|
3
|
-
const open = text.indexOf(patternStart)
|
|
4
|
-
if (open > -1) {
|
|
5
|
-
text = text.slice(open + patternStart.length)
|
|
6
|
-
const close = text.indexOf(patternEnd)
|
|
7
|
-
if (close > -1) {
|
|
8
|
-
result = text.slice(0, close)
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
const pattern = `${patternStart}${result}${patternEnd}`
|
|
12
|
-
return { result, pattern }
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default extractText
|
|
1
|
+
function extractText (text, patternStart, patternEnd) {
|
|
2
|
+
let result = ''
|
|
3
|
+
const open = text.indexOf(patternStart)
|
|
4
|
+
if (open > -1) {
|
|
5
|
+
text = text.slice(open + patternStart.length)
|
|
6
|
+
const close = text.indexOf(patternEnd)
|
|
7
|
+
if (close > -1) {
|
|
8
|
+
result = text.slice(0, close)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const pattern = `${patternStart}${result}${patternEnd}`
|
|
12
|
+
return { result, pattern }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default extractText
|
package/src/get-index.js
ADDED
package/src/get-key-by-value.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function getKeyByValue (object, value) {
|
|
2
|
-
return Object.keys(object).find(key => object[key] === value)
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export default getKeyByValue
|
|
1
|
+
function getKeyByValue (object, value) {
|
|
2
|
+
return Object.keys(object).find(key => object[key] === value)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export default getKeyByValue
|
package/src/includes.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
function includes (matcher = [], array = []) {
|
|
2
|
-
if (typeof matcher === 'string') matcher = [matcher]
|
|
3
|
-
let found = false
|
|
4
|
-
for (const m of matcher) {
|
|
5
|
-
found = array.includes(m)
|
|
6
|
-
if (found) break
|
|
7
|
-
}
|
|
8
|
-
return found
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default includes
|
|
1
|
+
function includes (matcher = [], array = []) {
|
|
2
|
+
if (typeof matcher === 'string') matcher = [matcher]
|
|
3
|
+
let found = false
|
|
4
|
+
for (const m of matcher) {
|
|
5
|
+
found = array.includes(m)
|
|
6
|
+
if (found) break
|
|
7
|
+
}
|
|
8
|
+
return found
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default includes
|
package/src/is-class.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
function isClass (item) {
|
|
2
|
-
return typeof item === 'function' &&
|
|
3
|
-
Object.prototype.hasOwnProperty.call(item, 'prototype') &&
|
|
4
|
-
!Object.prototype.hasOwnProperty.call(item, 'arguments')
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default isClass
|
|
1
|
+
function isClass (item) {
|
|
2
|
+
return typeof item === 'function' &&
|
|
3
|
+
Object.prototype.hasOwnProperty.call(item, 'prototype') &&
|
|
4
|
+
!Object.prototype.hasOwnProperty.call(item, 'arguments')
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default isClass
|
package/src/is-set.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function isSet (item) {
|
|
2
|
-
return ![undefined, null].includes(item)
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export default isSet
|
|
1
|
+
function isSet (item) {
|
|
2
|
+
return ![undefined, null].includes(item)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export default isSet
|
package/src/log.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { sprintf } from 'sprintf-js'
|
|
2
|
-
|
|
3
|
-
function format (fn, ...items) {
|
|
4
|
-
const date = (new Date()).toISOString()
|
|
5
|
-
const label = typeof items[0] === 'string' ? items[0] : undefined
|
|
6
|
-
if (label) {
|
|
7
|
-
items.shift()
|
|
8
|
-
return fn(sprintf(`[${date}] ${label}`, ...items))
|
|
9
|
-
}
|
|
10
|
-
return fn(...items)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function log (...items) {
|
|
14
|
-
return format(console.log, ...items)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function logError (...items) {
|
|
18
|
-
return format(console.error, ...items)
|
|
19
|
-
}
|
|
1
|
+
import { sprintf } from 'sprintf-js'
|
|
2
|
+
|
|
3
|
+
function format (fn, ...items) {
|
|
4
|
+
const date = (new Date()).toISOString()
|
|
5
|
+
const label = typeof items[0] === 'string' ? items[0] : undefined
|
|
6
|
+
if (label) {
|
|
7
|
+
items.shift()
|
|
8
|
+
return fn(sprintf(`[${date}] ${label}`, ...items))
|
|
9
|
+
}
|
|
10
|
+
return fn(...items)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function log (...items) {
|
|
14
|
+
return format(console.log, ...items)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function logError (...items) {
|
|
18
|
+
return format(console.error, ...items)
|
|
19
|
+
}
|
package/src/paginate.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import isPlainObject from 'lodash-es/isPlainObject.js'
|
|
2
|
-
import forOwn from 'lodash-es/forOwn.js'
|
|
3
|
-
import isEmpty from 'lodash-es/isEmpty.js'
|
|
4
|
-
import orderBy from 'lodash-es/orderBy.js'
|
|
5
|
-
|
|
6
|
-
function paginate (collection = [], { page = 1, limit = 25, sort } = {}) {
|
|
7
|
-
const count = collection.length
|
|
8
|
-
const offset = (page - 1) * limit
|
|
9
|
-
const fields = []
|
|
10
|
-
const dirs = []
|
|
11
|
-
if (isPlainObject(sort)) {
|
|
12
|
-
forOwn(sort, (v, k) => {
|
|
13
|
-
fields.push(k)
|
|
14
|
-
dirs.push(v < 0 ? 'desc' : 'asc')
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
if (!isEmpty(fields)) collection = orderBy(collection, fields, dirs)
|
|
18
|
-
const data = collection.slice(offset, offset + limit)
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
data,
|
|
22
|
-
page,
|
|
23
|
-
limit,
|
|
24
|
-
count,
|
|
25
|
-
pages: Math.ceil(collection.length / limit)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default paginate
|
|
1
|
+
import isPlainObject from 'lodash-es/isPlainObject.js'
|
|
2
|
+
import forOwn from 'lodash-es/forOwn.js'
|
|
3
|
+
import isEmpty from 'lodash-es/isEmpty.js'
|
|
4
|
+
import orderBy from 'lodash-es/orderBy.js'
|
|
5
|
+
|
|
6
|
+
function paginate (collection = [], { page = 1, limit = 25, sort } = {}) {
|
|
7
|
+
const count = collection.length
|
|
8
|
+
const offset = (page - 1) * limit
|
|
9
|
+
const fields = []
|
|
10
|
+
const dirs = []
|
|
11
|
+
if (isPlainObject(sort)) {
|
|
12
|
+
forOwn(sort, (v, k) => {
|
|
13
|
+
fields.push(k)
|
|
14
|
+
dirs.push(v < 0 ? 'desc' : 'asc')
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
if (!isEmpty(fields)) collection = orderBy(collection, fields, dirs)
|
|
18
|
+
const data = collection.slice(offset, offset + limit)
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
data,
|
|
22
|
+
page,
|
|
23
|
+
limit,
|
|
24
|
+
count,
|
|
25
|
+
pages: Math.ceil(collection.length / limit)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default paginate
|
package/src/pascal-case.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import upperFirst from 'lodash-es/upperFirst.js'
|
|
2
|
-
import camelCase from 'lodash-es/camelCase.js'
|
|
3
|
-
|
|
4
|
-
function pascalCase (text) {
|
|
5
|
-
return upperFirst(camelCase(text))
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export default pascalCase
|
|
1
|
+
import upperFirst from 'lodash-es/upperFirst.js'
|
|
2
|
+
import camelCase from 'lodash-es/camelCase.js'
|
|
3
|
+
|
|
4
|
+
function pascalCase (text) {
|
|
5
|
+
return upperFirst(camelCase(text))
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default pascalCase
|
package/src/round.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function round (val, scale = 0) {
|
|
2
|
-
scale = scale <= 0 ? 1 : 10 ** scale
|
|
3
|
-
return Math.round(val * scale) / scale
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export default round
|
|
1
|
+
function round (val, scale = 0) {
|
|
2
|
+
scale = scale <= 0 ? 1 : 10 ** scale
|
|
3
|
+
return Math.round(val * scale) / scale
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export default round
|
package/src/sec-to-hms.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import padStart from 'lodash-es/padStart.js'
|
|
2
|
-
|
|
3
|
-
export default function secToHms (secs, ms) {
|
|
4
|
-
let remain
|
|
5
|
-
if (ms) {
|
|
6
|
-
remain = secs % 1000
|
|
7
|
-
secs = Math.floor(secs / 1000)
|
|
8
|
-
}
|
|
9
|
-
const secNum = parseInt(secs, 10)
|
|
10
|
-
const hours = Math.floor(secNum / 3600)
|
|
11
|
-
const minutes = Math.floor(secNum / 60) % 60
|
|
12
|
-
const seconds = secNum % 60
|
|
13
|
-
|
|
14
|
-
let hms = [hours, minutes, seconds]
|
|
15
|
-
.map(v => v < 10 ? '0' + v : v)
|
|
16
|
-
.filter((v, i) => v !== '00' || i > 0)
|
|
17
|
-
.join(':')
|
|
18
|
-
if (ms) hms += '+' + padStart(remain, 3, '0')
|
|
19
|
-
return hms
|
|
20
|
-
}
|
|
1
|
+
import padStart from 'lodash-es/padStart.js'
|
|
2
|
+
|
|
3
|
+
export default function secToHms (secs, ms) {
|
|
4
|
+
let remain
|
|
5
|
+
if (ms) {
|
|
6
|
+
remain = secs % 1000
|
|
7
|
+
secs = Math.floor(secs / 1000)
|
|
8
|
+
}
|
|
9
|
+
const secNum = parseInt(secs, 10)
|
|
10
|
+
const hours = Math.floor(secNum / 3600)
|
|
11
|
+
const minutes = Math.floor(secNum / 60) % 60
|
|
12
|
+
const seconds = secNum % 60
|
|
13
|
+
|
|
14
|
+
let hms = [hours, minutes, seconds]
|
|
15
|
+
.map(v => v < 10 ? '0' + v : v)
|
|
16
|
+
.filter((v, i) => v !== '00' || i > 0)
|
|
17
|
+
.join(':')
|
|
18
|
+
if (ms) hms += '+' + padStart(remain, 3, '0')
|
|
19
|
+
return hms
|
|
20
|
+
}
|
package/src/titleize.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import forOwn from 'lodash-es/forOwn.js'
|
|
2
|
-
import map from 'lodash-es/map.js'
|
|
3
|
-
import words from 'lodash-es/words.js'
|
|
4
|
-
import uniq from 'lodash-es/uniq.js'
|
|
5
|
-
import concat from 'lodash-es/concat.js'
|
|
6
|
-
import upperFirst from 'lodash-es/upperFirst.js'
|
|
7
|
-
|
|
8
|
-
function titleize (text = '', { ignores = [], replacement = {} } = {}) {
|
|
9
|
-
const defIgnores = ['or', 'and', 'of', 'with']
|
|
10
|
-
const replacer = {}
|
|
11
|
-
forOwn(replacement, (v, k) => {
|
|
12
|
-
const id = this.generateId('int')
|
|
13
|
-
replacer[id] = k
|
|
14
|
-
text = text.replace(k, ` ${id} `)
|
|
15
|
-
})
|
|
16
|
-
return map(words(text), t => {
|
|
17
|
-
forOwn(replacer, (v, k) => {
|
|
18
|
-
if (k === t) t = replacement[replacer[k]]
|
|
19
|
-
})
|
|
20
|
-
ignores = uniq(concat(ignores, defIgnores))
|
|
21
|
-
if (ignores.includes(t)) return t
|
|
22
|
-
return upperFirst(t)
|
|
23
|
-
}).join(' ')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default titleize
|
|
1
|
+
import forOwn from 'lodash-es/forOwn.js'
|
|
2
|
+
import map from 'lodash-es/map.js'
|
|
3
|
+
import words from 'lodash-es/words.js'
|
|
4
|
+
import uniq from 'lodash-es/uniq.js'
|
|
5
|
+
import concat from 'lodash-es/concat.js'
|
|
6
|
+
import upperFirst from 'lodash-es/upperFirst.js'
|
|
7
|
+
|
|
8
|
+
function titleize (text = '', { ignores = [], replacement = {} } = {}) {
|
|
9
|
+
const defIgnores = ['or', 'and', 'of', 'with']
|
|
10
|
+
const replacer = {}
|
|
11
|
+
forOwn(replacement, (v, k) => {
|
|
12
|
+
const id = this.generateId('int')
|
|
13
|
+
replacer[id] = k
|
|
14
|
+
text = text.replace(k, ` ${id} `)
|
|
15
|
+
})
|
|
16
|
+
return map(words(text), t => {
|
|
17
|
+
forOwn(replacer, (v, k) => {
|
|
18
|
+
if (k === t) t = replacement[replacer[k]]
|
|
19
|
+
})
|
|
20
|
+
ignores = uniq(concat(ignores, defIgnores))
|
|
21
|
+
if (ignores.includes(t)) return t
|
|
22
|
+
return upperFirst(t)
|
|
23
|
+
}).join(' ')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default titleize
|