@shipload/sdk 1.0.0-next.30 → 1.0.0-next.31

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipload/sdk",
3
3
  "description": "SDKs for Shipload",
4
- "version": "1.0.0-next.30",
4
+ "version": "1.0.0-next.31",
5
5
  "homepage": "https://github.com/shipload/toolkit/tree/master/packages/sdk",
6
6
  "repository": {
7
7
  "type": "git",
@@ -144,7 +144,7 @@ export {
144
144
 
145
145
  export {hash, hash512} from './utils/hash'
146
146
  export {validateDisplayName, normalizeDisplayName} from './utils/display-name'
147
- export type {DisplayNameResult} from './utils/display-name'
147
+ export type {DisplayNameResult, ValidateDisplayNameOptions} from './utils/display-name'
148
148
 
149
149
  export {
150
150
  distanceBetweenCoordinates,
@@ -42,10 +42,19 @@ export function normalizeDisplayName(input: string): string {
42
42
  return input.slice(start, end)
43
43
  }
44
44
 
45
- export function validateDisplayName(input: string): DisplayNameResult {
45
+ export interface ValidateDisplayNameOptions {
46
+ allowEmpty?: boolean
47
+ }
48
+
49
+ export function validateDisplayName(
50
+ input: string,
51
+ opts: ValidateDisplayNameOptions = {}
52
+ ): DisplayNameResult {
46
53
  const name = normalizeDisplayName(input)
47
54
 
48
- if (name.length === 0) return {valid: false, reason: 'empty', name}
55
+ if (name.length === 0) {
56
+ return opts.allowEmpty ? {valid: true, name} : {valid: false, reason: 'empty', name}
57
+ }
49
58
  if (textEncoder.encode(name).length > MAX_DISPLAY_NAME_BYTES) {
50
59
  return {valid: false, reason: 'too_long', name}
51
60
  }