Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leetcode-public-api

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leetcode-public-api - npm Package Compare versions

Comparing version 1.0.2 to 1.0.4

5

dist/index.d.ts
import { IGetLCAccount } from '../types';
/**
* Fetches and parses a LeetCode profile using username.
* @async
* @param username - Username for the LeetCode profile.
*/
export declare const getLCAccount: IGetLCAccount;
export { fetchAccount } from './lib/fetchAccount';
export { parseAccount } from './lib/parseAccount';

28

dist/leetcode-public-api.cjs.development.js

@@ -5,4 +5,2 @@ 'use strict';

var axios = require('axios');
function _regeneratorRuntime() {

@@ -340,2 +338,8 @@ _regeneratorRuntime = function () {

/**
* Fetches the HTML for a LeetCode profile using username
* @async
* @param username - Username for the LeetCode profile.
* @returns - status, statusText, and data (as html string)
*/
var fetchAccount = /*#__PURE__*/function () {

@@ -348,3 +352,3 @@ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(username) {

_context.next = 2;
return axios.get("https://leetcode.com/" + username);
return fetch("https://leetcode.com/" + username);
case 2:

@@ -363,3 +367,3 @@ resp = _context.sent;

_context.next = 7;
return resp.data;
return resp.text();
case 7:

@@ -391,2 +395,7 @@ respText = _context.sent;

var contestAttendedEnd = '</div></div></div></div>';
/**
* Parses data from HTML String of a LeetCode Profile.
* @param html - HTML string of a LeetCode profile page.
* @returns - Type safe data for the LeetCode Account
*/
var parseAccount = function parseAccount(html) {

@@ -412,2 +421,8 @@ var _html$split$, _html$split$2, _html$split$2$split$, _html$split$3, _html$split$3$split$, _html$split$4, _html$split$4$split$;

};
/**
* Helper for parseAccount function, to make the data type-safe.
* @private
* @param user - Raw JSON response from parsing of the HTML.
* @returns - Type safe data for the LeetCode Account
*/
var typecastResponse = function typecastResponse(user) {

@@ -424,2 +439,7 @@ var transformed_user = user.reduce(function (acc, u) {

/**
* Fetches and parses a LeetCode profile using username.
* @async
* @param username - Username for the LeetCode profile.
*/
var getLCAccount = /*#__PURE__*/function () {

@@ -426,0 +446,0 @@ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(username) {

2

dist/leetcode-public-api.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("axios");function e(){e=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",c=a.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var a=Object.create((e&&e.prototype instanceof p?e:p).prototype),i=new O(n||[]);return o(a,"_invoke",{value:L(t,r,i)}),a}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var h={};function p(){}function d(){}function v(){}var y={};s(y,i,(function(){return this}));var g=Object.getPrototypeOf,x=g&&g(g(j([])));x&&x!==r&&n.call(x,i)&&(y=x);var m=v.prototype=p.prototype=Object.create(y);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){function r(o,a,i,u){var c=f(t[o],t,a);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,i,u)}),(function(t){r("throw",t,i,u)})):e.resolve(l).then((function(t){s.value=t,i(s)}),(function(t){return r("throw",t,i,u)}))}u(c.arg)}var a;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return a=a?a.then(o,o):o()}})}function L(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var u=k(i,r);if(u){if(u===h)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function k(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,k(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,h;var a=o.arg;return a?a.done?(e[t.resultName]=a.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function _(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function j(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:T}}function T(){return{value:void 0,done:!0}}return d.prototype=v,o(m,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:d,configurable:!0}),d.displayName=s(v,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,s(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},w(b.prototype),s(b.prototype,u,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new b(l(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},w(m),s(m,c,"Generator"),s(m,i,(function(){return this})),s(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=j,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(_),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,h):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),_(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;_(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},t}function r(t,e,r,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function n(t){return function(){var e=this,n=arguments;return new Promise((function(o,a){var i=t.apply(e,n);function u(t){r(i,o,a,u,c,"next",t)}function c(t){r(i,o,a,u,c,"throw",t)}u(void 0)}))}}var o=function(){var r=n(e().mark((function r(n){var o;return e().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.get("https://leetcode.com/"+n);case 2:if(200===(o=e.sent).status){e.next=5;break}return e.abrupt("return",{status:o.status,statusText:o.statusText,data:null});case 5:return e.next=7,o.data;case 7:return e.abrupt("return",{status:o.status,statusText:o.statusText,data:e.sent});case 9:case"end":return e.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}(),a=function(t){var e,r,n,o,a,u,c,s=[];JSON.parse(null==(e=t.split('<script id="__NEXT_DATA__" type="application/json">')[1])?void 0:e.split("<\/script>")[0]).props.pageProps.dehydratedState.queries.forEach((function(t){t.state&&t.state.data&&t.state.data.matchedUser&&s.push(t.state.data.matchedUser)}));var l=parseInt(null==(r=t.split('Attended</div><div class="text-label-1 dark:text-dark-label-1 font-medium leading-[22px]">')[1])||null==(n=r.split("</div></div></div></div>")[0])?void 0:n.replace(/,/g,""))||0,f=parseInt(null==(o=t.split('Contest Rating</div><div class="text-label-1 dark:text-dark-label-1 flex items-center text-2xl">')[1])||null==(a=o.split('</div></div><div class="mr-4"><div class="text-label-3 dark:text-dark-label-3">')[0])?void 0:a.replace(/,/g,""))||0,h=parseInt(null==(u=t.split('Global Ranking</div><div class="text-label-1 dark:text-dark-label-1 font-medium leading-[22px]">')[1])||null==(c=u.split('<span class="text-label-4 dark:text-dark-label-4">/\x3c!-- --\x3e')[0])?void 0:c.replace(/,/g,""))||0;return s.push({contestAttended:l,contestRating:f,contestRanking:h}),i(s)},i=function(t){return t.reduce((function(t,e){for(var r=0,n=Object.keys(e);r<n.length;r++){var o=n[r];t[o]=e[o]}return t}),{})},u=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,o(r);case 2:if(null==(n=t.sent).data){t.next=5;break}return t.abrupt("return",{status:n.status,statusText:n.statusText,data:a(n.data)});case 5:return t.abrupt("return",{status:n.status,statusText:n.statusText,data:null});case 6:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();exports.fetchAccount=o,exports.getLCAccount=u,exports.parseAccount=a;
"use strict";function t(){t=function(){return e};var e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",c=a.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var a=Object.create((e&&e.prototype instanceof p?e:p).prototype),i=new O(n||[]);return o(a,"_invoke",{value:L(t,r,i)}),a}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=l;var h={};function p(){}function d(){}function v(){}var y={};s(y,i,(function(){return this}));var g=Object.getPrototypeOf,x=g&&g(g(j([])));x&&x!==r&&n.call(x,i)&&(y=x);var m=v.prototype=p.prototype=Object.create(y);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){function r(o,a,i,u){var c=f(t[o],t,a);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,i,u)}),(function(t){r("throw",t,i,u)})):e.resolve(l).then((function(t){s.value=t,i(s)}),(function(t){return r("throw",t,i,u)}))}u(c.arg)}var a;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return a=a?a.then(o,o):o()}})}function L(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var u=k(i,r);if(u){if(u===h)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function k(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,k(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,h;var a=o.arg;return a?a.done?(e[t.resultName]=a.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,h):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,h)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function _(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function j(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:T}}function T(){return{value:void 0,done:!0}}return d.prototype=v,o(m,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:d,configurable:!0}),d.displayName=s(v,c,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,s(t,c,"GeneratorFunction")),t.prototype=Object.create(m),t},e.awrap=function(t){return{__await:t}},w(b.prototype),s(b.prototype,u,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var i=new b(l(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},w(m),s(m,c,"Generator"),s(m,i,(function(){return this})),s(m,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=j,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(_),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),c=n.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,h):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),_(r),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;_(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:j(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),h}},e}function e(t,e,r,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(o,a){var i=t.apply(r,n);function u(t){e(i,o,a,u,c,"next",t)}function c(t){e(i,o,a,u,c,"throw",t)}u(void 0)}))}}Object.defineProperty(exports,"__esModule",{value:!0});var n=function(){var e=r(t().mark((function e(r){var n;return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch("https://leetcode.com/"+r);case 2:if(200===(n=t.sent).status){t.next=5;break}return t.abrupt("return",{status:n.status,statusText:n.statusText,data:null});case 5:return t.next=7,n.text();case 7:return t.abrupt("return",{status:n.status,statusText:n.statusText,data:t.sent});case 9:case"end":return t.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),o=function(t){var e,r,n,o,i,u,c,s=[];JSON.parse(null==(e=t.split('<script id="__NEXT_DATA__" type="application/json">')[1])?void 0:e.split("<\/script>")[0]).props.pageProps.dehydratedState.queries.forEach((function(t){t.state&&t.state.data&&t.state.data.matchedUser&&s.push(t.state.data.matchedUser)}));var l=parseInt(null==(r=t.split('Attended</div><div class="text-label-1 dark:text-dark-label-1 font-medium leading-[22px]">')[1])||null==(n=r.split("</div></div></div></div>")[0])?void 0:n.replace(/,/g,""))||0,f=parseInt(null==(o=t.split('Contest Rating</div><div class="text-label-1 dark:text-dark-label-1 flex items-center text-2xl">')[1])||null==(i=o.split('</div></div><div class="mr-4"><div class="text-label-3 dark:text-dark-label-3">')[0])?void 0:i.replace(/,/g,""))||0,h=parseInt(null==(u=t.split('Global Ranking</div><div class="text-label-1 dark:text-dark-label-1 font-medium leading-[22px]">')[1])||null==(c=u.split('<span class="text-label-4 dark:text-dark-label-4">/\x3c!-- --\x3e')[0])?void 0:c.replace(/,/g,""))||0;return s.push({contestAttended:l,contestRating:f,contestRanking:h}),a(s)},a=function(t){return t.reduce((function(t,e){for(var r=0,n=Object.keys(e);r<n.length;r++){var o=n[r];t[o]=e[o]}return t}),{})},i=function(){var e=r(t().mark((function e(r){var a;return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,n(r);case 2:if(null==(a=t.sent).data){t.next=5;break}return t.abrupt("return",{status:a.status,statusText:a.statusText,data:o(a.data)});case 5:return t.abrupt("return",{status:a.status,statusText:a.statusText,data:null});case 6:case"end":return t.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();exports.fetchAccount=n,exports.getLCAccount=i,exports.parseAccount=o;
//# sourceMappingURL=leetcode-public-api.cjs.production.min.js.map

@@ -1,3 +0,1 @@

import axios from 'axios';
function _regeneratorRuntime() {

@@ -335,2 +333,8 @@ _regeneratorRuntime = function () {

/**
* Fetches the HTML for a LeetCode profile using username
* @async
* @param username - Username for the LeetCode profile.
* @returns - status, statusText, and data (as html string)
*/
var fetchAccount = /*#__PURE__*/function () {

@@ -343,3 +347,3 @@ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(username) {

_context.next = 2;
return axios.get("https://leetcode.com/" + username);
return fetch("https://leetcode.com/" + username);
case 2:

@@ -358,3 +362,3 @@ resp = _context.sent;

_context.next = 7;
return resp.data;
return resp.text();
case 7:

@@ -386,2 +390,7 @@ respText = _context.sent;

var contestAttendedEnd = '</div></div></div></div>';
/**
* Parses data from HTML String of a LeetCode Profile.
* @param html - HTML string of a LeetCode profile page.
* @returns - Type safe data for the LeetCode Account
*/
var parseAccount = function parseAccount(html) {

@@ -407,2 +416,8 @@ var _html$split$, _html$split$2, _html$split$2$split$, _html$split$3, _html$split$3$split$, _html$split$4, _html$split$4$split$;

};
/**
* Helper for parseAccount function, to make the data type-safe.
* @private
* @param user - Raw JSON response from parsing of the HTML.
* @returns - Type safe data for the LeetCode Account
*/
var typecastResponse = function typecastResponse(user) {

@@ -419,2 +434,7 @@ var transformed_user = user.reduce(function (acc, u) {

/**
* Fetches and parses a LeetCode profile using username.
* @async
* @param username - Username for the LeetCode profile.
*/
var getLCAccount = /*#__PURE__*/function () {

@@ -421,0 +441,0 @@ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(username) {

import { IFetchAccount } from '../../types';
/**
* Fetches the HTML for a LeetCode profile using username
* @async
* @param username - Username for the LeetCode profile.
* @returns - status, statusText, and data (as html string)
*/
export declare const fetchAccount: IFetchAccount;

@@ -1,3 +0,7 @@

import { ILeetCodeUser, IParseAccount } from '../../types';
import { IParseAccount } from '../../types';
/**
* Parses data from HTML String of a LeetCode Profile.
* @param html - HTML string of a LeetCode profile page.
* @returns - Type safe data for the LeetCode Account
*/
export declare const parseAccount: IParseAccount;
export declare const typecastResponse: (user: any[]) => ILeetCodeUser;
{
"name": "leetcode-public-api",
"version": "1.0.2",
"version": "1.0.4",
"license": "MIT",

@@ -51,2 +51,4 @@ "author": "Husain Shahid Rao",

"devDependencies": {
"@size-limit/esbuild": "^8.2.4",
"@size-limit/esbuild-why": "^8.2.4",
"@size-limit/preset-small-lib": "^8.2.4",

@@ -60,5 +62,8 @@ "@tsconfig/recommended": "^1.0.2",

},
"dependencies": {
"axios": "^1.4.0"
}
"dependencies": {},
"keywords": [
"leetcode",
"leetcode-api",
"scraper"
]
}
# LeetCode Public API
An unofficial public API for LeetCode with full type support!
An unofficial public API for LeetCode with full type support and zero dependencies!
**Requires NodeJS >= 17.5**
![LeetCode Public API](https://github.com/husain3012/leetcode-public-api/assets/49821470/3b30b00f-e39f-4dea-9aea-0e71557ff669)

@@ -23,12 +24,14 @@

- [📝 Table of Contents](#-table-of-contents)
- [🧐 About ](#-about-)
- [🏁 Getting Started ](#-getting-started-)
- [Installing](#installing)
- [Usage ](#usage-)
- [Functions](#functions)
- [LeetCode Public API](#leetcode-public-api)
- [📝 Table of Contents](#-table-of-contents)
- [🧐 About ](#-about-)
- [🏁 Getting Started ](#-getting-started-)
- [Installing](#installing)
- [Usage ](#usage-)
- [Example Response](#example-response)
- [Functions](#functions)
## 🧐 About <a name = "about"></a>
I small package written in typescript to fetch public stats of a LeetCode profile. This API makes call to `leetcode.com` so abusing it might lead to rate limiting your IP.
I small package written in typescript to fetch public stats of a LeetCode profile. This API makes call to `leetcode.com` using built in ```fetch```, so abusing it might lead to rate limiting your IP, and using it directly in browser may hit you with CORS.
## 🏁 Getting Started <a name = "getting_started"></a>

@@ -38,2 +41,3 @@

Compatible with JavaScript and Node JS 18 environments.

@@ -67,10 +71,357 @@ - Using yarn

## Functions
## Example Response
```typescript
fetchAccount = (username:string) => Promise<status:number, statusText:string, data:string|null>
```javascript
{
status:200,
statusText:"OK",
data:{
"contestBadge": null,
"username": "husain3012",
"githubUrl": "https://github.com/husain3012",
"twitterUrl": null,
"linkedinUrl": null,
"profile": {
"ranking": 289606,
"userAvatar": "https://assets.leetcode.com/users/avatars/avatar_1682222071.png",
"realName": "Husain Shahid",
"aboutMe": "",
"school": null,
"websites": [
"husainshahidrao.com"
],
"countryName": null,
"company": null,
"jobTitle": null,
"skillTags": [],
"postViewCount": 81,
"postViewCountDiff": 0,
"reputation": 0,
"reputationDiff": 0,
"solutionCount": 4,
"solutionCountDiff": 0,
"categoryDiscussCount": 0,
"categoryDiscussCountDiff": 0
},
"activeBadge": {
"displayName": "Feb LeetCoding Challenge",
"icon": "/static/images/badges/dcc-2022-2.png"
},
"languageProblemCount": [
{
"languageName": "C++",
"problemsSolved": 226
},
{
"languageName": "Elixir",
"problemsSolved": 2
},
{
"languageName": "Python",
"problemsSolved": 1
},
{
"languageName": "C",
"problemsSolved": 1
},
{
"languageName": "Python3",
"problemsSolved": 1
}
],
"tagProblemCounts": {
"advanced": [
{
"tagName": "Dynamic Programming",
"tagSlug": "dynamic-programming",
"problemsSolved": 35
},
{
"tagName": "Backtracking",
"tagSlug": "backtracking",
"problemsSolved": 8
},
{
"tagName": "Monotonic Stack",
"tagSlug": "monotonic-stack",
"problemsSolved": 8
},
{
"tagName": "Divide and Conquer",
"tagSlug": "divide-and-conquer",
"problemsSolved": 7
},
{
"tagName": "Union Find",
"tagSlug": "union-find",
"problemsSolved": 7
},
{
"tagName": "Quickselect",
"tagSlug": "quickselect",
"problemsSolved": 2
},
{
"tagName": "Trie",
"tagSlug": "trie",
"problemsSolved": 2
},
{
"tagName": "Topological Sort",
"tagSlug": "topological-sort",
"problemsSolved": 2
},
{
"tagName": "Rolling Hash",
"tagSlug": "rolling-hash",
"problemsSolved": 1
},
{
"tagName": "Bitmask",
"tagSlug": "bitmask",
"problemsSolved": 1
}
],
"intermediate": [
{
"tagName": "Hash Table",
"tagSlug": "hash-table",
"problemsSolved": 43
},
{
"tagName": "Math",
"tagSlug": "math",
"problemsSolved": 34
},
{
"tagName": "Binary Search",
"tagSlug": "binary-search",
"problemsSolved": 24
},
{
"tagName": "Depth-First Search",
"tagSlug": "depth-first-search",
"problemsSolved": 17
},
{
"tagName": "Greedy",
"tagSlug": "greedy",
"problemsSolved": 16
},
{
"tagName": "Breadth-First Search",
"tagSlug": "breadth-first-search",
"problemsSolved": 16
},
{
"tagName": "Tree",
"tagSlug": "tree",
"problemsSolved": 11
},
{
"tagName": "Bit Manipulation",
"tagSlug": "bit-manipulation",
"problemsSolved": 10
},
{
"tagName": "Binary Tree",
"tagSlug": "binary-tree",
"problemsSolved": 9
},
{
"tagName": "Graph",
"tagSlug": "graph",
"problemsSolved": 9
},
{
"tagName": "Sliding Window",
"tagSlug": "sliding-window",
"problemsSolved": 8
},
{
"tagName": "Recursion",
"tagSlug": "recursion",
"problemsSolved": 5
},
{
"tagName": "Design",
"tagSlug": "design",
"problemsSolved": 5
},
{
"tagName": "Ordered Set",
"tagSlug": "ordered-set",
"problemsSolved": 1
},
{
"tagName": "Randomized",
"tagSlug": "randomized",
"problemsSolved": 1
},
{
"tagName": "Iterator",
"tagSlug": "iterator",
"problemsSolved": 1
},
{
"tagName": "Brainteaser",
"tagSlug": "brainteaser",
"problemsSolved": 1
}
],
"fundamental": [
{
"tagName": "Array",
"tagSlug": "array",
"problemsSolved": 114
},
{
"tagName": "String",
"tagSlug": "string",
"problemsSolved": 51
},
{
"tagName": "Sorting",
"tagSlug": "sorting",
"problemsSolved": 31
},
{
"tagName": "Two Pointers",
"tagSlug": "two-pointers",
"problemsSolved": 30
},
{
"tagName": "Stack",
"tagSlug": "stack",
"problemsSolved": 20
},
{
"tagName": "Linked List",
"tagSlug": "linked-list",
"problemsSolved": 15
},
{
"tagName": "Matrix",
"tagSlug": "matrix",
"problemsSolved": 13
},
{
"tagName": "Simulation",
"tagSlug": "simulation",
"problemsSolved": 11
},
{
"tagName": "Queue",
"tagSlug": "queue",
"problemsSolved": 3
},
{
"tagName": "Enumeration",
"tagSlug": "enumeration",
"problemsSolved": 1
}
]
},
"userCalendar": {
"activeYears": [
2023,
2022,
2021
],
"streak": 17,
"totalActiveDays": 91,
"dccBadges": [],
"submissionCalendar": "{\"1672617600\": 4, \"1672876800\": 3, \"1673222400\": 5, \"1673395200\": 8, \"1673481600\": 7, \"1674259200\": 1, \"1674864000\": 1, \"1675036800\": 2, \"1675296000\": 14, \"1675382400\": 7, \"1675468800\": 5, \"1676678400\": 1, \"1677628800\": 3, \"1678320000\": 2, \"1678406400\": 6, \"1678492800\": 1, \"1678838400\": 2, \"1679356800\": 10, \"1679788800\": 13, \"1679875200\": 7, \"1680048000\": 5, \"1680825600\": 3, \"1680998400\": 13, \"1681257600\": 2, \"1681430400\": 5, \"1681516800\": 1, \"1681603200\": 8, \"1681689600\": 1, \"1681948800\": 7, \"1682035200\": 28, \"1682121600\": 12, \"1682208000\": 17, \"1682294400\": 4, \"1682380800\": 16, \"1682467200\": 4, \"1682553600\": 1, \"1682640000\": 2, \"1682726400\": 1, \"1682812800\": 3, \"1682899200\": 4, \"1682985600\": 3, \"1683072000\": 1, \"1683158400\": 2, \"1683244800\": 2, \"1683331200\": 1, \"1684281600\": 1, \"1685750400\": 7, \"1685836800\": 9, \"1685923200\": 14, \"1686009600\": 9, \"1686096000\": 12, \"1686182400\": 16, \"1686268800\": 9, \"1686355200\": 7, \"1655078400\": 1, \"1655337600\": 3, \"1655424000\": 7, \"1655510400\": 18, \"1655596800\": 7, \"1655683200\": 1, \"1655856000\": 7, \"1655942400\": 3, \"1656115200\": 15, \"1656288000\": 1, \"1656720000\": 1, \"1657843200\": 5, \"1664064000\": 3, \"1664409600\": 5, \"1664496000\": 13, \"1664582400\": 3, \"1665360000\": 3, \"1665446400\": 4, \"1668038400\": 8, \"1668124800\": 11, \"1668384000\": 3, \"1668470400\": 1, \"1668556800\": 8, \"1668643200\": 2, \"1668729600\": 3, \"1668816000\": 1, \"1668902400\": 16, \"1668988800\": 9, \"1669075200\": 1, \"1669161600\": 2, \"1669248000\": 2, \"1669334400\": 1, \"1669420800\": 1, \"1670284800\": 19, \"1670371200\": 1, \"1670630400\": 1, \"1672185600\": 3}"
},
"badges": [
{
"id": "1456837",
"name": "Annual Badge",
"shortName": "100 Days Badge 2022",
"displayName": "100 Days Badge 2022",
"icon": "https://leetcode.com/static/images/badges/2022/lg/2022-annual-100.png",
"hoverText": "100 Days Badge 2022",
"medal": {
"slug": "100-days-badge-2022",
"config": {
"iconGif": "https://leetcode.com/static/images/badges/2022/gif/2022-annual-100.gif",
"iconGifBackground": "https://assets.leetcode.com/static_assets/others/badge-background.png"
}
},
"creationDate": "2023-01-01",
"category": "COMPETITION"
},
{
"id": "615138",
"name": "Daily Coding Challenge",
"shortName": "Feb Badge",
"displayName": "Feb LeetCoding Challenge",
"icon": "/static/images/badges/dcc-2022-2.png",
"hoverText": "Feb LeetCoding Challenge",
"medal": {
"slug": "dcc-february-2022",
"config": {
"iconGif": "https://leetcode.com/static/images/badges/2022/gif/2022-02.gif",
"iconGifBackground": "https://assets.leetcode.com/static_assets/others/badge-background.png"
}
},
"creationDate": "2022-02-28",
"category": "DCC"
}
],
"upcomingBadges": [
{
"name": "Jun LeetCoding Challenge",
"icon": "/static/images/badges/dcc-2023-6.png",
"progress": 26
}
],
"problemsSolvedBeatsStats": [
{
"difficulty": "Easy",
"percentage": 84.35
},
{
"difficulty": "Medium",
"percentage": 88.69
},
{
"difficulty": "Hard",
"percentage": 81.17
}
],
"submitStatsGlobal": {
"acSubmissionNum": [
{
"difficulty": "All",
"count": 215
},
{
"difficulty": "Easy",
"count": 69
},
{
"difficulty": "Medium",
"count": 122
},
{
"difficulty": "Hard",
"count": 24
}
]
},
"contestAttended": 4,
"contestRating": 1481,
"contestRanking": 194463
}
}
```
```typescript
parseAccount = (profile_html:string) => ILeetCodeUser
```
## Functions
| Function | Type | Input | Output | Description |
| ------------ | ----- | ------------------------- | ------------------------------------------------------------------ | ------------------------------------------------------------------------------- |
| fetchAccount | async | ```username:string``` | ```{status:number, statusText:string, data:string\|null}``` | Fetches the HTML for a profile page |
| parseAccount | sync | ```profile_html:string``` | ```ILeetCodeUser``` | Parses and extracts info from the HTML of a profile |
| getLCAccount | async | ```username:string``` | ```{status:number, statusText:string, data:ILeetCodeUser\|null}``` | Top level function, uses fetchAccount with parseAccount to get the profile info |

@@ -6,2 +6,7 @@ import { IGetLCAccount } from '../types';

/**
* Fetches and parses a LeetCode profile using username.
* @async
* @param username - Username for the LeetCode profile.
*/
export const getLCAccount: IGetLCAccount = async (username) => {

@@ -8,0 +13,0 @@ const html = await fetchAccount(username);

@@ -1,6 +0,11 @@

import axios from 'axios';
import { IFetchAccount } from '../../types';
/**
* Fetches the HTML for a LeetCode profile using username
* @async
* @param username - Username for the LeetCode profile.
* @returns - status, statusText, and data (as html string)
*/
export const fetchAccount: IFetchAccount = async (username) => {
const resp = await axios.get(`https://leetcode.com/${username}`);
const resp = await fetch(`https://leetcode.com/${username}`);
if (resp.status !== 200) {

@@ -13,3 +18,4 @@ return {

}
const respText = await resp.data;
const respText = await resp.text();
return {

@@ -16,0 +22,0 @@ status: resp.status,

@@ -18,2 +18,7 @@ import { ILeetCodeUser, IParseAccount } from '../../types';

/**
* Parses data from HTML String of a LeetCode Profile.
* @param html - HTML string of a LeetCode profile page.
* @returns - Type safe data for the LeetCode Account
*/
export const parseAccount: IParseAccount = (html) => {

@@ -59,3 +64,9 @@ let useFullData = [];

export const typecastResponse = (user: any[]) => {
/**
* Helper for parseAccount function, to make the data type-safe.
* @private
* @param user - Raw JSON response from parsing of the HTML.
* @returns - Type safe data for the LeetCode Account
*/
const typecastResponse = (user: any[]) => {
const transformed_user = user.reduce((acc, u: any) => {

@@ -62,0 +73,0 @@ for (let key of Object.keys(u)) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc