[Javascript] How to write a Javascript libarary

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Javascript] How to write a Javascript libarary相关的知识,希望对你有一定的参考价值。

Create package.json file

//npm settings
npm set init-author-name ‘username‘
npm set init-author-email ‘[email protected]
npm set init-author-url ‘http://username.com‘
npm set save-exact true

//create package.json
npm init

 

Pubish to github and tag it

git status
git add -A
git commit -m "commit message"
git push
git tag 1.0.0
git push --tags

 

Publish to npm

npm publish
npm info <project_name>

 

Release a new version

1. according to the changes to change the version in package.json
2. publish to git
3. publish tag to git
4. npm publish
5. npm info

 

Publishing a beta version

1. In package.json: "version": "1.2.0-beta.0",
2. publish to git
3. tag it in git
4. npm publish --tag beta
5. npm info

//install
npm install starwars-[email protected]
npm install starwars[email protected]

 

Mocha, chai testing:

var expect = require(‘chai‘).expect;
var starWars = require(‘./index‘);

describe(‘starwars-names‘, function() {
    describe(‘all‘, function(){
        //check return type
        it(‘should be an array of strings‘, function(){
            expect(starWars.all).to.satisfy(isArrayOfString);
            
            function isArrayOfString(array){
                return array.every(function(item){
                    return typeof item === ‘string‘;
                });
            }
        });
        
        //ccheck one of the value
        it(‘should includ Asajj Ventress‘, function(){
            expect(starWars.all).to.include(‘Asajj Ventress‘);
        });
    });
    
    describe(‘random‘, function(){
        it(‘should return one of the starwar names form all‘, function(){
            expect(starWars.all).to.include(starWars.random());
        })
    });
});

 

以上是关于[Javascript] How to write a Javascript libarary的主要内容,如果未能解决你的问题,请参考以下文章

[译注]How to Write a 21st Century Proof

如何写科技论文How to write a technical paper

how to write bash shell CGI under uHTTPd

How to Write Go Code

How to write XML-RPC clients

how to write an email