@magic/semver 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -118,6 +118,14 @@ update dependencies
118
118
  - add typescript
119
119
  - update dependencies
120
120
 
121
- ##### 0.0.18 - unreleased
121
+ ##### 0.0.18
122
+
123
+ - fix handling a v in front of the version, eg v0.0.1
124
+
125
+ ##### 0.0.19
126
+
127
+ - better type exports
128
+
129
+ ##### 0.0.20 - unreleased
122
130
 
123
131
  ...
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic/semver",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "author": "Wizards & Witches",
5
5
  "description": "semantic version parsing and serialization.",
6
6
  "license": "AGPL-3.0",
package/src/bump.js CHANGED
@@ -7,10 +7,6 @@ import { isSemver } from './isSemver.js'
7
7
 
8
8
  const libName = '@magic/semver.bump'
9
9
 
10
- /**
11
- * @typedef {import('./types.js').Version} Version
12
- */
13
-
14
10
  /**
15
11
  * @param {string} v
16
12
  * @param {object} options
@@ -19,14 +15,14 @@ const libName = '@magic/semver.bump'
19
15
  * @param {boolean} [options.patch]
20
16
  * @param {boolean} [options.beta]
21
17
  * @param {boolean} [options.alpha]
22
- * @returns {Version | string}
18
+ * @returns {import('./types.js').Version | string}
23
19
  */
