-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ndaidong/v2.0.1
v2.0.1
- Loading branch information
Showing
9 changed files
with
206 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// release.test | ||
|
||
/* eslint-env jest */ | ||
|
||
import { | ||
existsSync, | ||
readFileSync | ||
} from 'fs' | ||
|
||
const pkg = JSON.parse(readFileSync('./package.json')) | ||
|
||
const esmFile = `${pkg.name}.esm.js` | ||
const cjsFile = `cjs/${pkg.name}.js` | ||
const minFile = `${pkg.name}.min.js` | ||
|
||
const runtest = (fname) => { | ||
const fpath = `./dist/${fname}` | ||
describe(`Validate ${fname} version output`, () => { | ||
test(`Check if ${fpath} file created`, () => { | ||
expect(existsSync(fpath)).toBeTruthy() | ||
}) | ||
const constent = readFileSync(fpath, 'utf8') | ||
const lines = constent.split('\n') | ||
test('Check if file meta contains package info', () => { | ||
expect(lines[0].includes(`${pkg.name}@${pkg.version}`)).toBeTruthy() | ||
expect(lines[0].includes(pkg.author)).toBeTruthy() | ||
expect(lines[0].includes(pkg.license)).toBeTruthy() | ||
}) | ||
}) | ||
return fpath | ||
} | ||
|
||
const arr = [ | ||
esmFile, | ||
cjsFile, | ||
minFile | ||
] | ||
|
||
arr.forEach((fname) => { | ||
runtest(fname) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,43 @@ | ||
/** | ||
* average-rating@2.0.0 | ||
* built with esbuild at: 2022-01-03T14:48:10.361Z | ||
* repository: https://github.com/ndaidong/average-rating | ||
* maintainer: @ndaidong | ||
* License: MIT | ||
**/ | ||
var n=(t,e)=>{if(t===0&&e===0)return 0;let o=((t+1.9208)/(t+e)-1.96*Math.sqrt(t*e/(t+e)+.9604)/(t+e))/(1+3.8416/(t+e));return Number(o.toFixed(2))},x=t=>{let e=t.length,o=t[0],c=t[e-1],u=(1/(e-1)).toFixed(2),s=e-1;for(let r=1;r<s;r++){let l=(u*r).toFixed(2);c+=t[r]*l,o+=t[s-r]*l}return n(c,o)},d=t=>{let e=t.reduce((s,r)=>s+r,0);if(e===0)return 0;let o=0,c=1;t.forEach(s=>{o+=s*c,c++});let u=o/e;return Number(u.toFixed(1))};export{d as average,x as rate,n as score}; | ||
// average-rating@2.0.1, by @ndaidong - built with esbuild at 2022-01-04T03:58:54.537Z - published under MIT license | ||
// src/main.js | ||
var score = (p, n) => { | ||
if (p === 0 && n === 0) { | ||
return 0; | ||
} | ||
const r = ((p + 1.9208) / (p + n) - 1.96 * Math.sqrt(p * n / (p + n) + 0.9604) / (p + n)) / (1 + 3.8416 / (p + n)); | ||
return Number(r.toFixed(2)); | ||
}; | ||
var rate = (rating) => { | ||
const size = rating.length; | ||
let n = rating[0]; | ||
let p = rating[size - 1]; | ||
const step = (1 / (size - 1)).toFixed(2); | ||
const totalStep = size - 1; | ||
for (let i = 1; i < totalStep; i++) { | ||
const ep = (step * i).toFixed(2); | ||
p += rating[i] * ep; | ||
n += rating[totalStep - i] * ep; | ||
} | ||
return score(p, n); | ||
}; | ||
var average = (rating) => { | ||
const total = rating.reduce((prev, current) => { | ||
return prev + current; | ||
}, 0); | ||
if (total === 0) { | ||
return 0; | ||
} | ||
let sum = 0; | ||
let k = 1; | ||
rating.forEach((item) => { | ||
sum += item * k; | ||
k++; | ||
}); | ||
const r = sum / total; | ||
return Number(r.toFixed(1)); | ||
}; | ||
export { | ||
average, | ||
rate, | ||
score | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,74 @@ | ||
/** | ||
* average-rating@2.0.0 | ||
* built with esbuild at: 2022-01-03T14:48:10.361Z | ||
* repository: https://github.com/ndaidong/average-rating | ||
* maintainer: @ndaidong | ||
* License: MIT | ||
**/ | ||
var l=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var h=t=>l(t,"__esModule",{value:!0});var i=(t,e)=>{for(var o in e)l(t,o,{get:e[o],enumerable:!0})},m=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of f(e))!F.call(t,r)&&(o||r!=="default")&&l(t,r,{get:()=>e[r],enumerable:!(s=d(e,r))||s.enumerable});return t};var a=(t=>(e,o)=>t&&t.get(e)||(o=m(h({}),e,1),t&&t.set(e,o),o))(typeof WeakMap!="undefined"?new WeakMap:0);var k={};i(k,{average:()=>N,rate:()=>b,score:()=>x});var x=(t,e)=>{if(t===0&&e===0)return 0;let o=((t+1.9208)/(t+e)-1.96*Math.sqrt(t*e/(t+e)+.9604)/(t+e))/(1+3.8416/(t+e));return Number(o.toFixed(2))},b=t=>{let e=t.length,o=t[0],s=t[e-1],r=(1/(e-1)).toFixed(2),u=e-1;for(let c=1;c<u;c++){let n=(r*c).toFixed(2);s+=t[c]*n,o+=t[u-c]*n}return x(s,o)},N=t=>{let e=t.reduce((u,c)=>u+c,0);if(e===0)return 0;let o=0,s=1;t.forEach(u=>{o+=u*s,s++});let r=o/e;return Number(r.toFixed(1))};module.exports=a(k);0&&(module.exports={average,rate,score}); | ||
// average-rating@2.0.1, by @ndaidong - built with esbuild at 2022-01-04T03:58:54.537Z - published under MIT license | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __reExport = (target, module2, copyDefault, desc) => { | ||
if (module2 && typeof module2 === "object" || typeof module2 === "function") { | ||
for (let key of __getOwnPropNames(module2)) | ||
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default")) | ||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); | ||
} | ||
return target; | ||
}; | ||
var __toCommonJS = /* @__PURE__ */ ((cache) => { | ||
return (module2, temp) => { | ||
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp); | ||
}; | ||
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0); | ||
|
||
// src/main.js | ||
var main_exports = {}; | ||
__export(main_exports, { | ||
average: () => average, | ||
rate: () => rate, | ||
score: () => score | ||
}); | ||
var score = (p, n) => { | ||
if (p === 0 && n === 0) { | ||
return 0; | ||
} | ||
const r = ((p + 1.9208) / (p + n) - 1.96 * Math.sqrt(p * n / (p + n) + 0.9604) / (p + n)) / (1 + 3.8416 / (p + n)); | ||
return Number(r.toFixed(2)); | ||
}; | ||
var rate = (rating) => { | ||
const size = rating.length; | ||
let n = rating[0]; | ||
let p = rating[size - 1]; | ||
const step = (1 / (size - 1)).toFixed(2); | ||
const totalStep = size - 1; | ||
for (let i = 1; i < totalStep; i++) { | ||
const ep = (step * i).toFixed(2); | ||
p += rating[i] * ep; | ||
n += rating[totalStep - i] * ep; | ||
} | ||
return score(p, n); | ||
}; | ||
var average = (rating) => { | ||
const total = rating.reduce((prev, current) => { | ||
return prev + current; | ||
}, 0); | ||
if (total === 0) { | ||
return 0; | ||
} | ||
let sum = 0; | ||
let k = 1; | ||
rating.forEach((item) => { | ||
sum += item * k; | ||
k++; | ||
}); | ||
const r = sum / total; | ||
return Number(r.toFixed(1)); | ||
}; | ||
module.exports = __toCommonJS(main_exports); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
average, | ||
rate, | ||
score | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "average-rating-cjs", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"main": "./average-rating.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// eval.js | ||
|
||
import { | ||
score, | ||
rate, | ||
average | ||
} from './src/main.js' | ||
|
||
const scoring = [80, 20] | ||
const rating = [134055, 57472, 143135, 365957, 1448459] | ||
|
||
console.log(`score(${scoring.join(', ')}) // => ${score(...scoring)}`) | ||
console.log(`average([${rating.join(', ')}]) // => ${average(rating)}`) | ||
console.log(`rate([${rating.join(', ')}]) // => ${rate(rating)}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters