github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/util/fixLong.ts (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  import Long from "long";
    12  
    13  // FixLong deals with the fact that a Long that doesn't exist in a proto is
    14  // returned as a constant number 0. This converts those constants back into a
    15  // Long of value 0 or returns the original Long if it already exists.
    16  export function FixLong(value: Long | number): Long {
    17    if (value as any === 0) {
    18      return Long.fromInt(0);
    19    }
    20    return value as Long;
    21  }