Skip to content

Commit

Permalink
feat: add create override
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Aug 22, 2023
1 parent 9de91e1 commit 3df3a83
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"trailingComma": "none",
"arrowParens": "always",
"printWidth": 80,
"printWidth": 70,
"bracketSpacing": true,
"jsxBracketSameLine": true,
"tabWidth": 2,
Expand Down
29 changes: 23 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ else if (freeModule) {
var EDGE_DOT_RE = /^\.|\.$/g;
var POS1 = '.$1';
var EMP = '';
var getType = function (obj) {
return Object.prototype.toString
.call(obj)
.slice(8, -1)
.toLowerCase();
};
var normalize = function (path) {
return path
.replace(INDEXES_PATH_RE, POS1)
Expand Down Expand Up @@ -122,7 +128,12 @@ else if (freeModule) {
var result;
for (key in inObject) {
if (hasOwn.call(inObject, key)) {
result = inCallback.call(inContext, key, inObject[key], inObject);
result = inCallback.call(
inContext,
key,
inObject[key],
inObject
);
if (result === nx.BREAKER) {
break;
}
Expand All @@ -134,8 +145,13 @@ else if (freeModule) {
var key, length;
var iterator = function (inKey, inValue, inIsArray) {
return (
inCallback.call(inContext, inKey, inValue, inTarget, inIsArray) ===
nx.BREAKER
inCallback.call(
inContext,
inKey,
inValue,
inTarget,
inIsArray
) === nx.BREAKER
);
};

Expand Down Expand Up @@ -252,13 +268,14 @@ else if (freeModule) {

nx.createOverload = function () {
var fnCacheMap = {};

function overload() {
var args = Array.prototype.slice.call(arguments);
var key = args.map((item) => typeof item).join();
var key = args.map(getType).join();
var fn = fnCacheMap[key];
if (!fn) {
throw new Error('No matching function, parameter type: [' + key + ']');
throw new Error(
'No matching function, parameter type: [' + key + ']'
);
}
return fn.apply(this, args);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 23 additions & 6 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
var EDGE_DOT_RE = /^\.|\.$/g;
var POS1 = '.$1';
var EMP = '';
var getType = function (obj) {
return Object.prototype.toString
.call(obj)
.slice(8, -1)
.toLowerCase();
};
var normalize = function (path) {
return path
.replace(INDEXES_PATH_RE, POS1)
Expand Down Expand Up @@ -64,7 +70,12 @@
var result;
for (key in inObject) {
if (hasOwn.call(inObject, key)) {
result = inCallback.call(inContext, key, inObject[key], inObject);
result = inCallback.call(
inContext,
key,
inObject[key],
inObject
);
if (result === nx.BREAKER) {
break;
}
Expand All @@ -76,8 +87,13 @@
var key, length;
var iterator = function (inKey, inValue, inIsArray) {
return (
inCallback.call(inContext, inKey, inValue, inTarget, inIsArray) ===
nx.BREAKER
inCallback.call(
inContext,
inKey,
inValue,
inTarget,
inIsArray
) === nx.BREAKER
);
};

Expand Down Expand Up @@ -194,13 +210,14 @@

nx.createOverload = function () {
var fnCacheMap = {};

function overload() {
var args = Array.prototype.slice.call(arguments);
var key = args.map((item) => typeof item).join();
var key = args.map(getType).join();
var fn = fnCacheMap[key];
if (!fn) {
throw new Error('No matching function, parameter type: [' + key + ']');
throw new Error(
'No matching function, parameter type: [' + key + ']'
);
}
return fn.apply(this, args);
}
Expand Down

0 comments on commit 3df3a83

Please sign in to comment.