repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
hsr-optimizer | github_2023 | fribbels | typescript | generateSubStats | function generateSubStats(grade: RelicGrade, sub1: subStat, sub2?: subStat, sub3?: subStat, sub4?: subStat): subStat[] {
const substats = [{
stat: sub1.stat,
value: sub1.value,
rolls: {
high: SubStatValues[sub1.stat][grade as 2 | 3 | 4 | 5].high,
mid: SubStatValues[sub1.stat][grade as 2 | 3 | ... | /**
* used to generate substats for fakeRelic() more easily
* @param grade relic rarity
* @param sub1 substat line 1
* @param sub2 substat line 2
* @param sub3 substat line 3
* @param sub4 substat line 4
* @returns array of substats for a relic
*/ | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/relics/relicScorerPotential.ts#L832-L874 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | getHandlingCase | function getHandlingCase(scoringMetadata: ScoringMetadata) {
const substats = scoringMetadata.sortedSubstats
if (substats[0][1] == 0) return relicPotentialCases.NONE
if (substats[1][1] == 0) return relicPotentialCases.SINGLE_STAT
if (substats[2][1] > 0) return relicPotentialCases.NORMAL
if (substats[1][0] == ... | /**
* Analyses the scoringMetadata to determine in which way it should be handled
* @param scoringMetadata The scoring metadata for the character
*/ | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/relics/relicScorerPotential.ts#L880-L892 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | findHighestWeight | function findHighestWeight(substats: subStat[] | Stat[], scoringMetadata: ScoringMetadata) {
let index = 0
let weight = 0
let stat = '' as SubStats
for (let i = 0; i < substats.length; i++) {
const newWeight = scoringMetadata.stats[substats[i].stat]
if (newWeight > weight || i == 0) {
weight = new... | /**
* @param substats array of substats to search across
* @param scoringMetadata character scoring metadata
* @returns lowest index in the substats array of highest weight substat
*/ | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/relics/relicScorerPotential.ts#L899-L916 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | findLowestWeight | function findLowestWeight(substats: subStat[] | Stat[], scoringMetadata: ScoringMetadata) {
let index = 0
let weight = 1
let stat = '' as SubStats
for (let i = 0; i < substats.length; i++) {
const newWeight = scoringMetadata.stats[substats[i].stat]
if (newWeight < weight || i == 0) {
weight = newW... | /**
* @param substats array of substats to search across
* @param scoringMetadata character scoring metadata
* @returns lowest index in the substats array of lowest weight substat
*/ | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/relics/relicScorerPotential.ts#L923-L940 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | maxEnhance | function maxEnhance(grade: 2 | 3 | 4 | 5) {
switch (grade) {
case 2:
return 6
case 3:
return 9
case 4:
return 12
default:
return 15
}
} | /**
* converts grade to (max) enhance while preserving type check compliance
*/ | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/relics/relicScorerPotential.ts#L945-L956 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | getMainStatWeight | function getMainStatWeight(relic: Relic, scoringMetadata: ScoringMetadata) {
if (!Utils.hasMainStat(relic.part)) {
return 0
}
if (scoringMetadata.parts[relic.part].includes(relic.main.stat)) {
return 1
}
return scoringMetadata.stats[relic.main.stat]
} | // Hands/Head have no weight. Optimal main stats are 1.0 weight, and anything else inherits the substat weight. | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/relics/relicScorerPotential.ts#L973-L981 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | getImageUrl | function getImageUrl(name: string) {
return new URL(BASE_PATH + `/assets` + name, import.meta.url).href
} | // let baseUrl = process.env.PUBLIC_URL // Local testing; | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/rendering/assets.ts#L8-L10 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | applyScoringFunction | const applyScoringFunction: ScoringFunction = (result: SimulationResult, penalty = true) => {
if (!result) return
result.unpenalizedSimScore = result.x.COMBO_DMG
result.penaltyMultiplier = calculatePenaltyMultiplier(result, metadata, benchmarkScoringParams)
result.simScore = result.unpenalizedSimScore ... | // Generate scoring function | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/scoring/characterScorer.ts#L199-L205 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | generatePartialSimulations | function generatePartialSimulations(
character: Character,
metadata: SimulationMetadata,
simulationSets: SimulationSets,
originalSim: Simulation,
) {
const forceSpdBoots = false // originalBaseSpeed - baselineSimResult.x[Stats.SPD] > 2.0 * 2 * 5 // 3 min spd rolls per piece
const feetParts: string[] = force... | // Generate all main stat possibilities | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/scoring/characterScorer.ts#L832-L893 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | simulateOriginalCharacter | function simulateOriginalCharacter(
displayRelics: RelicBuild,
simulationSets: SimulationSets,
simulationForm: Form,
context: OptimizerContext,
scoringParams: ScoringParams,
simulationFlags: SimulationFlags,
mainStatMultiplier = 1,
overwriteSets = false,
) {
const relicsByPart: RelicBuild = TsUtils.cl... | // TODO: why is this function used twice | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/scoring/characterScorer.ts#L933-L977 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | compareSameTypeSubstat | function compareSameTypeSubstat(oldSubstat: Stat, newSubstat: Stat) {
let oldValue: number
let newValue: number
if (Utils.isFlat(oldSubstat.stat)) {
// Flat atk/def/hp/spd values we floor to an int
oldValue = Math.floor(oldSubstat.value)
newValue = Math.floor(newSubstat.value)
} else {
// Other ... | // -1: old > new, 0: old == new, 1, new > old | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/state/db.ts#L1210-L1226 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | setRelic | function setRelic(relic: Relic) {
const relicsById = window.store.getState().relicsById
relicsById[relic.id] = relic
window.store.getState().setRelicsById(relicsById)
} | /**
* Sets the provided relic in the application's state.
*/ | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/state/db.ts#L1242-L1246 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | getLightConeOverrideCenter | function getLightConeOverrideCenter(): Record<string, number> {
return {
20000: 270,
20001: 220,
20002: 160,
20003: 310,
20004: 180,
20005: 210,
20006: 390,
20007: 180,
20008: 220,
20009: 230,
20010: 250,
20011: 390,
20012: 300,
20013: 220,
20014: 210,
2... | // Standardized to 450 width | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/state/metadata.ts#L737-L868 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | saveFile | const saveFile = async (blob: Blob, suggestedName: string) => {
// Feature detection. The API needs to be supported and the app not run in an iframe.
const supportsFileSystemAccess
= 'showSaveFilePicker' in window
&& (() => {
try {
return window.self === window.top
} catch {
retu... | // https://web.dev/patterns/files/save-a-file | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/tabs/tabImport/ImportTab.tsx#L17-L64 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | getNumber | function getNumber(value: number, defaultValue: number, divide: number = 0) {
if (value == null) {
return defaultValue
}
divide = divide || 1
return value / divide
} | // Convert a display value to its internal form value | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/tabs/tabOptimizer/optimizerForm/optimizerFormTransform.ts#L325-L331 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | unsetMin | function unsetMin(value: number, percent: boolean = false) {
if (value == undefined) return undefined
return value == 0 ? undefined : parseFloat((percent ? value * 100 : value).toFixed(3))
} | // Display a number, rendering 0 as blank | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/tabs/tabOptimizer/optimizerForm/optimizerFormTransform.ts#L334-L337 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | unsetMax | function unsetMax(value: number, percent: boolean = false) {
if (value == undefined) return undefined
return value == Constants.MAX_INT ? undefined : parseFloat((percent ? value * 100 : value).toFixed(3))
} | // Display a number, rendering MAX_INT as blank | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/tabs/tabOptimizer/optimizerForm/optimizerFormTransform.ts#L340-L343 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | cloneTeammate | function cloneTeammate(teammate: Teammate | undefined) {
if (!teammate?.characterId) return defaultTeammate() as Teammate
return {
characterId: teammate.characterId ?? null,
characterEidolon: teammate.characterEidolon ?? null,
lightCone: teammate.lightCone ?? null,
lightConeSuperimposition: teammat... | // Clone teammate and replace undefined values with null to force the form to keep the null | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/tabs/tabOptimizer/optimizerForm/optimizerFormTransform.ts#L346-L355 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | redistributePityCumulative | function redistributePityCumulative(pity: number, warpCap: number, distribution: number[]) {
const redistributedCumulative: number[] = []
for (let i = 0; i < pity; i++) {
redistributedCumulative[i] = 0
}
for (let i = pity; i < warpCap; i++) {
redistributedCumulative[i] = i == 0 ? distribution[i] : redi... | // We have the cumulative distribution of warp results for 0 pity counter. | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/tabs/tabWarp/warpCalculatorController.ts#L282-L297 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | getNextSuccessIndex | function getNextSuccessIndex(cumulative: number[], warpCap: number, pity: number) {
const rand = Math.random() * cumulative[warpCap - 1]
return getIndex(rand, cumulative, pity)
} | // Adjust the random number to account for pity counter since anything before the pity is impossible | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/tabs/tabWarp/warpCalculatorController.ts#L300-L303 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | getIndex | function getIndex(random: number, cumulativeDistribution: number[], pity: number) {
let left = pity
let right = cumulativeDistribution.length - 1
while (left < right) {
const mid = Math.floor((left + right) / 2)
if (random > cumulativeDistribution[mid]) {
left = mid + 1
} else {
right = m... | // Binary search the index of random number within the distribution | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/tabs/tabWarp/warpCalculatorController.ts#L306-L320 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
hsr-optimizer | github_2023 | fribbels | typescript | animation | function animation(currentTime: number) {
const elapsedTime = currentTime - startTime
const progress = Math.min(elapsedTime / duration, 1)
// Ease-in-out function
const easeInOut = progress < 0.5
? 2 * progress * progress
: 1 - Math.pow(-2 * progress + 2, 2) / 2
parent.sc... | // Smooth scroll animation | https://github.com/fribbels/hsr-optimizer/blob/dcd874755b98536e01ee8cc1c099aa8f55dd2d5e/src/lib/utils/TsUtils.ts#L114-L128 | dcd874755b98536e01ee8cc1c099aa8f55dd2d5e |
lowstorage | github_2023 | good-lly | typescript | lowstorage.checkIfStorageExists | async checkIfStorageExists(): Promise<boolean> {
try {
const exists = await this._s3.bucketExists();
return !!exists;
} catch (error: any) {
if (error.message.includes('Not Found')) {
return false;
}
throw new lowstorageError(`${error.message}`, lowstorage_ERROR_CODES.S3_OPERATION_ERROR);
}
} | /**
* Check if a bucket exists.
* @returns {Promise<boolean>} True if the bucket exists, false otherwise.
* @throws {lowstorageError} If there's an error.
*/ | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L136-L146 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | lowstorage.createStorage | async createStorage(): Promise<boolean> {
try {
const exists = await this.checkIfStorageExists();
if (!exists) {
const createdBucket = await this._s3.createBucket();
return !!createdBucket;
}
return exists;
} catch (error: any) {
if (error instanceof lowstorageError) {
throw error;
}
... | /**
* Create a new storage bucket if it doesn't exist.
* @returns {Promise<boolean>} A Promise that resolves to true if the bucket was created or already exists, false otherwise.
* @throws {lowstorageError} If there's an error.
*/ | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L153-L167 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | lowstorage.listCollections | async listCollections(): Promise<string[]> {
try {
const listed = await this._s3.list(DELIMITER, this._dirPrefix);
if (Array.isArray(listed)) {
// filter only the collection name, not the full path and remove files without COL_SUFFIX
const filtered = listed.filter((entry) => entry.key.endsWith(COL_SUFFI... | /**
* List all collections.
* @returns {Promise<string[]>} An array of collection names.
* @throws {S3OperationError} If there's an error during S3 operation.
* @throws {lowstorageError} If there's an error.
*/ | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L176-L193 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | lowstorage.collectionExists | async collectionExists(colName: string = ''): Promise<boolean> {
try {
_hasColName(colName);
const exists = await this._s3.fileExists(`${this._dirPrefix}${DELIMITER}${colName}${COL_SUFFIX}`);
return !!exists;
} catch (error: any) {
if (error.message.includes('Not Found')) {
return false;
}
thr... | /**
* Check if a collection exists.
* @param {string} colName - The name of the collection.
* @returns {Promise<boolean>} True if the collection exists, false otherwise.
* @throws {lowstorageError} If there's an error.
*/ | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L201-L212 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | lowstorage.createCollection | async createCollection(colName: string = '', data: any[] = []): Promise<Collection> {
try {
_hasColName(colName);
const exists = await this.collectionExists(colName);
if (!exists) {
if (data.length > 0) {
const packr = new Packr();
await this._s3.put(`${this._dirPrefix}${DELIMITER}${colName}${C... | /**
* Create a new collection.
* @param {string} colName - The name of the collection.
* @param {Array} [data=[]] - The initial data for the collection.
* @returns {Promise<Collection>} A Promise that resolves to a Collection object.
* @throws {lowstorageError} If there's an error.
*/ | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L221-L238 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | lowstorage.removeCollection | async removeCollection(colName: string = ''): Promise<boolean> {
try {
_hasColName(colName);
const deleted = await this._s3.delete(`${this._dirPrefix}${DELIMITER}${colName}${COL_SUFFIX}`);
const exists = await this.collectionExists(colName);
if (!deleted || exists) {
return false;
}
if (deleted ... | /**
* Remove a collection.
* @param {string} colName - The name of the collection.
* @returns {Promise<boolean>} A Promise that resolves to true if the collection is removed, false otherwise.
* @throws {lowstorageError} If there's an error.
*/ | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L246-L267 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | lowstorage.collection | async collection(colName: string = '', autoCreate: boolean = true): Promise<Collection> {
try {
_hasColName(colName);
const colPath = `${this._dirPrefix}${DELIMITER}${colName}${COL_SUFFIX}`;
const exists = await this._s3.fileExists(colPath);
if (!exists) {
if (!autoCreate) {
throw new lowstorageE... | /**
* Get or create a collection.
* @param {string} colName - The name of the collection.
* @param {boolean} [autoCreate=true] - Whether to automatically create the collection if it doesn't exist.
* @returns {Promise<Collection>} A Promise that resolves to a Collection object.
* @throws {lowstorageError} If t... | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L276-L292 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | lowstorage.s3 | s3 = (): S3 => {
return this._s3;
} | /**
* Get the S3 instance associated with the lowstorage instance.
* @returns {S3} The S3 instance. Use this to perform S3 operations. Check for ultralight-s3 for more details.
*/ | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | Collection.insert | async insert(doc: Object | Array<Object>): Promise<Object[]> {
try {
if (doc === undefined || doc === null) {
throw new lowstorageError(`Document is required for insert`, lowstorage_ERROR_CODES.INSERT_ERROR);
}
if (typeof doc !== 'object' && !Array.isArray(doc)) {
throw new DocumentValidationError(
... | /**
* Insert a document into the collection.
* @param {Object|Array} doc - The document to insert.
* @returns {Promise<Array>} A Promise that resolves to the array of inserted document(s).
* @throws {lowstorageError} If there's an error.
*/ | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L450-L481 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | Collection.find | async find(query: Object = {}, options: Object = {}): Promise<Object[]> {
try {
if (query === undefined || query === null) {
throw new lowstorageError(`Query is required for update`, lowstorage_ERROR_CODES.MISSING_ARGUMENT);
}
const data = await this._loadData();
const start = (options as { skip?: num... | /**
* Find documents in the collection.
* @param {Object} [query={}] - The query to filter documents.
* @param {Object} [options={}] - The options for pagination.
* @param {number} [options.skip=0] - The number of documents to skip. Default is 0.
* @param {number} [options.limit=undefined] - The maximum numbe... | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L492-L508 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | Collection.findOne | async findOne(query: Object = {}): Promise<Object | null> {
try {
if (query === null) {
throw new lowstorageError(`${MOD_NAME}: Query cannot be null`, lowstorage_ERROR_CODES.INVALID_ARGUMENT);
}
const result = await this.find(query, { limit: 1 });
return result[0] || null;
} catch (error: any) {
... | /**
* Find the first document in the collection that matches the query.
* @param {Object} [query={}] - The query to filter documents.
* @returns {Promise<Object|null>} A Promise that resolves to the first matching document or null if no match is found.
* @throws {lowstorageError} If there's an error.
*/ | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L516-L529 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | Collection.update | async update(query: Object = {}, update: Object = {}, options: Object = {}): Promise<number> {
try {
if (query === undefined || query === null || update === undefined || update === null) {
throw new lowstorageError(`Query and update values are required for update`, lowstorage_ERROR_CODES.MISSING_ARGUMENT);
... | /**
* Update a single document in the collection that matches the query.
* @param {Object} [query={}] - The query to filter the document to update.
* @param {Object} [update={}] - The update operations to apply to the matching document.
* @returns {Promise<number>} A Promise that resolves to number of documents... | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L540-L576 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | Collection.updateOne | async updateOne(query: Record<string, any> = {}, update: Record<string, any> = {}, options: Record<string, any> = {}): Promise<number> {
try {
if (query === undefined || query === null || update === undefined || update === null) {
throw new lowstorageError(`Query is required`, lowstorage_ERROR_CODES.MISSING_AR... | /**
* Update a single document in the collection that matches the query.
* @param {Object} [query={}] - The query to filter the document to update.
* @param {Object} [update={}] - The update operations to apply to the matching document.
* @returns {Promise<number>} A Promise that resolves to 1 if a document was... | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L589-L619 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | Collection.delete | async delete(query: Object = {}): Promise<number> {
try {
if (query === undefined || query === null) {
throw new lowstorageError(`Query is required`, lowstorage_ERROR_CODES.MISSING_ARGUMENT);
}
const data = await this._loadData();
if (data.length === 0) return 0;
const initialLength = data.length;
... | /**
* Delete documents from the collection.
* @param {Object} [query={}] - The query to filter documents to delete.
* @returns {Promise<number>} A Promise that resolves to the number of documents deleted.
* @throws {lowstorageError} If the delete operation fails.
* @throws {S3OperationError} If the S3 operati... | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L628-L649 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | Collection.deleteAll | async deleteAll(): Promise<number> {
try {
const data = await this._loadData();
const initialLength = data.length;
const success = await this._saveData([]);
if (!success) {
throw new S3OperationError(`${MOD_NAME}: Failed to delete document`, lowstorage_ERROR_CODES.S3_OPERATION_ERROR);
}
return i... | /**
* Delete all documents from the collection.
* @returns {Promise<number>} A Promise that resolves to the number of documents deleted.
* @throws {lowstorageError} If the delete operation fails.
* @throws {S3OperationError} If the S3 operation fails.
*/ | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L657-L672 | d009434f995ba3b3869666d3f68a09738b891345 |
lowstorage | github_2023 | good-lly | typescript | Collection.count | async count(query: Object = {}): Promise<number> {
try {
const data = await this.find(query);
return data.length;
} catch (error: any) {
throw new lowstorageError(`Count operation failed: ${error.message}`, lowstorage_ERROR_CODES.COUNT_ERROR);
}
} | /**
* Count the number of documents in the collection.
* @param {Object} [query={}] - The query to filter documents.
* @returns {Promise<number>} A Promise that resolves to the number of documents in the collection.
* @throws {lowstorageError} If the count operation fails.
*/ | https://github.com/good-lly/lowstorage/blob/d009434f995ba3b3869666d3f68a09738b891345/src/lowstorage.ts#L680-L687 | d009434f995ba3b3869666d3f68a09738b891345 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | pathResolve | const pathResolve = (dir = ".", metaUrl = import.meta.url) => {
// 当前文件目录的绝对路径
const currentFileDir = dirname(fileURLToPath(metaUrl));
// build 目录的绝对路径
const buildDir = resolve(currentFileDir, "build");
// 解析的绝对路径
const resolvedPath = resolve(currentFileDir, dir);
// 检查解析的绝对路径是否在 build 目录内
if (resolvedP... | /**
* @description 根据可选的路径片段生成一个新的绝对路径
* @param dir 路径片段,默认`build`
* @param metaUrl 模块的完整`url`,如果在`build`目录外调用必传`import.meta.url`
*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/build/utils.ts#L22-L36 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | wrapperEnv | const wrapperEnv = (envConf: Recordable): ViteEnv => {
// 默认值
const ret: ViteEnv = {
VITE_PORT: 8848,
VITE_PUBLIC_PATH: "",
VITE_ROUTER_HISTORY: "",
VITE_CDN: false,
VITE_HIDE_HOME: "false",
VITE_COMPRESSION: "none",
VITE_APP_BASE_API: "",
VITE_APP_BASE_URL: "",
VITE_APP_BASE_URL... | /** 处理环境变量 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/build/utils.ts#L51-L82 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | getPackageSize | const getPackageSize = options => {
const { folder = "dist", callback, format = true } = options;
readdir(folder, (err, files: string[]) => {
if (err) throw err;
let count = 0;
const checkEnd = () => {
++count == files.length &&
callback(format ? formatBytes(sum(fileListTotal)) : sum(fileL... | /** 获取指定文件夹中所有文件的总大小 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/build/utils.ts#L87-L112 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | pauseResume | function pauseResume() {
if (state.paused) {
resume();
state.paused = false;
} else {
pause();
state.paused = true;
}
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReCountTo/src/normal/index.tsx#L65-L73 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | reset | function reset() {
state.startTime = null;
cancelAnimationFrame(state.rAF);
state.displayValue = formatNumber(props.startVal);
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReCountTo/src/normal/index.tsx#L87-L91 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | addDialog | const addDialog = (options: DialogOptions) => {
const open = () =>
dialogStore.value.push(Object.assign(options, { visible: true }));
if (options?.openDelay) {
useTimeoutFn(() => {
open();
}, options.openDelay);
} else {
open();
}
}; | /** 打开弹框 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReDialog/index.ts#L16-L26 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | closeDialog | const closeDialog = (options: DialogOptions, index: number, args?: any) => {
dialogStore.value[index].visible = false;
options.closeCallBack && options.closeCallBack({ options, index, args });
const closeDelay = options?.closeDelay ?? 200;
useTimeoutFn(() => {
dialogStore.value.splice(index, 1);
}, close... | /** 关闭弹框 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReDialog/index.ts#L29-L37 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | updateDialog | const updateDialog = (value: any, key = "title", index = 0) => {
dialogStore.value[index][key] = value;
}; | /**
* @description 更改弹框自身属性值
* @param value 属性值
* @param key 属性,默认`title`
* @param index 弹框索引(默认`0`,代表只有一个弹框,对于嵌套弹框要改哪个弹框的属性值就把该弹框索引赋给`index`)
*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReDialog/index.ts#L45-L47 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | closeAllDialog | const closeAllDialog = () => {
dialogStore.value = [];
}; | /** 关闭所有弹框 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReDialog/index.ts#L50-L52 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | flipDown | const flipDown = (front: any, back: any): void => {
flip("down", front, back);
}; | // 下翻牌 | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReFlop/src/filpper.tsx#L49-L51 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | flipUp | const flipUp = (front: any, back: any): void => {
flip("up", front, back);
}; | // 上翻牌 | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReFlop/src/filpper.tsx#L54-L56 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | setFront | function setFront(text: number): void {
frontTextFromData.value = text;
} | // 设置前牌文字 | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReFlop/src/filpper.tsx#L59-L61 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | setBack | const setBack = (text: number): void => {
backTextFromData.value = text;
}; | // 设置后牌文字 | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReFlop/src/filpper.tsx#L64-L66 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | drawLogoWithImage | const drawLogoWithImage = (image: HTMLImageElement) => {
ctx.drawImage(image, logoXY, logoXY, logoWidth, logoWidth);
}; | // 使用image绘制可以避免某些跨域情况 | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReQrcode/src/index.tsx#L160-L162 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | drawLogoWithCanvas | const drawLogoWithCanvas = (image: HTMLImageElement) => {
const canvasImage = document.createElement("canvas");
canvasImage.width = logoXY + logoWidth;
canvasImage.height = logoXY + logoWidth;
const imageCanvas = canvasImage.getContext("2d");
if (!imageCanvas || !ctx) return;
... | // 使用canvas绘制以获得更多的功能 | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReQrcode/src/index.tsx#L164-L178 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | throwError | function throwError(message: string) {
throw new TypeError(message);
} | /**
* 输出错误信息
* @param message 错误信息
*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReTypeit/src/index.tsx#L19-L21 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | getBrowserLanguage | function getBrowserLanguage() {
return navigator.language;
} | /**
* 获取浏览器默认语言
*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/components/ReTypeit/src/index.tsx#L26-L28 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | responsiveStorageNameSpace | const responsiveStorageNameSpace = () => getConfig().ResponsiveStorageNameSpace; | /** 本地响应式存储的命名空间 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/config/index.ts#L53-L53 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | setLayoutThemeColor | function setLayoutThemeColor(
theme = getConfig().Theme ?? "light",
isClick = true
) {
layoutTheme.value.theme = theme;
toggleTheme({
scopeName: `layout-theme-${theme}`
});
// 如果非isClick,保留之前的themeColor
const storageThemeColor = $storage.layout.themeColor;
$storage.layout = {
... | /** 设置导航主题色 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/layout/hooks/useDataThemeChange.ts#L52-L78 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | setEpThemeColor | const setEpThemeColor = (color: string) => {
useEpThemeStoreHook().setEpThemeColor(color);
document.documentElement.style.setProperty("--el-color-primary", color);
for (let i = 1; i <= 2; i++) {
setPropertyPrimary("dark", i, color);
}
for (let i = 1; i <= 9; i++) {
setPropertyPrimary("li... | /** 设置 `element-plus` 主题色 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/layout/hooks/useDataThemeChange.ts#L88-L97 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | dataThemeChange | function dataThemeChange(overall?: string) {
overallStyle.value = overall;
if (useEpThemeStoreHook().epTheme === "light" && dataTheme.value) {
setLayoutThemeColor("default", false);
} else {
setLayoutThemeColor(useEpThemeStoreHook().epTheme, false);
}
if (dataTheme.value) {
docume... | /** 浅色、深色整体风格切换 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/layout/hooks/useDataThemeChange.ts#L100-L116 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | onReset | function onReset() {
removeToken();
storageLocal().clear();
const { Grey, Weak, MultiTagsCache, EpThemeColor, Layout } = getConfig();
useAppStoreHook().setLayout(Layout);
setEpThemeColor(EpThemeColor);
useMultiTagsStoreHook().multiTagsCacheChange(MultiTagsCache);
toggleClass(Grey, "html-grey... | /** 清空缓存并返回登录页 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/layout/hooks/useDataThemeChange.ts#L119-L131 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | changeTitle | function changeTitle(meta: routeMetaType) {
const Title = getConfig().Title;
if (Title) document.title = `${transformI18n(meta.title)} | ${Title}`;
else document.title = transformI18n(meta.title);
} | /** 动态title */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/layout/hooks/useNav.ts#L92-L96 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | logout | function logout() {
useUserStoreHook().logOut();
} | /** 退出登录 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/layout/hooks/useNav.ts#L99-L101 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | isRemaining | function isRemaining(path: string) {
return remainingPaths.includes(path);
} | /** 判断路径是否参与菜单 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/layout/hooks/useNav.ts#L140-L142 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | getLogo | function getLogo() {
return new URL("/logo.svg", import.meta.url).href;
} | /** 获取`logo` */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/layout/hooks/useNav.ts#L145-L147 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | onMouseenter | function onMouseenter(index) {
if (index) activeIndex.value = index;
if (unref(showModel) === "smart") {
if (hasClass(instance.refs["schedule" + index][0], "schedule-active"))
return;
toggleClass(true, "schedule-in", instance.refs["schedule" + index][0]);
toggleClass(false, "schedule-o... | /** 鼠标移入添加激活样式 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/layout/hooks/useTag.ts#L169-L181 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | onMouseleave | function onMouseleave(index) {
activeIndex.value = -1;
if (unref(showModel) === "smart") {
if (hasClass(instance.refs["schedule" + index][0], "schedule-active"))
return;
toggleClass(false, "schedule-in", instance.refs["schedule" + index][0]);
toggleClass(true, "schedule-out", instance.... | /** 鼠标移出恢复默认样式 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/layout/hooks/useTag.ts#L184-L196 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | getObjectKeys | function getObjectKeys(obj) {
const stack = [];
const keys: Set<string> = new Set();
stack.push({ obj, key: "" });
while (stack.length > 0) {
const { obj, key } = stack.pop();
for (const k in obj) {
const newKey = key ? `${key}.${k}` : k;
if (obj[k] && isObject(obj[k])) {
stack.p... | /** 获取对象中所有嵌套对象的key键,并将它们用点号分割组成字符串 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/plugins/i18n.ts#L38-L59 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | toCorrectRoute | function toCorrectRoute() {
whiteList.includes(to.fullPath) ? next(_from.fullPath) : next();
} | /** 如果已经登录并存在登录信息后不能跳转到路由白名单,而是继续保持在当前页面 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/index.ts#L130-L132 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | ascending | function ascending(arr: any[]) {
arr.forEach((v, index) => {
// 当rank不存在时,根据顺序自动创建,首页路由永远在第一位
if (handRank(v)) v.meta.rank = index + 2;
});
return arr.sort(
(a: { meta: { rank: number } }, b: { meta: { rank: number } }) => {
return a?.meta.rank - b?.meta.rank;
}
);
} | /** 按照路由中meta下的rank等级升序来排序路由 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L44-L54 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | filterTree | function filterTree(data: RouteComponent[]) {
const newTree = cloneDeep(data).filter(
(v: { meta: { showLink: boolean } }) => v.meta?.showLink !== false
);
newTree.forEach(
(v: { children }) => v.children && (v.children = filterTree(v.children))
);
return newTree;
} | /** 过滤meta中showLink为false的菜单 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L57-L65 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | filterChildrenTree | function filterChildrenTree(data: RouteComponent[]) {
const newTree = cloneDeep(data).filter((v: any) => v?.children?.length !== 0);
newTree.forEach(
(v: { children }) => v.children && (v.children = filterTree(v.children))
);
return newTree;
} | /** 过滤children长度为0的的目录,当目录下没有菜单时,会过滤此目录,目录没有赋予roles权限,当目录下只要有一个菜单有显示权限,那么此目录就会显示 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L68-L74 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | isOneOfArray | function isOneOfArray(a: Array<string>, b: Array<string>) {
return Array.isArray(a) && Array.isArray(b)
? intersection(a, b).length > 0
? true
: false
: true;
} | /** 判断两个数组彼此是否存在相同值 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L77-L83 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | filterNoPermissionTree | function filterNoPermissionTree(data: RouteComponent[]) {
const currentRoles =
storageLocal().getItem<DataInfo<number>>(userKey)?.roles ?? [];
const newTree = cloneDeep(data).filter((v: any) =>
isOneOfArray(v.meta?.roles, currentRoles)
);
newTree.forEach(
(v: any) => v.children && (v.children = filt... | /** 从localStorage里取出当前登录用户的角色roles,过滤无权限的菜单 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L86-L96 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | getParentPaths | function getParentPaths(value: string, routes: RouteRecordRaw[], key = "path") {
// 深度遍历查找
function dfs(routes: RouteRecordRaw[], value: string, parents: string[]) {
for (let i = 0; i < routes.length; i++) {
const item = routes[i];
// 返回父级path
if (item[key] === value) return parents;
// ... | /** 通过指定 `key` 获取父级路径集合,默认 `key` 为 `path` */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L99-L120 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | dfs | function dfs(routes: RouteRecordRaw[], value: string, parents: string[]) {
for (let i = 0; i < routes.length; i++) {
const item = routes[i];
// 返回父级path
if (item[key] === value) return parents;
// children不存在或为空则不递归
if (!item.children || !item.children.length) continue;
// 往下查找时将... | // 深度遍历查找 | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L101-L117 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | findRouteByPath | function findRouteByPath(path: string, routes: RouteRecordRaw[]) {
let res = routes.find((item: { path: string }) => item.path == path);
if (res) {
return isProxy(res) ? toRaw(res) : res;
} else {
for (let i = 0; i < routes.length; i++) {
if (
routes[i].children instanceof Array &&
r... | /** 查找对应 `path` 的路由信息 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L123-L141 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | handleAsyncRoutes | function handleAsyncRoutes(routeList) {
if (routeList.length === 0) {
usePermissionStoreHook().handleWholeMenus(routeList);
} else {
formatFlatteningRoutes(addAsyncRoutes(routeList)).map(
(v: RouteRecordRaw) => {
// 防止重复添加路由
if (
router.options.routes[0].children.findIndex(
... | /** 处理动态路由(后端返回的路由) */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L154-L191 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | initRouter | function initRouter() {
if (getConfig()?.CachingAsyncRoutes) {
// 开启动态路由缓存本地localStorage
const key = "async-routes";
const asyncRouteList = storageLocal().getItem(key) as any;
if (asyncRouteList && asyncRouteList?.length > 0) {
return new Promise(resolve => {
handleAsyncRoutes(asyncRoute... | /** 初始化路由(`new Promise` 写法防止在异步请求中造成无限循环)*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L194-L221 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | formatFlatteningRoutes | function formatFlatteningRoutes(routesList: RouteRecordRaw[]) {
if (routesList.length === 0) return routesList;
let hierarchyList = buildHierarchyTree(routesList);
for (let i = 0; i < hierarchyList.length; i++) {
if (hierarchyList[i].children) {
hierarchyList = hierarchyList
.slice(0, i + 1)
... | /**
* 将多级嵌套路由处理成一维数组
* @param routesList 传入路由
* @returns 返回处理后的一维路由
*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L228-L239 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | formatTwoStageRoutes | function formatTwoStageRoutes(routesList: RouteRecordRaw[]) {
if (routesList.length === 0) return routesList;
const newRoutesList: RouteRecordRaw[] = [];
routesList.forEach((v: RouteRecordRaw) => {
if (v.path === "/") {
newRoutesList.push({
component: v.component,
name: v.name,
p... | /**
* 一维数组处理成多级嵌套数组(三级及以上的路由全部拍成二级,keep-alive 只支持到二级缓存)
* https://github.com/pure-admin/vue-pure-admin/issues/67
* @param routesList 处理后的一维路由菜单数组
* @returns 返回将一维数组重新处理成规定路由的格式
*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L247-L265 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | handleAliveRoute | function handleAliveRoute({ name }: ToRouteType, mode?: string) {
switch (mode) {
case "add":
usePermissionStoreHook().cacheOperate({
mode: "add",
name
});
break;
case "delete":
usePermissionStoreHook().cacheOperate({
mode: "delete",
name
});
... | /** 处理缓存路由(添加、删除、刷新) */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L268-L300 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | addAsyncRoutes | function addAsyncRoutes(arrRoutes: Array<RouteRecordRaw>) {
if (!arrRoutes || !arrRoutes.length) return;
const modulesRoutesKeys = Object.keys(modulesRoutes);
arrRoutes.forEach((v: RouteRecordRaw) => {
if (v.children == null) {
v.children = undefined;
}
// 将backstage属性加入meta,标识此路由为后端返回路由
v.m... | /** 过滤后端传来的动态路由 重新生成规范路由 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L303-L332 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | getHistoryMode | function getHistoryMode(routerHistory): RouterHistory {
// len为1 代表只有历史模式 为2 代表历史模式中存在base参数 https://next.router.vuejs.org/zh/api/#%E5%8F%82%E6%95%B0-1
const historyMode = routerHistory.split(",");
const leftMode = historyMode[0];
const rightMode = historyMode[1];
// no param
if (historyMode.length === 1) {... | /** 获取路由历史模式 https://next.router.vuejs.org/zh/guide/essentials/history-mode.html */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L335-L355 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | getAuths | function getAuths(): Array<string> {
return router.currentRoute.value.meta.auths as Array<string>;
} | /** 获取当前页面按钮级别的权限 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L358-L360 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | hasAuth | function hasAuth(value: string | Array<string>): boolean {
if (!value) return false;
/** 从当前路由的`meta`字段里获取按钮级别的所有自定义`code`值 */
const metaAuths = getAuths();
if (!metaAuths) return false;
const isAuths = isString(value)
? metaAuths.includes(value)
: isIncludeAllChildren(value, metaAuths);
return isAu... | /** 是否有按钮级别的权限(根据路由`meta`中的`auths`字段进行判断)*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L363-L372 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | getTopMenu | function getTopMenu(tag = false): menuType {
const topMenu = handleTopMenu(
usePermissionStoreHook().wholeMenus[0]?.children[0]
);
tag && useMultiTagsStoreHook().handleTags("push", topMenu);
return topMenu;
} | /** 获取所有菜单中的第一个菜单(顶级菜单)*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/router/utils.ts#L387-L393 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | convertTextToCode | function convertTextToCode(
provinceText: string,
cityText: string,
regionText?: string
): string {
let code = "";
if (provinceText && TextToCode[provinceText]) {
const province = TextToCode[provinceText];
code = province.code;
if (cityText && province[cityText]) {
const city = province[cit... | /**
* 汉字转区域码
* @param provinceText 省
* @param cityText 市
* @param regionText 区
* @returns
*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/chinaArea.ts#L159-L181 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | message | const message = (
message: string | VNode | (() => VNode),
params?: MessageParams
): MessageHandler => {
if (!params) {
return ElMessage({
message,
customClass: "pure-message"
});
} else {
const {
icon,
type = "info",
dangerouslyUseHTMLString = false,
customClass ... | /** 用法非常简单,参考 src/views/components/message/index.vue 文件 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/message.ts#L38-L78 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | closeAllMessage | const closeAllMessage = (): void => ElMessage.closeAll(); | /**
* 关闭所有 `Message` 消息提示函数
*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/message.ts#L83-L83 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | isImgElement | function isImgElement(element) {
return typeof HTMLImageElement !== "undefined"
? element instanceof HTMLImageElement
: element.tagName.toLowerCase() === "img";
} | /** 是否为`img`标签 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/preventDefault.ts#L4-L8 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | propTypes.style | static get style() {
return toValidableType("style", {
type: [String, Object]
});
} | // a native-like validator that supports the `.validable` method | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/propTypes.ts#L28-L32 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | PureHttp.retryOriginalRequest | private static retryOriginalRequest(config: PureHttpRequestConfig) {
return new Promise(resolve => {
PureHttp.requests.push((token: string) => {
config.headers["Authorization"] = formatToken(token);
resolve(config);
});
});
} | /** 重连原始请求 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/http/index.ts#L48-L55 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | PureHttp.httpInterceptorsRequest | private httpInterceptorsRequest(): void {
PureHttp.axiosInstance.interceptors.request.use(
async (config: PureHttpRequestConfig): Promise<any> => {
// 开启进度条动画
NProgress.start();
// 优先判断post/get等方法是否传入回调,否则执行初始化设置等回调
if (typeof config.beforeRequestCallback === "function") {
... | /** 请求拦截 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/http/index.ts#L58-L113 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | PureHttp.httpInterceptorsResponse | private httpInterceptorsResponse(): void {
const instance = PureHttp.axiosInstance;
instance.interceptors.response.use(
(response: any) => {
const $config = response.config;
// 关闭进度条动画
NProgress.done();
// 优先判断post/get等方法是否传入回调,否则执行初始化设置等回调
if (typeof $config.before... | /** 响应拦截 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/http/index.ts#L116-L144 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | PureHttp.request | public request<T>(
method: RequestMethods,
url: string,
param?: AxiosRequestConfig,
axiosConfig?: PureHttpRequestConfig
): Promise<T> {
const config = {
method,
url,
...param,
...axiosConfig
} as PureHttpRequestConfig;
// 单独处理自定义请求/响应回调
return new Promise((reso... | /** 通用请求工具函数 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/http/index.ts#L147-L171 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | PureHttp.post | public post<T, P>(
url: string,
params?: AxiosRequestConfig<P>,
config?: PureHttpRequestConfig
): Promise<T> {
return this.request<T>("post", url, params, config);
} | /** 单独抽离的`post`工具函数 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/http/index.ts#L174-L180 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | PureHttp.get | public get<T, P>(
url: string,
params?: AxiosRequestConfig<P>,
config?: PureHttpRequestConfig
): Promise<T> {
return this.request<T>("get", url, params, config);
} | /** 单独抽离的`get`工具函数 */ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/http/index.ts#L183-L189 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | StorageProxy.setItem | public async setItem<T>(k: string, v: T, m = 0): Promise<T> {
return new Promise((resolve, reject) => {
this.storage
.setItem(k, {
data: v,
expires: m ? new Date().getTime() + m * 60 * 1000 : 0
})
.then(value => {
resolve(value.data);
})
.c... | /**
* @description 将对应键名的数据保存到离线仓库
* @param k 键名
* @param v 键值
* @param m 缓存时间(单位`分`,默认`0`分钟,永久缓存)
*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/localforage/index.ts#L21-L35 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | StorageProxy.getItem | public async getItem<T>(k: string): Promise<T> {
return new Promise((resolve, reject) => {
this.storage
.getItem(k)
.then((value: ExpiresData<T>) => {
value && (value.expires > new Date().getTime() || value.expires === 0)
? resolve(value.data)
: resolve(null);... | /**
* @description 从离线仓库中获取对应键名的值
* @param k 键名
*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/localforage/index.ts#L41-L54 | e03895bcb6eca1f1894af1de15784838172956d5 |
Yi.Abp.Admin | github_2023 | ccnetcore | typescript | StorageProxy.removeItem | public async removeItem(k: string) {
return new Promise<void>((resolve, reject) => {
this.storage
.removeItem(k)
.then(() => {
resolve();
})
.catch(err => {
reject(err);
});
});
} | /**
* @description 从离线仓库中删除对应键名的值
* @param k 键名
*/ | https://github.com/ccnetcore/Yi.Abp.Admin/blob/e03895bcb6eca1f1894af1de15784838172956d5/Yi.Pure.Vue3/src/utils/localforage/index.ts#L60-L71 | e03895bcb6eca1f1894af1de15784838172956d5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.