UNPKG

cambridge-dictionary

Version:
2 lines 6.73 kB
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports["cambridge-dictionary"]=n():e["cambridge-dictionary"]=n()}(global,function(){return function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=18)}([function(e,n){e.exports=require("@babel/runtime/regenerator")},function(e,n){e.exports=require("@babel/runtime/helpers/asyncToGenerator")},function(e,n){e.exports=require("@babel/runtime/helpers/objectSpread")},function(e,n,t){"use strict";var r=t(0),o=t.n(r),i=t(2),a=t.n(i),c=t(1),u=t.n(c),s=t(4),f=t.n(s),d=t(5),p=t.n(d),l=t(6),b=t.n(l),h=t(7),m=t.n(h),x=t(8),g=t.n(x),v=t(11),y=t.n(v),w="english";t.d(n,"a",function(){return j}),t.d(n,"b",function(){return S});var k="https://dictionary.cambridge.org",q=function(e){function n(e){var t;return f()(this,n),(t=p()(this,b()(n).call(this,e))).name="CambridgeFetchError",t}return m()(n,e),n}(g()(Error)),j=function(e){function n(e){var t;return f()(this,n),(t=p()(this,b()(n).call(this,e))).name="WordNotFound",t}return m()(n,e),n}(g()(Error));function S(e){return function(){return u()(o.a.mark(function e(n){var t,r,i,c,u,s,f=arguments;return o.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=1<f.length&&void 0!==f[1]?f[1]:{},r=a()({from:w,to:w},t),i=r.from,c=r.to,u=i!==c?"".concat(i,"-").concat(c):i,e.next=5,y()("".concat(k,"/dictionary/").concat(u,"/").concat(n),{redirect:"manual"});case 5:if(s=e.sent,300<(o=s.status)&&o<400)throw new j(n);e.next=8;break;case 8:if(s.ok){e.next=10;break}throw new q("Fail when getDictionaryHTML.");case 10:return e.abrupt("return",s.text());case 11:case"end":return e.stop()}var o},e,this)})).apply(this,arguments)}.apply(this,arguments)}},function(e,n){e.exports=require("@babel/runtime/helpers/classCallCheck")},function(e,n){e.exports=require("@babel/runtime/helpers/possibleConstructorReturn")},function(e,n){e.exports=require("@babel/runtime/helpers/getPrototypeOf")},function(e,n){e.exports=require("@babel/runtime/helpers/inherits")},function(e,n){e.exports=require("@babel/runtime/helpers/wrapNativeSuper")},function(e,n){e.exports=require("chalk")},function(e,n,t){"use strict";var r=t(0),o=t.n(r),i=t(1),a=t.n(i),c=t(3),u=t(12),s=t.n(u);function f(e){var n=s.a.load(e);return n("#dataset-cald4").find(".entry-body__el").map(function(e,t){var r=n(t);return{pos:r.find(".posgram").text(),ipa_uk:r.find(".uk .ipa").text(),ipa_us:r.find(".us .ipa").text(),senses:r.find(".sense-block").map(function(e,t){var r=n(t);return{guideWord:r.find(".guideword").children().first().text(),definations:r.find(".def-block").map(function(e,t){var r=n(t),o=r.find(".def-head"),i=r.find(".def-body");return{level:o.find(".epp-xref").text(),domain:o.find(".domain").text(),text:d(o.find(".def").text()),examples:i.find(".examp").map(function(e,t){return n(t).text()}).get().map(function(e){return e.trim()}).map(d)}}).get()}}).get()}}).get()}function d(){return(0<arguments.length&&void 0!==arguments[0]?arguments[0]:"").replace(/[\s\n|\t]+/g," ")}function p(e){return function(){return a()(o.a.mark(function e(n){var t,r;return o.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Object(c.b)(n);case 2:return t=e.sent,r=f(t),e.abrupt("return",{word:n,explanations:r});case 5:case"end":return e.stop()}},e,this)})).apply(this,arguments)}.apply(this,arguments)}t.d(n,"a",function(){return p})},function(e,n){e.exports=require("node-fetch")},function(e,n){e.exports=require("cheerio")},function(e,n){e.exports=require("yargs")},function(e,n){e.exports=require("@babel/runtime/helpers/slicedToArray")},function(e,n){e.exports=require("ora")},function(e,n){e.exports=require("word-wrap")},,function(e,n,t){"use strict";t.r(n);var r=t(0),o=t.n(r),i=t(14),a=t.n(i),c=t(1),u=t.n(c),s=t(13),f=t.n(s),d=t(15),p=t.n(d),l=t(10),b=t(3),h=t(2),m=t.n(h),x=t(9),g=t.n(x),v=t(16),y=t.n(v);function w(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},t=m()({indent:0,trimStart:!1,end:"\n"},n),r=t.indent,o=t.trimStart,i=t.end,a=y()(e,{indent:" ".repeat(r),width:process.stdout.columns-2*r}),c=o?a.trimLeft():a;process.stdout.write(c+i)}function k(e){var n=e.word,t=void 0===n?"":n,r=e.explanations,o=void 0===r?[]:r,i=o.length;w(),o.forEach(function(e,n){var r=e.pos,o=e.ipa_us,a=e.senses;1<i&&w("[".concat(n+1,"/").concat(i,"] "),{end:""}),w("".concat(g.a.bold(t)," /").concat(o,"/ ").concat(g.a.bgWhite.black(" ".concat(r,". ")))),w(),a.forEach(function(e){e.definations.forEach(function(e){var n=e.level,r=e.domain,o=e.text,i=e.examples;w(g.a.bgYellow.black(" Defination: "),{indent:2,end:""}),w(r?g.a.bgWhite.black(" [".concat(r,"] ")):"",{end:""}),w(n?" [".concat(n,"] "):""),w(),w(o,{indent:4}),w(),0<i.length&&(w("".concat(g.a.bgCyan.black(" Examples: ")),{indent:2}),w()),i.forEach(function(e){var n=e.replace(new RegExp(t,"gi"),function(e){return g.a.bold.underline.white(e)});w("- ",{indent:2,end:""}),w(n,{indent:4,trimStart:!0}),w()})})})})}function q(){return(q=u()(o.a.mark(function e(n){var t,r,i,c;return o.a.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=a()(n._,1),r=t[0],i=p()('Searching "'.concat(r,'"...')).start(),e.prev=2,e.next=5,Object(l.a)(r);case 5:c=e.sent,e.next=15;break;case 8:if(e.prev=8,e.t0=e.catch(2),e.t0 instanceof b.a)return i.fail('"'.concat(r,'" not founded!')),e.abrupt("return");e.next=13;break;case 13:return i.fail("Something went wrong!"),e.abrupt("return");case 15:i.succeed(),k(c);case 17:case"end":return e.stop()}},e,this,[[2,8]])}))).apply(this,arguments)}f.a.demandCommand(1).command("<word>","Check word meaning in dictionary",function(e){e.positional("word",{describe:"the word you want to search in cambridge dictionary"})}),function(e){q.apply(this,arguments)}(f.a.argv)}])}); //# sourceMappingURL=cli.js.map