2025/2/8第一次更新

This commit is contained in:
爱吃咸鱼小猫咪
2025-02-08 18:50:38 +08:00
commit d7af560866
26519 changed files with 5046029 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
https://github.com/lodash/lodash/wiki/Changelog
+49
View File
@@ -0,0 +1,49 @@
The MIT License
Copyright JS Foundation and other contributors <https://js.foundation/>
Based on Underscore.js, copyright Jeremy Ashkenas,
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/lodash/lodash
The following license applies to all parts of this software except as
documented below:
====
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.
====
Copyright and related rights for sample code are waived via CC0. Sample
code is defined as all source code displayed within the prose of the
documentation.
CC0: http://creativecommons.org/publicdomain/zero/1.0/
====
Files located in the node_modules and vendor directories are externally
maintained libraries used by this software which have their own
licenses; we recommend you read them, as their terms may differ from the
terms above.
+80
View File
@@ -0,0 +1,80 @@
# lodash
[Site](https://lodash.com/) |
[Docs](https://lodash.com/docs) |
[FP Guide](https://github.com/lodash/lodash/wiki/FP-Guide) |
[Contributing](https://github.com/lodash/lodash/blob/master/.github/CONTRIBUTING.md) |
[Wiki](https://github.com/lodash/lodash/wiki "Changelog, Roadmap, etc.") |
[Code of Conduct](https://code-of-conduct.openjsf.org) |
[Twitter](https://twitter.com/bestiejs) |
[Chat](https://gitter.im/lodash/lodash)
The [Lodash](https://lodash.com/) library exported as a [UMD](https://github.com/umdjs/umd) module.
Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli):
```shell
$ npm run build
$ lodash -o ./dist/lodash.js
$ lodash core -o ./dist/lodash.core.js
```
## Download
* [Core build](https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/core.js) ([~4 kB gzipped](https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/core.min.js))
* [Full build](https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/lodash.js) ([~24 kB gzipped](https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/lodash.min.js))
* [CDN copies](https://www.jsdelivr.com/projects/lodash) [![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/lodash/badge)](https://www.jsdelivr.com/package/npm/lodash)
Lodash is released under the [MIT license](https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/LICENSE) & supports modern environments.<br>
Review the [build differences](https://github.com/lodash/lodash/wiki/build-differences) & pick one thats right for you.
## Installation
In a browser:
```html
<script src="lodash.js"></script>
```
Using npm:
```shell
$ npm i -g npm
$ npm i lodash
```
Note: add `--save` if you are using npm < 5.0.0
In Node.js:
```js
// Load the full build.
var _ = require('lodash');
// Load the core build.
var _ = require('lodash/core');
// Load the FP build for immutable auto-curried iteratee-first data-last methods.
var fp = require('lodash/fp');
// Load method categories.
var array = require('lodash/array');
var object = require('lodash/fp/object');
// Cherry-pick methods for smaller browserify/rollup/webpack bundles.
var at = require('lodash/at');
var curryN = require('lodash/fp/curryN');
```
Looking for Lodash modules written in ES6 or smaller bundle sizes? Check out [lodash-es](https://www.npmjs.com/package/lodash-es).
## Why Lodash?
Lodash makes JavaScript easier by taking the hassle out of working with arrays,<br>
numbers, objects, strings, etc. Lodashs modular methods are great for:
* Iterating arrays, objects, & strings
* Manipulating & testing values
* Creating composite functions
## Module Formats
Lodash is available in a [variety of builds](https://lodash.com/custom-builds) & module formats.
* [lodash](https://www.npmjs.com/package/lodash) & [per method packages](https://www.npmjs.com/search?q=keywords:lodash-modularized)
* [lodash-es](https://www.npmjs.com/package/lodash-es), [babel-plugin-lodash](https://www.npmjs.com/package/babel-plugin-lodash), & [lodash-webpack-plugin](https://www.npmjs.com/package/lodash-webpack-plugin)
* [lodash/fp](https://github.com/lodash/lodash/tree/npm/fp)
* [lodash-amd](https://www.npmjs.com/package/lodash-amd)
+4
View File
@@ -0,0 +1,4 @@
export function addMapEntry(map: any, pair: any) {
map.set(pair[0], pair[1])
return map
}
+4
View File
@@ -0,0 +1,4 @@
export function addSetEntry(set: any, value: any) {
set.add(value)
return set
}
+14
View File
@@ -0,0 +1,14 @@
export function arrayFilter(array: any, predicate: any) {
let index = -1
const length = array == null ? 0 : array.length
let resIndex = 0
const result = []
while (++index < length) {
const value = array[index]
if (predicate(value, index, array)) {
result[resIndex++] = value
}
}
return result
}
+25
View File
@@ -0,0 +1,25 @@
import { baseTimes } from './_baseTime'
import { isIndex } from './_isIndex'
import { isArguments } from './is-arguments'
import { isArray } from './is-array'
const objectProto = Object.prototype
const hasOwnProperty = objectProto.hasOwnProperty
export function arrayLikeKeys(value: any, inherited?: any) {
const result =
isArray(value) || isArguments(value) ? baseTimes(value.length, String) : []
const length = result.length,
skipIndexes = !!length
for (const key in value) {
if (
(inherited || hasOwnProperty.call(value, key)) &&
!(skipIndexes && (key == 'length' || isIndex(key, length)))
) {
result.push(key)
}
}
return result
}
+17
View File
@@ -0,0 +1,17 @@
export function arrayReduce(
array: any,
iteratee: any,
accumulator: any,
initAccum?: any
) {
let index = -1
const length = array ? array.length : 0
if (initAccum && length) {
accumulator = array[++index]
}
while (++index < length) {
accumulator = iteratee(accumulator, array[index], index, array)
}
return accumulator
}
+3
View File
@@ -0,0 +1,3 @@
export function asciiToArray(string: string) {
return string.split('')
}
+18
View File
@@ -0,0 +1,18 @@
import { eq } from './_eq'
const objectProto = Object.prototype
const hasOwnProperty = objectProto.hasOwnProperty
export function assignValue<T extends object>(
object: T,
key: string | symbol,
value: any
) {
const objValue = object[key as keyof typeof object]
if (
!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
(value === undefined && !(key in object))
) {
object[key as keyof typeof object] = value
}
}
+6
View File
@@ -0,0 +1,6 @@
import { copyObject } from './_copyObject'
import { keys } from './keys'
export function baseAssign(object: any, source: any) {
return object && copyObject(source, keys(source), object)
}
+16
View File
@@ -0,0 +1,16 @@
export function baseFindIndex(
array: string[],
predicate: (...args: any[]) => boolean,
fromIndex: number,
fromRight = false
) {
const length = array.length
let index = fromIndex + (fromRight ? 1 : -1)
while (fromRight ? index-- : ++index < length) {
if (predicate(array[index], index, array)) {
return index
}
}
return -1
}
+6
View File
@@ -0,0 +1,6 @@
const objectProto = Object.prototype
const objectToString = objectProto.toString
export function baseGetTag(value: any) {
return objectToString.call(value)
}
+9
View File
@@ -0,0 +1,9 @@
import { baseFindIndex } from './_baseFindIndex'
import { baseIsNaN } from './_baseIsNan'
import { strictIndexOf } from './_strictIndexOf'
export function baseIndexOf(array: string[], value: string, fromIndex: number) {
return value === value
? strictIndexOf(array, value, fromIndex)
: baseFindIndex(array, baseIsNaN, fromIndex)
}
@@ -0,0 +1,8 @@
import { baseGetTag } from './_baseGetTag'
import { isObjectLike } from './is-object-like'
const argsTag = '[object Arguments]'
export function baseIsArguments(value: any) {
return isObjectLike(value) && baseGetTag(value) == argsTag
}
+3
View File
@@ -0,0 +1,3 @@
export function baseIsNaN(value: any) {
return value !== value
}
+18
View File
@@ -0,0 +1,18 @@
import { isPrototype } from './_isPrototype'
import { nativeKeys } from './_nativeKeys'
const objectProto = Object.prototype
const hasOwnProperty = objectProto.hasOwnProperty
export function baseKeys(object: any) {
if (!isPrototype(object)) {
return nativeKeys(object)
}
const result = []
for (const key in new Object(object)) {
if (hasOwnProperty.call(object, key) && key != 'constructor') {
result.push(key)
}
}
return result
}
+20
View File
@@ -0,0 +1,20 @@
export function baseSlice(array: string[], start: number, end: number) {
let index = -1
let length = array.length
if (start < 0) {
start = -start > length ? 0 : length + start
}
end = end > length ? length : end
if (end < 0) {
end += length
}
length = start > end ? 0 : (end - start) >>> 0
start >>>= 0
const result = Array.from({ length })
while (++index < length) {
result[index] = array[index + start]
}
return result
}
+9
View File
@@ -0,0 +1,9 @@
export function baseTimes(n: any, iteratee: any) {
let index = -1
const result = Array.from({ length: n })
while (++index < n) {
result[index] = iteratee(index)
}
return result
}
+18
View File
@@ -0,0 +1,18 @@
import { isSymbol } from '@vue/shared'
import { INFINITY } from './_common'
import type { PropertyName } from './_common'
const symbolProto = Symbol ? Symbol.prototype : undefined
const symbolToString = symbolProto ? symbolProto.toString : undefined
export function baseToString(value: PropertyName) {
if (typeof value == 'string') {
return value
}
if (isSymbol(value)) {
return symbolToString ? symbolToString.call(value) : ''
}
const result = `${value}`
return result == '0' && 1 / value == -INFINITY ? '-0' : result
}
+9
View File
@@ -0,0 +1,9 @@
import { trimmedEndIndex } from './_trimmedEndIndex'
const reTrimStart = /^\s+/
export function baseTrim(string: string) {
return string
? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
: string
}
+7
View File
@@ -0,0 +1,7 @@
import { stringToPath } from './_stringToPath'
import type { PropertyName, PropertyPath } from './_common'
export function castPath(value: PropertyPath) {
return Array.isArray(value) ? value : stringToPath(value as PropertyName)
}
+7
View File
@@ -0,0 +1,7 @@
import { baseSlice } from './_baseSlice'
export function castSlice(array: string[], start: number, end: number) {
const length = array.length
end = end === undefined ? length : end
return !start && end >= length ? array : baseSlice(array, start, end)
}
+14
View File
@@ -0,0 +1,14 @@
import { baseIndexOf } from './_baseIndexOf'
export function charsStartIndex(strSymbols: string[], chrSymbols: string[]) {
let index = -1
const length = strSymbols.length
while (
++index < length &&
baseIndexOf(chrSymbols, strSymbols[index], 0) > -1
) {
/* empty */
}
return index
}
+10
View File
@@ -0,0 +1,10 @@
import { baseIndexOf } from './_baseIndexOf'
export function charsEndIndex(strSymbols: string[], chrSymbols: string[]) {
let index = strSymbols.length
while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {
/* empty */
}
return index
}
@@ -0,0 +1,5 @@
export function cloneArrayBuffer(arrayBuffer: any) {
const result = new arrayBuffer.constructor(arrayBuffer.byteLength)
new Uint8Array(result).set(new Uint8Array(arrayBuffer))
return result
}
+10
View File
@@ -0,0 +1,10 @@
import { cloneArrayBuffer } from './_cloneArrayBuffer'
export function cloneDataView(dataView: any, isDeep: any) {
const buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer
return new dataView.constructor(
buffer,
dataView.byteOffset,
dataView.byteLength
)
}
+8
View File
@@ -0,0 +1,8 @@
import { addMapEntry } from './_addMapEntry'
import { arrayReduce } from './_arrayReduce'
import { mapToArray } from './_mapToArray'
export function cloneMap(map: any, isDeep: any, cloneFunc: any) {
const array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map)
return arrayReduce(array, addMapEntry, new map.constructor())
}
+14
View File
@@ -0,0 +1,14 @@
const reFlags = /\w*$/
/**
* Creates a clone of `regexp`.
*
* @private
* @param {Object} regexp The regexp to clone.
* @returns {Object} Returns the cloned regexp.
*/
export function cloneRegExp(regexp: any) {
const result = new regexp.constructor(regexp.source, reFlags.exec(regexp))
result.lastIndex = regexp.lastIndex
return result
}
+8
View File
@@ -0,0 +1,8 @@
import { addSetEntry } from './_addSetEntry'
import { arrayReduce } from './_arrayReduce'
import { setToArray } from './_setToArray'
export function cloneSet(set: any, isDeep: any, cloneFunc: any) {
const array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set)
return arrayReduce(array, addSetEntry, new set.constructor())
}
+6
View File
@@ -0,0 +1,6 @@
const symbolProto = Symbol ? Symbol.prototype : undefined,
symbolValueOf = symbolProto ? symbolProto.valueOf : undefined
export function cloneSymbol(symbol: any) {
return symbolValueOf ? new Object(symbolValueOf.call(symbol)) : {}
}
+12
View File
@@ -0,0 +1,12 @@
import { cloneArrayBuffer } from './_cloneArrayBuffer'
export function cloneTypedArray(typedArray: any, isDeep: any) {
const buffer = isDeep
? cloneArrayBuffer(typedArray.buffer)
: typedArray.buffer
return new typedArray.constructor(
buffer,
typedArray.byteOffset,
typedArray.length
)
}
+31
View File
@@ -0,0 +1,31 @@
export type Many<T> = T | ReadonlyArray<T>
export type PropertyName = string | number | symbol
export type PropertyPath = Many<PropertyName>
export interface DebounceSettings {
leading?: boolean | undefined
maxWait?: number | undefined
trailing?: boolean | undefined
}
export interface ThrottleSettings {
leading?: boolean | undefined
trailing?: boolean | undefined
}
export interface DebouncedFunc<T extends (...args: any[]) => any> {
(...args: Parameters<T>): ReturnType<T> | undefined
cancel(): void
flush(): ReturnType<T> | undefined
}
export const reIsPlainProp = /^\w*$/
export const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/
export const reLeadingDot = /^\./
export const rePropName =
/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g
export const reEscapeChar = /\\(\\)?/g
export const reIsUint = /^(?:0|[1-9]\d*)$/
export const INFINITY = 1 / 0
export const MAX_SAFE_INTEGER = 9007199254740991
+10
View File
@@ -0,0 +1,10 @@
export function copyArray(source: any, array: any) {
let index = -1
const length = source.length
array || (array = Array.from({ length }))
while (++index < length) {
array[index] = source[index]
}
return array
}
+27
View File
@@ -0,0 +1,27 @@
import { assignValue } from './_assignValue'
export function copyObject(
source: any,
props: any,
object: any,
customizer?: any
) {
object || (object = {})
let index = -1
const length = props.length
while (++index < length) {
const key = props[index]
let newValue = customizer
? customizer(object[key], source[key], key, object, source)
: undefined
if (newValue === undefined) {
newValue = source[key]
}
assignValue(object, key, newValue)
}
return object
}
+6
View File
@@ -0,0 +1,6 @@
import { copyObject } from './_copyObject'
import { getSymbols } from './_getSymbol'
export function copySymbols(source: any, object: any) {
return copyObject(source, getSymbols(source) as unknown as any, object)
}
+3
View File
@@ -0,0 +1,3 @@
export function eq(value: any, other: any) {
return value === other || (value !== value && other !== other)
}
+22
View File
@@ -0,0 +1,22 @@
/* eslint-disable prefer-arrow-callback */
/* eslint-disable indent */
import { arrayFilter } from './_arrayFilter'
import { stubArray } from './stubArray'
const objectProto = Object.prototype
const propertyIsEnumerable = objectProto.propertyIsEnumerable
const nativeGetSymbols = Object.getOwnPropertySymbols
const getSymbols = !nativeGetSymbols
? stubArray
: function (object: any) {
if (object == null) return []
object = new Object(object)
return arrayFilter(nativeGetSymbols(object), function (symbol: any) {
return propertyIsEnumerable.call(object, symbol)
})
}
export { getSymbols }
+60
View File
@@ -0,0 +1,60 @@
import { baseGetTag } from './_baseGetTag'
import { toSource } from './_toSource'
/** `Object#toString` result references. */
const mapTag = '[object Map]',
objectTag = '[object Object]',
promiseTag = '[object Promise]',
setTag = '[object Set]',
weakMapTag = '[object WeakMap]'
const dataViewTag = '[object DataView]'
/** Used to detect maps, sets, and weakmaps. */
const dataViewCtorString = toSource(DataView),
mapCtorString = toSource(Map),
promiseCtorString = toSource(Promise),
setCtorString = toSource(Set),
weakMapCtorString = toSource(WeakMap)
/**
* Gets the `toStringTag` of `value`.
*
* @private
* @param {*} value The value to query.
* @returns {string} Returns the `toStringTag`.
*/
let getTag = baseGetTag
// Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
if (
(DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
(Map && getTag(new Map()) != mapTag) ||
(Promise && getTag(Promise.resolve()) != promiseTag) ||
(Set && getTag(new Set()) != setTag) ||
(WeakMap && getTag(new WeakMap()) != weakMapTag)
) {
getTag = function (value: any) {
const result = baseGetTag(value)
const Ctor = result == objectTag ? value.constructor : undefined
const ctorString = Ctor ? toSource(Ctor) : ''
if (ctorString) {
switch (ctorString) {
case dataViewCtorString:
return dataViewTag
case mapCtorString:
return mapTag
case promiseCtorString:
return promiseTag
case setCtorString:
return setTag
case weakMapCtorString:
return weakMapTag
}
}
return result
}
}
export { getTag }
+20
View File
@@ -0,0 +1,20 @@
const rsAstralRange = '\\ud800-\\udfff',
rsComboMarksRange = '\\u0300-\\u036f',
reComboHalfMarksRange = '\\ufe20-\\ufe2f',
rsComboSymbolsRange = '\\u20d0-\\u20ff',
rsComboRange =
rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
rsVarRange = '\\ufe0e\\ufe0f'
/** Used to compose unicode capture groups. */
const rsZWJ = '\\u200d'
/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
// eslint-disable-next-line no-misleading-character-class
const reHasUnicode = new RegExp(
`[${rsZWJ}${rsAstralRange}${rsComboRange}${rsVarRange}]`
)
export function hasUnicode(string: string) {
return reHasUnicode.test(string)
}
+18
View File
@@ -0,0 +1,18 @@
const objectProto = Object.prototype
const hasOwnProperty = objectProto.hasOwnProperty
export function initCloneArray(array: any) {
const length = array.length
const result = new array.constructor(length)
// Add properties assigned by `RegExp#exec`.
if (
length &&
typeof array[0] == 'string' &&
hasOwnProperty.call(array, 'index')
) {
result.index = array.index
result.input = array.input
}
return result
}
+75
View File
@@ -0,0 +1,75 @@
import { cloneArrayBuffer } from './_cloneArrayBuffer'
import { cloneDataView } from './_cloneDataView'
import { cloneMap } from './_cloneMap'
import { cloneRegExp } from './_cloneRegExp'
import { cloneSet } from './_cloneSet'
import { cloneSymbol } from './_cloneSymbol'
import { cloneTypedArray } from './_cloneTypedArray'
const boolTag = '[object Boolean]',
dateTag = '[object Date]',
mapTag = '[object Map]',
numberTag = '[object Number]',
regexpTag = '[object RegExp]',
setTag = '[object Set]',
stringTag = '[object String]',
symbolTag = '[object Symbol]'
const arrayBufferTag = '[object ArrayBuffer]',
dataViewTag = '[object DataView]',
float32Tag = '[object Float32Array]',
float64Tag = '[object Float64Array]',
int8Tag = '[object Int8Array]',
int16Tag = '[object Int16Array]',
int32Tag = '[object Int32Array]',
uint8Tag = '[object Uint8Array]',
uint8ClampedTag = '[object Uint8ClampedArray]',
uint16Tag = '[object Uint16Array]',
uint32Tag = '[object Uint32Array]'
export function initCloneByTag(
object: any,
tag: any,
cloneFunc: any,
isDeep: any
) {
const Ctor = object.constructor
switch (tag) {
case arrayBufferTag:
return cloneArrayBuffer(object)
case boolTag:
case dateTag:
return new Ctor(+object)
case dataViewTag:
return cloneDataView(object, isDeep)
case float32Tag:
case float64Tag:
case int8Tag:
case int16Tag:
case int32Tag:
case uint8Tag:
case uint8ClampedTag:
case uint16Tag:
case uint32Tag:
return cloneTypedArray(object, isDeep)
case mapTag:
return cloneMap(object, isDeep, cloneFunc)
case numberTag:
case stringTag:
return new Ctor(object)
case regexpTag:
return cloneRegExp(object)
case setTag:
return cloneSet(object, isDeep, cloneFunc)
case symbolTag:
return cloneSymbol(object)
}
}
+22
View File
@@ -0,0 +1,22 @@
import { isPrototype } from './_isPrototype'
import { isObject } from './is-object'
function overArg(func: any, transform: any) {
return function (arg: any) {
return func(transform(arg))
}
}
const getPrototype = overArg(Object.getPrototypeOf, Object)
function baseCreate(proto: any) {
return isObject(proto) ? objectCreate(proto) : {}
}
const objectCreate = Object.create
export function initCloneObject(object: any) {
return typeof object.constructor == 'function' && !isPrototype(object)
? baseCreate(getPrototype(object))
: {}
}
+9
View File
@@ -0,0 +1,9 @@
export function isHostObject(value: any) {
let result = false
if (value != null && typeof value.toString != 'function') {
try {
result = !!`${value}`
} catch (e) {}
}
return result
}
+12
View File
@@ -0,0 +1,12 @@
import { MAX_SAFE_INTEGER, reIsUint } from './_common'
export function isIndex(value: any, length?: any) {
length = length == null ? MAX_SAFE_INTEGER : length
return (
!!length &&
(typeof value == 'number' || reIsUint.test(value)) &&
value > -1 &&
value % 1 == 0 &&
value < length
)
}
+27
View File
@@ -0,0 +1,27 @@
import { isSymbol } from '@vue/shared'
import { reIsDeepProp, reIsPlainProp } from './_common'
import type { PropertyPath } from './_common'
export function isKey(value: PropertyPath, object: any) {
if (Array.isArray(value)) {
return false
}
const type = typeof value
if (
type == 'number' ||
type == 'symbol' ||
type == 'boolean' ||
value == null ||
isSymbol(value)
) {
return true
}
return (
reIsPlainProp.test(value as string) ||
!reIsDeepProp.test(value as string) ||
// eslint-disable-next-line unicorn/new-for-builtins
(object != null && (value as any) in Object(object))
)
}
+8
View File
@@ -0,0 +1,8 @@
const objectProto = Object.prototype
export function isPrototype(value: any) {
const Ctor = value && value.constructor,
proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto
return value === proto
}
+9
View File
@@ -0,0 +1,9 @@
export function mapToArray(map: any) {
let index = -1
const result = Array.from({ length: map.size })
map.forEach((value: any, key: any) => {
result[++index] = [key, value]
})
return result
}
+5
View File
@@ -0,0 +1,5 @@
import { overArg } from './_overArg'
const nativeKeys = overArg(Object.keys, Object)
export { nativeKeys }
+3
View File
@@ -0,0 +1,3 @@
const objectProto = Object.prototype
export const objectToString = objectProto.toString
+5
View File
@@ -0,0 +1,5 @@
export function overArg(func: any, transform: any) {
return function (arg: any) {
return func(transform(arg))
}
}
+9
View File
@@ -0,0 +1,9 @@
export function setToArray(set: any) {
let index = -1
const result = Array.from({ length: set.size })
set.forEach((value: any) => {
result[++index] = value
})
return result
}
+15
View File
@@ -0,0 +1,15 @@
export function strictIndexOf(
array: string[],
value: string,
fromIndex: number
) {
let index = fromIndex - 1
const length = array.length
while (++index < length) {
if (array[index] === value) {
return index
}
}
return -1
}
+7
View File
@@ -0,0 +1,7 @@
import { asciiToArray } from './_asciiToArray'
import { hasUnicode } from './_hasUnicode'
import { unicodeToArray } from './_unicodeToArray'
export function stringToArray(string: string) {
return hasUnicode(string) ? unicodeToArray(string) : asciiToArray(string)
}
+21
View File
@@ -0,0 +1,21 @@
import { toString } from './_toString'
import { reEscapeChar, reLeadingDot, rePropName } from './_common'
import type { PropertyName } from './_common'
export const stringToPath = function (string: PropertyName) {
string = toString(string)
const result = []
if (reLeadingDot.test(string)) {
result.push('')
}
string.replace(
rePropName,
(match: string, number: any, quote: any, string: any) => {
result.push(quote ? string.replace(reEscapeChar, '$1') : number || match)
return ''
}
)
return result
}
+10
View File
@@ -0,0 +1,10 @@
import { isSymbol } from '@vue/shared'
import { INFINITY } from './_common'
export function toKey(value: any) {
if (typeof value == 'string' || isSymbol(value)) {
return value
}
const result = `${value}`
return result == '0' && 1 / value == -INFINITY ? '-0' : result
}
+31
View File
@@ -0,0 +1,31 @@
import { isObject, isSymbol } from '@vue/shared'
const NAN = 0 / 0
const reTrim = /^\s+|\s+$/g
const reIsBinary = /^0b[01]+$/i
const reIsOctal = /^0o[0-7]+$/i
const reIsBadHex = /^[-+]0x[0-9a-f]+$/i
export function toNumber(value: any) {
if (typeof value == 'number') {
return value
}
if (isSymbol(value)) {
return NAN
}
if (isObject(value)) {
const other = typeof value.valueOf == 'function' ? value.valueOf() : value
value = isObject(other) ? `${other}` : other
}
if (typeof value != 'string') {
return value === 0 ? value : +value
}
value = value.replace(reTrim, '')
const isBinary = reIsBinary.test(value)
return isBinary || reIsOctal.test(value)
? Number.parseInt(value.slice(2), isBinary ? 2 : 8)
: reIsBadHex.test(value)
? NAN
: +value
}
+14
View File
@@ -0,0 +1,14 @@
const funcProto = Function.prototype
const funcToString = funcProto.toString
export function toSource(func: any) {
if (func != null) {
try {
return funcToString.call(func)
} catch (e) {}
try {
return `${func}`
} catch (e) {}
}
return ''
}
+7
View File
@@ -0,0 +1,7 @@
import { baseToString } from './_baseToString'
import type { PropertyName } from './_common'
export function toString(value: PropertyName) {
return value == null ? '' : baseToString(value)
}
+10
View File
@@ -0,0 +1,10 @@
const reWhitespace = /\s/
export function trimmedEndIndex(string: string) {
let index = string.length
while (index-- && reWhitespace.test(string.charAt(index))) {
/* empty */
}
return index
}
+46
View File
@@ -0,0 +1,46 @@
const rsAstralRange = '\\ud800-\\udfff',
rsComboMarksRange = '\\u0300-\\u036f',
reComboHalfMarksRange = '\\ufe20-\\ufe2f',
rsComboSymbolsRange = '\\u20d0-\\u20ff',
rsComboRange =
rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
rsVarRange = '\\ufe0e\\ufe0f'
/** Used to compose unicode capture groups. */
const rsAstral = `[${rsAstralRange}]`,
rsCombo = `[${rsComboRange}]`,
rsFitz = '\\ud83c[\\udffb-\\udfff]',
rsModifier = `(?:${rsCombo}|${rsFitz})`,
rsNonAstral = `[^${rsAstralRange}]`,
rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
rsZWJ = '\\u200d'
/** Used to compose unicode regexes. */
const reOptMod = `${rsModifier}?`,
rsOptVar = `[${rsVarRange}]?`,
rsOptJoin = `(?:${rsZWJ}(?:${[rsNonAstral, rsRegional, rsSurrPair].join(
'|'
)})${rsOptVar}${reOptMod})*`,
rsSeq = rsOptVar + reOptMod + rsOptJoin,
rsSymbol = `(?:${[
`${rsNonAstral + rsCombo}?`,
rsCombo,
rsRegional,
rsSurrPair,
rsAstral,
].join('|')})`
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
const reUnicode = new RegExp(`${rsFitz}(?=${rsFitz})|${rsSymbol}${rsSeq}`, 'g')
/**
* Converts a Unicode `string` to an array.
*
* @private
* @param {string} string The string to convert.
* @returns {Array} Returns the converted array.
*/
export function unicodeToArray(string: string) {
return string.match(reUnicode) || []
}
+8
View File
@@ -0,0 +1,8 @@
import type { Many } from './_common'
export function castArray<T>(value: Many<T>): T[] {
if (!value || (Array.isArray(value) && !value.length)) {
return []
}
return Array.isArray(value) ? value : [value as T]
}
+141
View File
@@ -0,0 +1,141 @@
import { isObject } from '@vue/shared'
import { toNumber } from './_toNumber'
import type { DebounceSettings, DebouncedFunc } from './_common'
const FUNC_ERROR_TEXT = 'Expected a function'
export function debounce<T extends (...args: any) => any>(
func: T,
wait?: number,
options?: DebounceSettings
): DebouncedFunc<T> {
let lastArgs: any
let lastThis: any
let maxWait: any
let result: any
let timerId: any
let lastCallTime: any
let lastInvokeTime = 0
let leading = false
let maxing = false
let trailing = true
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT)
}
wait = toNumber(wait) || 0
if (isObject(options)) {
leading = !!options.leading
maxing = 'maxWait' in options
maxWait = maxing
? Math.max(toNumber(options.maxWait) || 0, wait as number)
: maxWait
trailing = 'trailing' in options ? !!options.trailing : trailing
}
function invokeFunc(time: number) {
const args = lastArgs,
thisArg = lastThis
lastArgs = lastThis = undefined
lastInvokeTime = time
result = func.apply(thisArg, args)
return result
}
function leadingEdge(time: number) {
// Reset any `maxWait` timer.
lastInvokeTime = time
// Start the timer for the trailing edge.
timerId = setTimeout(timerExpired, wait)
// Invoke the leading edge.
return leading ? invokeFunc(time) : result
}
function remainingWait(time: number) {
const timeSinceLastCall = time - lastCallTime,
timeSinceLastInvoke = time - lastInvokeTime,
result = (wait as number) - timeSinceLastCall
return maxing ? Math.max(result, maxWait - timeSinceLastInvoke) : result
}
function shouldInvoke(time: number) {
const timeSinceLastCall = time - lastCallTime,
timeSinceLastInvoke = time - lastInvokeTime
// Either this is the first call, activity has stopped and we're at the
// trailing edge, the system time has gone backwards and we're treating
// it as the trailing edge, or we've hit the `maxWait` limit.
return (
lastCallTime === undefined ||
timeSinceLastCall >= (wait as number) ||
timeSinceLastCall < 0 ||
(maxing && timeSinceLastInvoke >= maxWait)
)
}
function timerExpired() {
const time = Date.now()
if (shouldInvoke(time)) {
return trailingEdge(time)
}
// Restart the timer.
timerId = setTimeout(timerExpired, remainingWait(time))
}
function trailingEdge(time: number) {
timerId = undefined
// Only invoke if we have `lastArgs` which means `func` has been
// debounced at least once.
if (trailing && lastArgs) {
return invokeFunc(time)
}
lastArgs = lastThis = undefined
return result
}
function cancel() {
if (timerId !== undefined) {
clearTimeout(timerId)
}
lastInvokeTime = 0
lastArgs = lastCallTime = lastThis = timerId = undefined
}
function flush() {
return timerId === undefined ? result : trailingEdge(Date.now())
}
function debounced(this: any) {
const time = Date.now(),
isInvoking = shouldInvoke(time)
// eslint-disable-next-line prefer-rest-params
lastArgs = arguments
// eslint-disable-next-line @typescript-eslint/no-this-alias
lastThis = this
lastCallTime = time
if (isInvoking) {
if (timerId === undefined) {
return leadingEdge(lastCallTime)
}
if (maxing) {
// Handle invocations in a tight loop.
timerId = setTimeout(timerExpired, wait)
return invokeFunc(lastCallTime)
}
}
if (timerId === undefined) {
timerId = setTimeout(timerExpired, wait)
}
return result
}
debounced.cancel = cancel
debounced.flush = flush
return debounced
}
+21
View File
@@ -0,0 +1,21 @@
type List<T> = ArrayLike<T>
type PropertyName = string | number | symbol
interface Dictionary<T> {
[index: string]: T
}
export function fromPairs<T>(
pairs: List<[PropertyName, T]> | null | undefined
): Dictionary<T>
export function fromPairs(
pairs: List<any[]> | null | undefined
): Dictionary<any> {
const result = {}
if (pairs == null) {
return result
}
for (const pair of pairs) {
result[pair[0]] = pair[1]
}
return result
}
+22
View File
@@ -0,0 +1,22 @@
import { isKey } from './_isKey'
import { castPath } from './_castPath'
import { toKey } from './_toKey'
import type { PropertyPath } from './_common'
function baseGet(object: any, path: PropertyPath) {
path = isKey(path, object) ? [path] : castPath(path)
let index = 0
const length = path.length
while (object != null && index < length) {
object = object[toKey(path[index++])]
}
return index && index == length ? object : undefined
}
export function get(object: any, path: PropertyPath, defaultValue?: any): any {
const result = object == null ? undefined : baseGet(object, path)
return result === undefined ? defaultValue : result
}
+10
View File
@@ -0,0 +1,10 @@
export { fromPairs } from './from-pairs'
export { isNil } from './is-nil'
export { isBoolean } from './is-boolean'
export { isNumber } from './is-number'
export { get } from './get'
export { set } from './set'
export { debounce } from './debounce'
export { throttle } from './throttle'
export { castArray } from './cast-array'
export { trim } from './trim'
+26
View File
@@ -0,0 +1,26 @@
/* eslint-disable indent */
import { baseIsArguments } from './_baseIsArguments'
import { isObjectLike } from './is-object-like'
const objectProto = Object.prototype
const hasOwnProperty = objectProto.hasOwnProperty
const propertyIsEnumerable = objectProto.propertyIsEnumerable
const isArguments = baseIsArguments(
(function () {
// eslint-disable-next-line prefer-rest-params
return arguments
})()
)
? baseIsArguments
: function (value: any) {
return (
isObjectLike(value) &&
hasOwnProperty.call(value, 'callee') &&
!propertyIsEnumerable.call(value, 'callee')
)
}
export { isArguments }
+6
View File
@@ -0,0 +1,6 @@
import { isFunction } from './is-function'
import { isLength } from './is-length'
export function isArrayLike(value: any) {
return value != null && isLength(value.length) && !isFunction(value)
}
+3
View File
@@ -0,0 +1,3 @@
export function isArray(value: any) {
return Array.isArray(value)
}
+12
View File
@@ -0,0 +1,12 @@
import { isObjectLike } from './is-object-like'
import { objectToString } from './_objectToString'
const boolTag = '[object Boolean]'
export function isBoolean(value?: any): value is boolean {
return (
value === true ||
value === false ||
(isObjectLike(value) && objectToString.call(value) == boolTag)
)
}
+16
View File
@@ -0,0 +1,16 @@
import { baseGetTag } from './_baseGetTag'
import { isObject } from './is-object'
const asyncTag = '[object AsyncFunction]',
funcTag = '[object Function]',
genTag = '[object GeneratorFunction]',
proxyTag = '[object Proxy]'
export function isFunction(value: any) {
if (!isObject(value)) {
return false
}
const tag = baseGetTag(value)
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag
}
+10
View File
@@ -0,0 +1,10 @@
import { MAX_SAFE_INTEGER } from './_common'
export function isLength(value: any) {
return (
typeof value == 'number' &&
value > -1 &&
value % 1 == 0 &&
value <= MAX_SAFE_INTEGER
)
}
+3
View File
@@ -0,0 +1,3 @@
export function isNil(value: any): value is null | undefined {
return value == null
}
+11
View File
@@ -0,0 +1,11 @@
import { isObjectLike } from './is-object-like'
import { objectToString } from './_objectToString'
const numberTag = '[object Number]'
export function isNumber(value?: any): value is number {
return (
typeof value == 'number' ||
(isObjectLike(value) && objectToString.call(value) == numberTag)
)
}
+3
View File
@@ -0,0 +1,3 @@
export function isObjectLike(value?: any): boolean {
return value != null && typeof value == 'object'
}
+4
View File
@@ -0,0 +1,4 @@
export function isObject(value: any) {
const type = typeof value
return value != null && (type == 'object' || type == 'function')
}
+7
View File
@@ -0,0 +1,7 @@
import { arrayLikeKeys } from './_arrayLikeKeys'
import { baseKeys } from './_baseKeys'
import { isArrayLike } from './is-array-like'
export function keys(object: any) {
return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object)
}
+53
View File
@@ -0,0 +1,53 @@
import { isObject } from '@vue/shared'
import { isKey } from './_isKey'
import { castPath } from './_castPath'
import { toKey } from './_toKey'
import { isIndex } from './_isIndex'
import { assignValue } from './_assignValue'
import type { PropertyPath } from './_common'
function baseSet<T extends object>(
object: T,
path: PropertyPath,
value: any,
customizer?: any
): T {
if (!isObject(object)) {
return object
}
path = isKey(path, object) ? [path] : castPath(path)
let index = -1
const length = path.length
const lastIndex = length - 1
let nested = object
while (nested != null && ++index < length) {
const key = toKey(path[index])
let newValue = value
if (index != lastIndex) {
const objValue = nested[key as keyof typeof nested]
newValue = customizer ? customizer(objValue, key, nested) : undefined
if (newValue === undefined) {
newValue = isObject(objValue)
? objValue
: isIndex(path[index + 1])
? []
: {}
}
}
assignValue(nested, key, newValue)
nested = nested[key as keyof typeof nested]
}
return object
}
export function set<T extends object>(
object: T,
path: PropertyPath,
value: any
): T {
return object == null ? object : baseSet(object, path, value)
}
+3
View File
@@ -0,0 +1,3 @@
export function stubArray() {
return []
}
+28
View File
@@ -0,0 +1,28 @@
import { isObject } from '@vue/shared'
import { debounce } from './debounce'
import type { DebouncedFunc, ThrottleSettings } from './_common'
const FUNC_ERROR_TEXT = 'Expected a function'
export function throttle<T extends (...args: any) => any>(
func: T,
wait?: number,
options?: ThrottleSettings
): DebouncedFunc<T> {
let leading = true,
trailing = true
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT)
}
if (isObject(options)) {
leading = 'leading' in options ? !!options.leading : leading
trailing = 'trailing' in options ? !!options.trailing : trailing
}
return debounce(func, wait, {
leading,
maxWait: wait,
trailing,
})
}
+25
View File
@@ -0,0 +1,25 @@
import { toString } from './_toString'
import { baseTrim } from './_baseTrim'
import { baseToString } from './_baseToString'
import { stringToArray } from './_stringToArray'
import { charsStartIndex } from './_charStartIndex'
import { charsEndIndex } from './_charsEndIndex'
import { castSlice } from './_castSlice'
export function trim(string: string, chars?: string): string {
string = toString(string)
if (string && chars === undefined) {
return baseTrim(string)
}
if (!string || !(chars = baseToString(chars as string))) {
return string
}
const strSymbols = stringToArray(string),
chrSymbols = stringToArray(chars),
start = charsStartIndex(strSymbols, chrSymbols),
end = charsEndIndex(strSymbols, chrSymbols) + 1
return castSlice(strSymbols, start, end).join('')
}