js sdk: expose type.describe() for convenience (#1667)

This commit is contained in:
Aaron Boodman
2016-05-27 14:08:34 -07:00
parent 8eb6167976
commit 18838b7c2a
3 changed files with 18 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@attic/noms",
"version": "41.3.0",
"version": "41.4.0",
"description": "Noms JS SDK",
"repository": "https://github.com/attic-labs/noms",
"main": "dist/commonjs/noms.js",

View File

@@ -121,4 +121,16 @@ suite('Type', () => {
assertValid('a_');
assertValid('a0_');
});
test('type.describe', () => {
// This is tested exaustively as part of HRS, just testing here that
// type.describe() is present and works.
[
[numberType, 'Number'],
[stringType, 'String'],
[makeSetType(numberType), 'Set<Number>'],
].forEach(([t, desc]) => {
assert.equal(t.describe(), desc);
});
});
});

View File

@@ -8,6 +8,7 @@ import {isPrimitiveKind, Kind} from './noms-kind.js';
import {ValueBase} from './value.js';
import type Value from './value.js';
import {compare, equals} from './compare.js';
import {describeType} from './encode-human-readable.js';
export interface TypeDesc {
kind: NomsKind;
@@ -142,6 +143,10 @@ export class Type<T: TypeDesc> extends ValueBase {
invariant(this._desc instanceof CompoundDesc);
return this._desc.elemTypes;
}
describe(): string {
return describeType(this);
}
}
function buildType<T: TypeDesc>(desc: T): Type<T> {