24
20
  export const bump = (v, options = {}) => {
25
21
  if (is.empty(v)) {
26
22
  throw error(`${libName} expects arguments to be non-empty`, 'E_VERSION_EMPTY')
27
23
  }
28
24
 
29
- /** @type {Partial<Version> } */
25
+ /** @type {Partial<import('./types.js').Version> } */
30
26
  let version
31
27
 
32
28
  const isString = is.string(v)
package/src/index.js CHANGED
@@ -12,6 +12,9 @@ export const parse = p
12
12
  export const stringify = s
13
13
  export const serialize = s
14
14
 
15
+ /** @typedef {import('./types.js').Version} Version */
16
+ /** @typedef {import('./types.js').VersionResult} VersionResult */
17
+
15
18
  export default {
16
19
  bump,
17
20
  isBigger,
package/src/isSemver.js CHANGED
@@ -3,12 +3,8 @@ import { parse } from './parse.js'
3
3
  import { serialize } from './serialize.js'
4
4
 
5
5
  /**
6
- * @typedef {import('./types.js').Version} Version
7
- */
8
-
9
- /**
10
- * @param {Version | string | unknown} v
11
- * @returns {v is Version}
6
+ * @param {import('./types.js').Version | string | unknown} v
7
+ * @returns {v is import('./types.js').Version}
12
8
  *
13
9
  */
14
10
  export const isSemver = v => {
package/src/parse.js CHANGED
@@ -3,14 +3,9 @@ import error from '@magic/error'
3
3
 
4
4
  const libName = `@magic/semver.parse:`
5
5
 
6
- /**
7
- * @typedef {import('./types.js').Version} Version
8
- * @typedef {import('./types.js').VersionResult} VersionResult
9
- */
10
-
11
6
  /**
12
7
  * @param {string} v
13
- * @returns {VersionResult}
8
+ * @returns {import('./types.js').VersionResult}
14
9
  */
15
10
  export const parse = v => {
16
11
  if (is.empty(v)) {
@@ -27,9 +22,9 @@ export const parse = v => {
27
22
 
28
23
  const [major, minor, patch, demo] = v.split('.')
29
24
 
30
- /** @type {VersionResult} */
25
+ /** @type {import('./types.js').VersionResult} */
31
26
  const result = {
32
- major: parseInt(major),
27
+ major: parseInt(major.replace('v', '')),
33
28
  minor: parseInt(minor),
34
29
  patch: -1,
35
30
  v,
@@ -48,7 +43,7 @@ export const parse = v => {
48
43
  }
49
44
 
50
45
  if (!is.number(result.major)) {
51
- throw error(`${libName} major was not an Int: ${result.major}`, 'E_MAJOR_TYPE')
46
+ throw error(`${libName} major was not an Int: ${v} ${result.major}`, 'E_MAJOR_TYPE')
52
47
  } else if (!is.number(result.minor)) {
53
48
  throw error(`${libName} minor was not an Int: ${result.minor}`, 'E_MINOR_TYPE')
54
49
  } else if (!is.number(result.patch)) {
package/src/serialize.js CHANGED
@@ -4,11 +4,7 @@ import error from '@magic/error'
4
4
  const libName = `@magic/semver.serialize:`
5
5
 
6
6
  /**
7
- * @typedef {import('./types.js').Version} Version
8
- */
9
-
10
- /**
11
- * @param {Version | unknown} v
7
+ * @param {import('./types.js').Version | unknown} v
12
8
  * @returns {string}
13
9
  */
14
10
  export const serialize = v => {
@@ -55,5 +51,7 @@ export const serialize = v => {
55
51
  demoString = `-${string}.${version}`
56
52
  }
57
53
 
58
- return `${major}.${minor}.${patch}${demoString}`
54
+ const prefix = is.str(v.v) && v.v.startsWith('v') ? 'v' : ''
55
+
56
+ return `${prefix}${major}.${minor}.${patch}${demoString}`
59
57
  }
package/types/bump.d.ts CHANGED
@@ -7,5 +7,4 @@ export function bump(
7
7
  beta?: boolean | undefined
8
8
  alpha?: boolean | undefined
9
9
  },
10
- ): Version | string
11
- export type Version = import('./types.js').Version
10
+ ): import('./types.js').Version | string
package/types/index.d.ts CHANGED
@@ -7,13 +7,15 @@ export const bump: (
7
7
  beta?: boolean | undefined
8
8
  alpha?: boolean | undefined
9
9
  },
10
- ) => Version | string
10
+ ) => import('./types.js').Version | string
11
11
  export const isBigger: (a: string, b: string) => boolean
12
- export const isSemver: (v: Version | string | unknown) => v is Version
12
+ export const isSemver: (
13
+ v: import('./types.js').Version | string | unknown,
14
+ ) => v is import('./types.js').Version
13
15
  export const isSmaller: (a: string, b: string) => boolean
14
- export const parse: (v: string) => VersionResult
15
- export const stringify: (v: Version | unknown) => string
16
- export const serialize: (v: Version | unknown) => string
16
+ export const parse: (v: string) => import('./types.js').VersionResult
17
+ export const stringify: (v: import('./types.js').Version | unknown) => string
18
+ export const serialize: (v: import('./types.js').Version | unknown) => string
17
19
  declare namespace _default {
18
20
  export { bump }
19
21
  export { isBigger }
@@ -24,3 +26,5 @@ declare namespace _default {
24
26
  export { stringify }
25
27
  }
26
28
  export default _default
29
+ export type Version = import('./types.js').Version
30
+ export type VersionResult = import('./types.js').VersionResult
@@ -1,2 +1,3 @@
1
- export function isSemver(v: Version | string | unknown): v is Version
2
- export type Version = import('./types.js').Version
1
+ export function isSemver(
2
+ v: import('./types.js').Version | string | unknown,
3
+ ): v is import('./types.js').Version
package/types/parse.d.ts CHANGED
@@ -1,3 +1 @@
1
- export function parse(v: string): VersionResult
2
- export type Version = import('./types.js').Version
3
- export type VersionResult = import('./types.js').VersionResult
1
+ export function parse(v: string): import('./types.js').VersionResult
@@ -1,2 +1 @@
1
- export function serialize(v: Version | unknown): string
2
- export type Version = import('./types.js').Version
1
+ export function serialize(v: import('./types.js').Version | unknown): string