本文整理汇总了TypeScript中@ephox/katamari.Result.error方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Result.error方法的具体用法?TypeScript Result.error怎么用?TypeScript Result.error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ephox/katamari.Result
的用法示例。
在下文中一共展示了Result.error方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
const cGetDialogLabelId = Chain.binder((dialogE: Element) => {
if (Attr.has(dialogE, 'aria-labelledby')) {
const labelId = Attr.get(dialogE, 'aria-labelledby');
return labelId.length > 0 ? Result.value(labelId) : Result.error('Dialog has zero length aria-labelledby attribute');
} else {
return Result.error('Dialog has no aria-labelledby attribute');
}
});
示例2: load
return Future.nu(function (resolve) {
load(
url,
Fun.compose(resolve, Fun.constant(Result.value(url))),
Fun.compose(resolve, Fun.constant(Result.error(url)))
);
});
示例3:
const extractGlobal = (url: string): Result<Record<string, any>, any> => {
if (Global.tinymce[GLOBAL_NAME]) {
const result = Result.value(Global.tinymce[GLOBAL_NAME]);
delete Global.tinymce[GLOBAL_NAME];
return result;
} else {
return Result.error(`URL ${url} did not contain the expected format for emoticons`);
}
};
示例4:
return Chain.binder(function (_) {
const tableElm = Element.fromHtml(html);
const startElm = Hierarchy.follow(tableElm, startPath).getOrDie();
const endElm = Hierarchy.follow(tableElm, endPath).getOrDie();
return SimpleTableModel.subsection(SimpleTableModel.fromDom(tableElm), startElm, endElm).fold(
Fun.constant(Result.error('Failed to get the subsection')),
Result.value
);
});
示例5:
Chain.binder((rect: ClientRect) => {
const middle = { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
const range = document.caretRangeFromPoint(middle.x, middle.y);
if (! range) {
return Result.error('Could not find a range at coordinate: (' + middle.x + ', ' + middle.y + ')');
} else {
return SelectorExists.closest(Element.fromDom(range.startContainer), selector) ? Result.value(rect) : Result.error('Range was not within: "' + selector + '". Are you sure that it is on top of the dialog?');
}
})
示例6: function
export const parseSize = function (sizeText: string): Result<Size, string> {
const numPattern = /^\s*(\d+(?:\.\d+)?)\s*(|cm|mm|in|px|pt|pc|em|ex|ch|rem|vw|vh|vmin|vmax|%)\s*$/;
const match = numPattern.exec(sizeText);
if (match !== null) {
const value = parseFloat(match[1]);
const unit = match[2] as SizeUnit;
return Result.value({ value, unit });
} else {
return Result.error(sizeText);
}
};
示例7: parseSize
UnitTest.test('SizeInputParsingTest', () => {
const check = (expected: Result<Size, string>, text: string) => {
const result = parseSize(text);
expected.fold((err) => {
result.fold((resultErr) => {
assert.eq(err, resultErr);
}, (resultValue) => {
assert.fail('parseSize should have failed but succeeded with value:\n' + JSON.stringify(resultValue));
});
}, (value: Size) => {
result.fold((resultErr) => {
assert.fail('parseSize should have succeeded but failed with err: "' + resultErr + '"');
}, (resultValue) => {
assert.eq(value, resultValue);
});
});
};
check(Result.error(''), '');
check(Result.error('px'), 'px');
check(Result.error('a'), 'a');
check(Result.error('blah'), 'blah');
check(Result.error('1a'), '1a');
// check negative numbers are not allowed
check(Result.error('-1px'), '-1px');
// check the empty unit
check(Result.value(nuSize(1, '')), '1');
// check various forms of padding
check(Result.value(nuSize(1, 'px')), '1px');
check(Result.value(nuSize(1, 'px')), ' 1px');
check(Result.value(nuSize(1, 'px')), '1px ');
check(Result.value(nuSize(1, 'px')), ' 1px ');
check(Result.value(nuSize(1, 'px')), ' 1 px ');
check(Result.value(nuSize(1.25, 'px')), ' 1.25 px ');
// check that all units work
Arr.each(units, (unit) => {
check(Result.error(unit), unit);
check(Result.value(nuSize(4, unit as SizeUnit)), '4' + unit);
});
const arbPad = Jsc.array(Jsc.elements(' \t'.split(''))).smap(
function (arr) { return arr.join(''); },
function (s) { return s.split(''); }
);
Jsc.property(
'Valid size strings should be parseable',
arbPad, Jsc.number(0, largeSensible), arbPad, Jsc.oneof(Jsc.elements(units)), arbPad,
function (pad1: string, nonNegNumber: number, pad2: string, unit: SizeUnit, pad3: string) {
const str = pad1 + nonNegNumber + pad2 + unit + pad3;
const parsed = parseSize(str);
const size = parsed.toOption().getOrNull();
return Jsc.eq(nuSize(nonNegNumber, unit), size);
}
);
});
示例8: getRoot
const validatingBehaviours = spec.validation.map((vl) => {
return Invalidating.config({
getRoot(input) {
return Traverse.parent(input.element());
},
invalidClass: 'tox-invalid',
validator: {
validate(input) {
const v = Representing.getValue(input);
const result = vl.validator(v);
return Future.pure(result === true ? Result.value(v) : Result.error(result));
},
validateOnLoad: vl.validateOnLoad
}
});
}).toArray();
示例9:
const cFindNthIn = (selector, n) => Chain.binder((elem: Element) => {
const matches = UiFinder.findAllIn(elem, selector);
return matches.length > 0 && n < matches.length ? Result.value(matches[n]) :
Result.error(`Could not find match ${n} of selector: ${selector}`);
});
示例10: return
const result = data.bind((dimensions) => {
return ((Type.isString(dimensions.width) || Type.isNumber(dimensions.width)) && (Type.isString(dimensions.height) || Type.isNumber(dimensions.height))) ?
Result.value({ width: String(dimensions.width), height: String(dimensions.height) }) :
Result.error(undefined);
});