@bluelovers/string-natural-compare
Advanced tools
Comparing version
@@ -6,2 +6,13 @@ # Change Log | ||
## [1.1.1](https://github.com/bluelovers/ws-array/compare/@bluelovers/string-natural-compare@1.0.7...@bluelovers/string-natural-compare@1.1.1) (2020-06-19) | ||
### 🐛 Bug Fixes | ||
* **typescript:** avoid https://github.com/microsoft/TypeScript/issues/39149 ([44a5863](https://github.com/bluelovers/ws-array/commit/44a586363f01f66ac4d061b71bdefd0a17d4d2b6)) | ||
## [1.0.7](https://github.com/bluelovers/ws-array/compare/@bluelovers/string-natural-compare@1.0.6...@bluelovers/string-natural-compare@1.0.7) (2020-06-16) | ||
@@ -8,0 +19,0 @@ |
@@ -1,39 +0,3 @@ | ||
/** | ||
* Created by user on 2020/6/4. | ||
*/ | ||
export interface IOptionsStringNaturalCompare { | ||
/** | ||
* Set to true to compare strings case-insensitively. Default: false. | ||
*/ | ||
caseInsensitive?: boolean; | ||
/** | ||
* A string of characters that define a custom character ordering. Default: undefined. | ||
*/ | ||
alphabet?: string; | ||
} | ||
export interface IOptionsNaturalCompare extends IOptionsStringNaturalCompare { | ||
desc?: boolean; | ||
} | ||
/** | ||
* Compare alphanumeric strings the same way a human would, | ||
* using a natural order algorithm | ||
* (originally known as the alphanum algorithm) | ||
* where numeric characters are sorted | ||
* based on their numeric values rather than their ASCII values. | ||
*/ | ||
export declare function naturalCompare(a: any, b: any, opts?: IOptionsNaturalCompare): number; | ||
export declare namespace naturalCompare { | ||
export var createNew: typeof import("./core").createNew; | ||
export var compareCaseInsensitive: (a: any, b: any) => number; | ||
var _a: typeof naturalCompare; | ||
export { _a as default }; | ||
} | ||
/** | ||
* create compare with preset options | ||
*/ | ||
export declare function createNew(opts?: IOptionsNaturalCompare): (a: any, b: any) => number; | ||
/** | ||
* compare strings case-insensitively | ||
*/ | ||
export declare const compareCaseInsensitive: (a: any, b: any) => number; | ||
export * from './index'; | ||
import naturalCompare from './index'; | ||
export default naturalCompare; |
66
core.js
"use strict"; | ||
/** | ||
* Created by user on 2020/6/4. | ||
*/ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -9,52 +16,5 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.compareCaseInsensitive = exports.createNew = exports.naturalCompare = void 0; | ||
const string_natural_compare_1 = __importDefault(require("string-natural-compare")); | ||
/** | ||
* Compare alphanumeric strings the same way a human would, | ||
* using a natural order algorithm | ||
* (originally known as the alphanum algorithm) | ||
* where numeric characters are sorted | ||
* based on their numeric values rather than their ASCII values. | ||
*/ | ||
function naturalCompare(a, b, opts) { | ||
let i; | ||
if (typeof a === 'number' && typeof b === 'number') { | ||
i = a - b; | ||
} | ||
else { | ||
if (typeof a === 'number') { | ||
a = String(a); | ||
} | ||
else if (typeof b === 'number') { | ||
b = String(b); | ||
} | ||
if (a === b) { | ||
return 0; | ||
} | ||
i = string_natural_compare_1.default(a, b, opts); | ||
} | ||
if (i !== 0 && (opts === null || opts === void 0 ? void 0 : opts.desc)) { | ||
i = 0 - i; | ||
} | ||
return i; | ||
} | ||
exports.naturalCompare = naturalCompare; | ||
/** | ||
* create compare with preset options | ||
*/ | ||
function createNew(opts) { | ||
return (a, b) => naturalCompare(a, b, opts); | ||
} | ||
exports.createNew = createNew; | ||
/** | ||
* compare strings case-insensitively | ||
*/ | ||
exports.compareCaseInsensitive = createNew({ | ||
caseInsensitive: true, | ||
}); | ||
naturalCompare.createNew = createNew; | ||
naturalCompare.compareCaseInsensitive = exports.compareCaseInsensitive; | ||
naturalCompare.default = naturalCompare; | ||
Object.defineProperty(naturalCompare, "__esModule", { value: true }); | ||
exports.default = naturalCompare; | ||
__exportStar(require("./index"), exports); | ||
const index_1 = __importDefault(require("./index")); | ||
exports.default = index_1.default; | ||
//# sourceMappingURL=core.js.map |
/** | ||
* Created by user on 2020/6/4. | ||
*/ | ||
import naturalCompare from './core'; | ||
export = naturalCompare; | ||
export interface IOptionsStringNaturalCompare { | ||
/** | ||
* Set to true to compare strings case-insensitively. Default: false. | ||
*/ | ||
caseInsensitive?: boolean; | ||
/** | ||
* A string of characters that define a custom character ordering. Default: undefined. | ||
*/ | ||
alphabet?: string; | ||
} | ||
export interface IOptionsNaturalCompare extends IOptionsStringNaturalCompare { | ||
desc?: boolean; | ||
} | ||
/** | ||
* Compare alphanumeric strings the same way a human would, | ||
* using a natural order algorithm | ||
* (originally known as the alphanum algorithm) | ||
* where numeric characters are sorted | ||
* based on their numeric values rather than their ASCII values. | ||
*/ | ||
export declare function naturalCompare(a: any, b: any, opts?: IOptionsNaturalCompare): number; | ||
export declare namespace naturalCompare { | ||
export var createNew: typeof import(".").createNew; | ||
export var compareCaseInsensitive: (a: any, b: any) => number; | ||
var _a: typeof naturalCompare; | ||
export { _a as default }; | ||
} | ||
/** | ||
* create compare with preset options | ||
*/ | ||
export declare function createNew(opts?: IOptionsNaturalCompare): (a: any, b: any) => number; | ||
/** | ||
* compare strings case-insensitively | ||
*/ | ||
export declare const compareCaseInsensitive: (a: any, b: any) => number; | ||
export default naturalCompare; |
53
index.js
@@ -8,4 +8,53 @@ "use strict"; | ||
}; | ||
const core_1 = __importDefault(require("./core")); | ||
module.exports = core_1.default; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.compareCaseInsensitive = exports.createNew = exports.naturalCompare = void 0; | ||
const string_natural_compare_1 = __importDefault(require("string-natural-compare")); | ||
/** | ||
* Compare alphanumeric strings the same way a human would, | ||
* using a natural order algorithm | ||
* (originally known as the alphanum algorithm) | ||
* where numeric characters are sorted | ||
* based on their numeric values rather than their ASCII values. | ||
*/ | ||
function naturalCompare(a, b, opts) { | ||
let i; | ||
if (typeof a === 'number' && typeof b === 'number') { | ||
i = a - b; | ||
} | ||
else { | ||
if (typeof a === 'number') { | ||
a = String(a); | ||
} | ||
else if (typeof b === 'number') { | ||
b = String(b); | ||
} | ||
if (a === b) { | ||
return 0; | ||
} | ||
i = string_natural_compare_1.default(a, b, opts); | ||
} | ||
if (i !== 0 && (opts === null || opts === void 0 ? void 0 : opts.desc)) { | ||
i = 0 - i; | ||
} | ||
return i; | ||
} | ||
exports.naturalCompare = naturalCompare; | ||
/** | ||
* create compare with preset options | ||
*/ | ||
function createNew(opts) { | ||
return (a, b) => naturalCompare(a, b, opts); | ||
} | ||
exports.createNew = createNew; | ||
/** | ||
* compare strings case-insensitively | ||
*/ | ||
exports.compareCaseInsensitive = createNew({ | ||
caseInsensitive: true, | ||
}); | ||
naturalCompare.createNew = createNew; | ||
naturalCompare.compareCaseInsensitive = exports.compareCaseInsensitive; | ||
naturalCompare.default = naturalCompare; | ||
Object.defineProperty(naturalCompare, "__esModule", { value: true }); | ||
exports.default = naturalCompare; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@bluelovers/string-natural-compare", | ||
"version": "1.0.7", | ||
"version": "1.1.1", | ||
"description": "Compare alphanumeric strings the same way a human would, using a natural order algorithm", | ||
@@ -38,3 +38,3 @@ "homepage": "https://github.com/bluelovers/ws-array/tree/master/packages/string-natural-compare#readme", | ||
}, | ||
"gitHead": "315a9098b8d606eb0be8a9edc7b5fe0674c452d1" | ||
"gitHead": "37f990c1d60adba476a07b0dda67f4df723ef2f8" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12011
15.38%12
33.33%132
18.92%1
Infinity%