Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
build
Browse files Browse the repository at this point in the history
Removed deprecated .load & .save Dann methods

Better regex for isEs6 function
  • Loading branch information
matiasvlevi committed Apr 29, 2022
1 parent 5ebbd59 commit cae7de6
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 315 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
## Installation
### CDN :
```html
<script src="https://cdn.jsdelivr.net/gh/matiasvlevi/dann@v2.4.1c/build/dann.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/matiasvlevi/dann@v2.4.1d/build/dann.min.js"></script>
```
### Node :
```
Expand Down
140 changes: 5 additions & 135 deletions build/dann.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! Dann.js */
const isBrowser = typeof process !== 'object';
const VERSION = 'v2.4.1c';
const VERSION = 'v2.4.1d';

/*
* Undisplayed documentation
Expand Down Expand Up @@ -2836,48 +2836,6 @@ Dann.prototype.fromJSON = function fromJSON(data) {
* @param {String} name The name of the saved directory that holds the dann model.
* @param {Function} arg2 A function to be called when the model finished loading.
*/
// Dann.prototype.load = function load(name, arg2, arg3) {
// if (isBrowser) {
// upload(name, arg2, arg3);
// } else {
// let path = './savedDanns/' + name + '/dannData.json';
// if (fs.existsSync(path)) {
// let text = fs.readFileSync(path, 'utf8');
// let xdata = JSON.parse(text);

// let newNN = xdata;
// this.applyToModel(newNN);
// if (typeof arg2 === 'function') {
// arg2(false);
// } else {
// let type = typeof arg2;
// DannError.error(
// "callback specified is not a function, the function recieved a '" +
// type +
// "' instead",
// 'Dann.prototype.load'
// );
// return;
// }
// } else {
// if (typeof arg2 === 'function') {
// arg2(true);
// } else if (typeof arg2 !== 'function') {
// let type = typeof arg2;
// DannError.error(
// 'Callback specified is not a function, the function recieved a ' +
// type +
// ' instead',
// 'Dann.prototype.load'
// );
// return;
// } else {
// DannError.error('File not found', 'Dann.prototype.load');
// return;
// }
// }
// }
// };

/*
* (Browser)
Expand All @@ -2896,94 +2854,6 @@ Dann.prototype.fromJSON = function fromJSON(data) {
* @param {String} name The name of the json file.
* @param {Object} [options] An object containing options on the save process.
*/
// Dann.prototype.save = function save(name, options) {
// let path;
// let overwritten = false;
// let report = false;
// let result = 0;
// let rstr = 'none';
// //options
// if (options !== undefined) {
// if (options.report !== undefined) {
// report = options.report;
// }
// if (options.test !== undefined) {
// if (typeof options.test === 'function') {
// let testfunc = options.test;
// result = testfunc() * 100;
// rstr = result + '%';
// } else {
// console.error('Dann Error: the test option can only be a function.');
// console.trace();
// }
// }
// }
// let dataOBJ = this.dataObject();

// if (isBrowser) {
// downloadSTR(dataOBJ, name);
// } else {
// path = './savedDanns/' + name + '/dannData.json';
// if (fs.existsSync(path)) {
// overwritten = true;
// }
// if (!fs.existsSync('./savedDanns')) {
// fs.mkdirSync('./savedDanns');
// }
// if (!fs.existsSync('./savedDanns/' + name)) {
// fs.mkdirSync('./savedDanns/' + name);
// }
// if (report === true) {
// let acts = [];
// for (let i = 1; i < this.arch.length; i++) {
// acts[i - 1] = this.Layers[i].actname;
// }
// let csvFile = [];
// csvFile.push(['Dann', 'train report']);
// csvFile.push(['Arch: ', this.arch]);
// csvFile.push(['Acts: ', acts]);
// csvFile.push(['Lr: ', this.lr]);
// csvFile.push(['Epoch:', this.epoch]);

// if (typeof options.test === 'function') {
// csvFile.push(['Accuracy:', rstr]);
// }
// csvFile.push(['Index', 'AvgLoss']);
// for (let i = 0; i < this.losses.length; i++) {
// csvFile.push([i + 1, this.losses[i]]);
// }

// w.writeToPath('./savedDanns/' + name + '/report.csv', csvFile)
// .on('error', (err) => console.error(err))
// .on('finish', () =>
// console.log(
// 'saved training report at ' + './savedDanns/' + name + '/report.csv'
// )
// );
// }

// fs.writeFileSync(path, JSON.stringify(dataOBJ));
// if (overwritten === true) {
// console.log('\x1b[32m', '');
// this.log();
// console.log(
// 'Succesfully overwritten the Dann Model at ./savedDanns/' +
// name +
// '/dannData.json '
// );
// console.log('\x1b[0m', '');
// } else {
// console.log('\x1b[32m', '');
// this.log();
// console.log(
// 'Succesfully saved the Dann Model at ./savedDanns/' +
// name +
// '/dannData.json '
// );
// console.log('\x1b[0m', '');
// }
// }
// };

/**
* @module Dann
Expand All @@ -2999,9 +2869,9 @@ Dann.prototype.fromJSON = function fromJSON(data) {
* const nn = new Dann(4, 4);
* nn.addHiddenLayer(8);
* nn.makeWeights();
* let stringFunction = nn.toFunction();
*
* // Copy & paste the string function!
* console.log(stringFunction);
* console.log(nn.toFunction());
* </code>
*/
Dann.prototype.toFunction = function toFunction(name = 'myDannFunction') {
Expand Down Expand Up @@ -3146,7 +3016,7 @@ function minify(string) {
* Detect if a function is an ES6 function.
*/
function isES6(fn) {
let s = fn.match(/([a-z]=>).*/gm);
let s = fn.match(/([a-z] {0,1}=> {0,1}).*/gm);
if (s !== null) return true;
return false;
}
Expand All @@ -3158,7 +3028,7 @@ function toES6(fn) {
if (isES6(fn)) return fn;

let args = fn.match(/\(.*?\)/gm)[0];
let matches = fn.split('\n').join('').match(/{.*?}/);
let matches = fn.match(/{.*?}/);
let implementation = '';

if (matches !== null) {
Expand Down
2 changes: 1 addition & 1 deletion build/dann.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/yuidoc-dannjs-theme/partials/readme.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<h2 id="installation">Installation</h2>
<h3 id="cdn-">CDN :</h3>
<pre><code class="rmcode html">&lt;script src=&quot;https://cdn.jsdelivr.net/gh/matiasvlevi/dann@v2.4.1c/build/dann.min.js&quot;&gt;&lt;/script&gt;</code></pre>
<pre><code class="rmcode html">&lt;script src=&quot;https://cdn.jsdelivr.net/gh/matiasvlevi/dann@v2.4.1d/build/dann.min.js&quot;&gt;&lt;/script&gt;</code></pre>
<h3 id="node-">Node :</h3>
<pre><code>npm i dannjs</code></pre><p><a href="https://www.npmjs.com/package/dannjs">dannjs on npmjs.com</a>
<br/><br/></p>
Expand Down
91 changes: 54 additions & 37 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ module.exports = (grunt) => {
},
terser: {
src: {
files: [{
src: 'build/dann.js',
dest: 'build/dann.min.js',
}, ],
files: [
{
src: 'build/dann.js',
dest: 'build/dann.min.js',
},
],
},
},
clean: {
Expand All @@ -87,8 +89,8 @@ module.exports = (grunt) => {
},
makechangelog: {
targets: {
path: 'CHANGES.md'
}
path: 'CHANGES.md',
},
},
yuidoc: {
compile: {
Expand All @@ -113,10 +115,12 @@ module.exports = (grunt) => {
},
rename: {
main: {
files: [{
src: ['docs/documentation/markdown/README.html'],
dest: 'docs/' + theme + '/partials/readme.handlebars',
}, ],
files: [
{
src: ['docs/documentation/markdown/README.html'],
dest: 'docs/' + theme + '/partials/readme.handlebars',
},
],
},
},
sampleTest: {
Expand All @@ -138,15 +142,18 @@ module.exports = (grunt) => {
'docs/documentation/classes/*.html',
],
overwrite: true,
replacements: [{
from: /<li><a class="type" href="\.*\/classes\/Add\.html">Add<\/a><\/li>/gm,
to: '',
}, ],
replacements: [
{
from: /<li><a class="type" href="\.*\/classes\/Add\.html">Add<\/a><\/li>/gm,
to: '',
},
],
},
index: {
src: ['docs/documentation/*.html'],
overwrite: true,
replacements: [{
replacements: [
{
from: /\.\.\/index\.html/gm,
to: '/',
},
Expand All @@ -159,15 +166,18 @@ module.exports = (grunt) => {
constant: {
src: ['src/io/head.js'],
overwrite: true,
replacements: [{
from: /VERSION = '.*'/gm,
to: "VERSION = 'v<%= grunt.option('ver') %>'",
}, ],
replacements: [
{
from: /VERSION = '.*'/gm,
to: "VERSION = 'v<%= grunt.option('ver') %>'",
},
],
},
version: {
src: ['package.json'],
overwrite: true,
replacements: [{
replacements: [
{
from: /"_id": "dannjs@.*"/gm,
to: '"_id": "dannjs@<%= grunt.option("ver") %>"',
},
Expand All @@ -180,31 +190,38 @@ module.exports = (grunt) => {
testversion: {
src: ['test/manual-tests/browser/*/*.html'],
overwrite: true,
replacements: [{
from: /<span class="project-version">.*<\/span>/gm,
to: '<span class="project-version"><%= grunt.option("ver")%></span>',
}, ],
replacements: [
{
from: /<span class="project-version">.*<\/span>/gm,
to: '<span class="project-version"><%= grunt.option("ver")%></span>',
},
],
},
readmeversion: {
src: ['README.md'],
overwrite: true,
replacements: [{
from: /dann@v.*\/build/gm,
to: 'dann@v<%= grunt.option("ver") %>/build',
}, ],
replacements: [
{
from: /dann@v.*\/build/gm,
to: 'dann@v<%= grunt.option("ver") %>/build',
},
],
},
hljsdocs: {
src: ['docs/documentation/classes/*.html'],
overwrite: true,
replacements: [{
from: /\.\.\/highlight\/hljs\.min\.js/gm,
to: '../../highlight/hljs.min.js',
}, ],
replacements: [
{
from: /\.\.\/highlight\/hljs\.min\.js/gm,
to: '../../highlight/hljs.min.js',
},
],
},
hljsdocsIndex: {
src: ['docs/documentation/index.html'],
overwrite: true,
replacements: [{
replacements: [
{
from: /\.\.\/assets\//gm,
to: './assets/',
},
Expand Down Expand Up @@ -245,20 +262,20 @@ module.exports = (grunt) => {
'formatExamples',
'clean:unused',
'replace:addClass',
'replace:hljsdocsIndex'
'replace:hljsdocsIndex',
]);
grunt.registerTask('tag', [
'replace:version',
'replace:testversion',
'replace:readmeversion',
'replace:constant',
'build-fix'
'build-fix',
]);
grunt.registerTask('test', [
'doc-compile',
'build-unit',
'sampleTest:samples',
'mochaTest:test'
'mochaTest:test',
]);
grunt.registerTask('prod', ['build-fix', 'doc-compile', 'test']);
};
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_from": "dannjs",
"_id": "dannjs@2.4.1c",
"_id": "dannjs@2.4.1d",
"_inBundle": false,
"_integrity": "sha512-+Do7tE1EtLn/UMqyIy0V6dgLo43Wq6tj2vAY8oZTMHAY+ysYLJ2sT32H9DgZViL/B59XTIKN6BO8WEbn5pv8XA==",
"_location": "/dannjs",
Expand Down Expand Up @@ -56,7 +56,7 @@
"doc-server": "node docs/serve.js",
"makechangelog": "grunt makechangelog"
},
"version": "2.4.1c",
"version": "2.4.1d",
"keywords": [
"dann",
"dannjs",
Expand Down
Loading

0 comments on commit cae7de6

Please sign in to comment.