Skip to content

Instantly share code, notes, and snippets.

@iwill
Last active October 2, 2024 09:14
Show Gist options
  • Save iwill/a83038623ba4fef6abb9efca87ae9ccb to your computer and use it in GitHub Desktop.
Save iwill/a83038623ba4fef6abb9efca87ae9ccb to your computer and use it in GitHub Desktop.

Revisions

  1. iwill revised this gist Jun 16, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion semverCompare.js
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,6 @@
    */
    function semverCompare(a, b) {
    if (a.startsWith(b + "-")) return -1
    if (b.startsWith(a + "-")) return 1
    if (b.startsWith(a + "-")) return 1
    return a.localeCompare(b, undefined, { numeric: true, sensitivity: "case", caseFirst: "upper" })
    }
  2. iwill revised this gist Jun 8, 2022. No changes.
  3. iwill renamed this gist May 20, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions versionCompare.js → semverCompare.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    /**
    * Semantic Versioning Comparing
    * #see https://semver.org/
    * #see https://stackoverflow.com/a/65687141/456536
    * #see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options
  4. iwill revised this gist May 17, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion versionCompare.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,6 @@
    * #see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options
    */
    function semverCompare(a, b) {
    if (a === b) return 0
    if (a.startsWith(b + "-")) return -1
    if (b.startsWith(a + "-")) return 1
    return a.localeCompare(b, undefined, { numeric: true, sensitivity: "case", caseFirst: "upper" })
  5. iwill revised this gist May 17, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion versionCompare.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,6 @@
    * #see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options
    */
    function semverCompare(a, b) {
    a ||= "", b ||= ""
    if (a === b) return 0
    if (a.startsWith(b + "-")) return -1
    if (b.startsWith(a + "-")) return 1
  6. iwill revised this gist May 17, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion versionCompare.js
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,12 @@
    /**
    * #see https://semver.org/
    * #see https://stackoverflow.com/a/65687141/456536
    * #see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options
    */
    function semverCompare(a, b) {
    a ||= "", b ||= ""
    if (a === b) return 0
    if (a.startsWith(b + "-")) return -1
    if (b.startsWith(a + "-")) return 1
    return a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' })
    return a.localeCompare(b, undefined, { numeric: true, sensitivity: "case", caseFirst: "upper" })
    }
  7. iwill revised this gist May 17, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions versionCompare.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    function semverCompare(a, b) {
    a ||= "", b ||= ""
    if (a === b) return 0
    if (a.startsWith(b)) return -1
    if (b.startsWith(a)) return 1
    if (a.startsWith(b + "-")) return -1
    if (b.startsWith(a + "-")) return 1
    return a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' })
    }
  8. iwill revised this gist May 17, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion versionCompare.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    * #see https://semver.org/
    * #see https://stackoverflow.com/a/65687141/456536
    */
    function versionCompare(a, b) {
    function semverCompare(a, b) {
    a ||= "", b ||= ""
    if (a === b) return 0
    if (a.startsWith(b)) return -1
  9. iwill created this gist May 17, 2022.
    11 changes: 11 additions & 0 deletions versionCompare.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    /**
    * #see https://semver.org/
    * #see https://stackoverflow.com/a/65687141/456536
    */
    function versionCompare(a, b) {
    a ||= "", b ||= ""
    if (a === b) return 0
    if (a.startsWith(b)) return -1
    if (b.startsWith(a)) return 1
    return a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' })
    }