@gedit/utils
Advanced tools
Comparing version 0.1.54 to 0.1.55
@@ -25,3 +25,3 @@ "use strict"; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
var classnames_1 = require("classnames"); | ||
var clsx_1 = require("clsx"); | ||
var common_1 = require("../common"); | ||
@@ -62,3 +62,3 @@ var toStyleKey = function (key) { return key.replace(/([A-Z])/, function (k) { return "-" + k.toLowerCase(); }); }; | ||
if (classNames.length > 0) { | ||
element.className = classnames_1.default(classNames); | ||
element.className = clsx_1.default(classNames); | ||
} | ||
@@ -82,3 +82,3 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} | ||
element.className = classnames_1.default(classNames.concat(element.className.split(' '))); | ||
element.className = clsx_1.default(classNames.concat(element.className.split(' '))); | ||
} | ||
@@ -102,3 +102,3 @@ domUtils.addClass = addClass; | ||
} | ||
element.className = classnames_1.default(classNames); | ||
element.className = clsx_1.default(classNames); | ||
} | ||
@@ -140,3 +140,3 @@ domUtils.coverClass = coverClass; | ||
function classNameWithPrefix(prefix) { | ||
return function (key, opts) { return classnames_1.default(key.split(/\s+/).map(function (s) { return prefix + "-" + s; }).join(' '), opts); }; | ||
return function (key, opts) { return clsx_1.default(key.split(/\s+/).map(function (s) { return prefix + "-" + s; }).join(' '), opts); }; | ||
} | ||
@@ -143,0 +143,0 @@ domUtils.classNameWithPrefix = classNameWithPrefix; |
@@ -30,2 +30,11 @@ export declare function iterToArray<T = any>(iter: IterableIterator<T>): T[]; | ||
export declare function moveSourceToDest(arr: Array<any>, sourceIndex: number, destIndex: number): Array<any>; | ||
/** | ||
* @param {Array} targetArr | ||
* @param {Function?} getter | ||
* @returns {Array.<*>} | ||
* @example | ||
* const arr = [{name: 'bcde'}, {name: 'abcgga'}] | ||
* const newArr = sortArrByCharCode(arr, (obj) => obj.name) | ||
*/ | ||
export declare function sortArrayByCharCode<T = any>(targetArr?: T[], getter?: (obj: T) => string | number): T[]; | ||
//# sourceMappingURL=array.d.ts.map |
@@ -14,3 +14,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.moveSourceToDest = exports.deleteElement = exports.moveBackward = exports.moveForward = exports.updateArrayItem = exports.arrayUnion = exports.arrayToSet = exports.iterToArray = void 0; | ||
exports.sortArrayByCharCode = exports.moveSourceToDest = exports.deleteElement = exports.moveBackward = exports.moveForward = exports.updateArrayItem = exports.arrayUnion = exports.arrayToSet = exports.iterToArray = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
@@ -110,2 +110,43 @@ function iterToArray(iter) { | ||
exports.moveSourceToDest = moveSourceToDest; | ||
/** | ||
* @param {Array} targetArr | ||
* @param {Function?} getter | ||
* @returns {Array.<*>} | ||
* @example | ||
* const arr = [{name: 'bcde'}, {name: 'abcgga'}] | ||
* const newArr = sortArrByCharCode(arr, (obj) => obj.name) | ||
*/ | ||
function sortArrayByCharCode(targetArr, getter) { | ||
if (targetArr === void 0) { targetArr = []; } | ||
return targetArr.sort(function (obj1, obj2) { | ||
var str1 = obj1; | ||
var str2 = obj2; | ||
if (getter) { | ||
str1 = getter(obj1); | ||
str2 = getter(obj2); | ||
} | ||
var cursor = 0; | ||
if (typeof str1 === 'number' || typeof str2 === 'number') { | ||
if (str1 === str2) | ||
return 0; | ||
return str1 < str2 ? -1 : 1; | ||
} | ||
for (; cursor <= str1.length; cursor++) { | ||
var A = str1.charCodeAt(cursor); | ||
var B = str2.charCodeAt(cursor); | ||
var a = str1.toLowerCase().charCodeAt(cursor); | ||
var b = str2.toLowerCase().charCodeAt(cursor); | ||
if (isNaN(b)) | ||
return -1; | ||
if (a !== b) | ||
return a < b ? -1 : 1; | ||
if (a === b && A !== B) { | ||
// 小写排前面 | ||
return A < B ? 1 : -1; | ||
} | ||
} | ||
return 0; | ||
}); | ||
} | ||
exports.sortArrayByCharCode = sortArrayByCharCode; | ||
//# sourceMappingURL=array.js.map |
@@ -61,2 +61,5 @@ /******************************************************************************** | ||
withQuery(query: string): URI; | ||
addQueryObject(queryObj: { | ||
[key: string]: string; | ||
}): URI; | ||
/** | ||
@@ -83,8 +86,8 @@ * return this URI without a query | ||
function objectToQueryString(obj?: { | ||
[key: string]: string; | ||
[key: string]: string | undefined; | ||
}): string; | ||
function queryStringToObject(queryString: string): { | ||
[key: string]: string; | ||
[key: string]: string | undefined; | ||
}; | ||
} | ||
//# sourceMappingURL=uri.d.ts.map |
@@ -139,8 +139,3 @@ "use strict"; | ||
get: function () { | ||
return this.query.split('&').reduce(function (obj, key) { | ||
var _a = __read(key.split('='), 2), k = _a[0], value = _a[1]; | ||
obj[k] = value; | ||
return obj; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
}, {}); | ||
return URI.queryStringToObject(this.query); | ||
}, | ||
@@ -208,2 +203,6 @@ enumerable: false, | ||
}; | ||
URI.prototype.addQueryObject = function (queryObj) { | ||
queryObj = __assign(__assign({}, this.queryObject), queryObj); | ||
return this.withQuery(URI.objectToQueryString(queryObj)); | ||
}; | ||
/** | ||
@@ -247,3 +246,3 @@ * return this URI without a query | ||
return ''; | ||
return Object.keys(obj).map(function (key) { return key + "=" + obj[key]; }).join('&'); | ||
return Object.keys(obj).map(function (key) { return key + "=" + (obj[key] || ''); }).join('&'); | ||
} | ||
@@ -250,0 +249,0 @@ URI.objectToQueryString = objectToQueryString; |
{ | ||
"name": "@gedit/utils", | ||
"version": "0.1.54", | ||
"version": "0.1.55", | ||
"license": "MIT", | ||
@@ -12,6 +12,5 @@ "main": "lib/common/index", | ||
"dependencies": { | ||
"@types/classnames": "^2.2.10", | ||
"@types/lodash.clonedeep": "^4.5.6", | ||
"@types/lodash.debounce": "4.0.3", | ||
"classnames": "^2.2.6", | ||
"clsx": "^1.1.1", | ||
"inversify": "^5.0.1", | ||
@@ -33,3 +32,3 @@ "is-electron": "^2.1.0", | ||
}, | ||
"gitHead": "d3f88764de52d4497c40d8182f6cb525b0af64fc" | ||
"gitHead": "2978c97847865b758fe9b7730c57f286fc0bd286" | ||
} |
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import clx from 'classnames'; | ||
import clx from 'clsx'; | ||
import { Cache, CacheManager, Disposable, each } from '../common'; | ||
@@ -4,0 +4,0 @@ |
@@ -79,1 +79,38 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
} | ||
/** | ||
* @param {Array} targetArr | ||
* @param {Function?} getter | ||
* @returns {Array.<*>} | ||
* @example | ||
* const arr = [{name: 'bcde'}, {name: 'abcgga'}] | ||
* const newArr = sortArrByCharCode(arr, (obj) => obj.name) | ||
*/ | ||
export function sortArrayByCharCode<T = any>(targetArr: T[] = [], getter?: (obj: T) => string | number): T[] { | ||
return targetArr.sort((obj1: any, obj2: any) => { | ||
let str1: string | number = obj1 as string; | ||
let str2: string | number = obj2 as string; | ||
if (getter) { | ||
str1 = getter(obj1); | ||
str2 = getter(obj2); | ||
} | ||
let cursor = 0; | ||
if (typeof str1 === 'number' || typeof str2 === 'number') { | ||
if (str1 === str2) return 0; | ||
return str1 < str2 ? -1 : 1; | ||
} | ||
for (; cursor <= str1.length; cursor++) { | ||
const A = str1.charCodeAt(cursor); | ||
const B = str2.charCodeAt(cursor); | ||
const a = str1.toLowerCase().charCodeAt(cursor); | ||
const b = str2.toLowerCase().charCodeAt(cursor); | ||
if (isNaN(b)) return -1; | ||
if (a !== b) return a < b ? -1 : 1; | ||
if (a === b && A !== B) { | ||
// 小写排前面 | ||
return A < B ? 1 : -1; | ||
} | ||
} | ||
return 0; | ||
}); | ||
} |
@@ -89,8 +89,3 @@ /******************************************************************************** | ||
get queryObject(): object { | ||
return this.query.split('&').reduce( (obj, key: string) => { | ||
const [k, value] = key.split('='); | ||
obj[k] = value; | ||
return obj; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
}, {} as any); | ||
return URI.queryStringToObject(this.query); | ||
} | ||
@@ -179,2 +174,6 @@ | ||
} | ||
addQueryObject(queryObj: { [key: string]: string }): URI { | ||
queryObj = { ...this.queryObject, ...queryObj }; | ||
return this.withQuery(URI.objectToQueryString(queryObj)); | ||
} | ||
@@ -225,7 +224,7 @@ /** | ||
export namespace URI { | ||
export function objectToQueryString(obj?: {[key: string]: string}): string { | ||
export function objectToQueryString(obj?: {[key: string]: string | undefined }): string { | ||
if (!obj) return ''; | ||
return Object.keys(obj).map(key => `${key}=${obj[key]}`).join('&'); | ||
return Object.keys(obj).map(key => `${key}=${obj[key] || ''}`).join('&'); | ||
} | ||
export function queryStringToObject(queryString: string): {[key: string]: string} { | ||
export function queryStringToObject(queryString: string): {[key: string]: string | undefined } { | ||
return queryString.split('&').reduce( (obj, key: string) => { | ||
@@ -232,0 +231,0 @@ const [k, value] = key.split('='); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
546620
8
10350
+ Addedclsx@^1.1.1
+ Addedclsx@1.2.1(transitive)
- Removed@types/classnames@^2.2.10
- Removedclassnames@^2.2.6
- Removed@types/classnames@2.3.4(transitive)
- Removedclassnames@2.5.1(transitive)