Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit7726b7d

Browse files
committed
rename polyfills -> utils. Improve utils documentation
1 parent0c7b687 commit7726b7d

File tree

17 files changed

+113
-8
lines changed

17 files changed

+113
-8
lines changed

‎lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ var ReactDOM = require('react-dom');
33
varSidePanel_1=require('./components/SidePanel');
44
varStatusBar_1=require('./components/StatusBar');
55
varsetup_1=require('./modules/setup');
6-
varpolyfills_1=require('./polyfills');
76
varstore_1=require('./store');
87
varsubscriptions_1=require('./subscriptions');
8+
varutils_1=require('./utils');
99
varinjectTapEventPlugin=require('react-tap-event-plugin');
1010
process.env.NODE_ENV='production';
1111
varMain=(function(){
1212
functionMain(){
1313
injectTapEventPlugin();
14-
polyfills_1.default();
14+
utils_1.default();
1515
store_1.default.dispatch(setup_1.setupVerify());
1616
this.side=SidePanel_1.sideElement.init();
1717
this.subscriptions=newsubscriptions_1.default();

‎lib/modules/tests/test-run/config-path.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
varpath_1=require('path');
3-
varsystem_1=require('../../../polyfills/system');
3+
varsystem_1=require('../../../utils/system');
44
functionconfigPath(_a){
55
vardir=_a.dir,tutorial=_a.tutorial,testPath=_a.testPath;
66
if(system_1.isWindows){

‎lib/modules/tutorial/utils/config-runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
varpath_1=require('path');
3-
varsystem_1=require('../../../polyfills/system');
3+
varsystem_1=require('../../../utils/system');
44
varnode_file_exists_1=require('node-file-exists');
55
functionconfigRunner(name,runner,dir){
66
varflatDep=path_1.join(dir,'node_modules',runner,'package.json');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
varfetch_1=require('../../utils/fetch');
3+
varapiCall=function(name){return("https://registry.npmjs.org/"+name);};
4+
functiongetLatestVersion(name,current){
5+
returnfetch_1.default(apiCall(name))
6+
.then(function(res){
7+
if(res){
8+
JSON.parse(res)['dist-tags'].latest;
9+
returntrue;
10+
}
11+
returnfalse;
12+
});
13+
}

‎lib/utils/fetch.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use strict";
2+
varfetch=function(url){
3+
returnnewPromise(function(resolve,reject){
4+
varlib=url.startsWith('https') ?require('https') :require('http');
5+
varrequest=lib.get(url,function(response){
6+
if(response.statusCode<200||response.statusCode>299){
7+
reject(newError('Failed to load page, status code: '+response.statusCode));
8+
}
9+
varbody=[];
10+
response.on('data',function(chunk){returnbody.push(chunk);});
11+
response.on('end',function(){returnresolve(body.join(''));});
12+
});
13+
request.on('error',function(err){returnreject(err);});
14+
});
15+
};
16+
Object.defineProperty(exports,"__esModule",{value:true});
17+
exports.default=fetch;

‎lib/utils/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
varobject_values_1=require('./object-values');
3+
functionloadPolyfills(){
4+
object_values_1.default();
5+
}
6+
Object.defineProperty(exports,"__esModule",{value:true});
7+
exports.default=loadPolyfills;

‎lib/utils/object-values.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
functionpolyfillObjectValues(){
3+
if(typeofObject.values!=='function'){
4+
Object.values=function(obj){
5+
varvals=newSet();
6+
for(varkeyinobj){
7+
vals.add(obj[key]);
8+
}
9+
returnArray.from(vals);
10+
};
11+
}
12+
}
13+
Object.defineProperty(exports,"__esModule",{value:true});
14+
exports.default=polyfillObjectValues;

‎lib/utils/system.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
exports.isWindows=window.navigator.appVersion.indexOf('Win')>-1||false;

‎src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import * as ReactDOM from 'react-dom';
44
import{SideRoot,sideElement}from'./components/SidePanel';
55
importaddToStatusBarfrom'./components/StatusBar';
66
import{setupVerify}from'./modules/setup';
7-
importloadPolyfillsfrom'./polyfills';
87
importstorefrom'./store';
98
importSubscriptionsfrom'./subscriptions';
9+
importloadPolyfillsfrom'./utils/polyfills';
1010
import*asinjectTapEventPluginfrom'react-tap-event-plugin';
1111

1212
// React optimization

‎src/modules/tests/test-run/config-path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import{join}from'path';
22

3-
import{isWindows}from'../../../polyfills/system';
3+
import{isWindows}from'../../../utils/system';
44

55
/**
66
* set paths to tests as absolute paths

‎src/modules/tutorial/utils/config-runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import{join}from'path';
2-
import{isWindows}from'../../../polyfills/system';
2+
import{isWindows}from'../../../utils/system';
33
importfileExistsfrom'node-file-exists';
44

55
/**

‎src/modules/tutorial/utils/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {join} from 'path';
22

33
import{configIssuesPath,configRepo}from'./config-repo';
44
importconfigRunnerfrom'./config-runner';
5-
import{isWindows}from'../../../polyfills/system';
5+
import{isWindows}from'../../../utils/system';
66
importfileExistsfrom'node-file-exists';
77

88
/**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
importfetchfrom'../../utils/fetch';
2+
3+
constapiCall=name=>`https://registry.npmjs.org/${name}`;
4+
5+
functiongetLatestVersion(name:string,current:string):Promise<boolean>{
6+
returnfetch(apiCall(name))
7+
.then((res:string)=>{
8+
if(res){
9+
JSON.parse(res)['dist-tags'].latest;
10+
returntrue;
11+
}
12+
returnfalse;
13+
});
14+
}

‎src/utils/fetch.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* fetch data from url
3+
*@param {string} url
4+
*@returns Promise
5+
*/
6+
constfetch=functionfetch(url:string):Promise<Object>{
7+
returnnewPromise((resolve,reject)=>{
8+
constlib=url.startsWith('https') ?require('https') :require('http');
9+
constrequest=lib.get(url,(response)=>{
10+
// handle http errors
11+
if(response.statusCode<200||response.statusCode>299){
12+
reject(newError('Failed to load page, status code: '+response.statusCode));
13+
}
14+
constbody=[];
15+
// on every content chunk, push it to the data array
16+
response.on('data',(chunk)=>body.push(chunk));
17+
// we are done, resolve promise with those joined chunks
18+
response.on('end',()=>resolve(body.join('')));
19+
});
20+
// handle connection errors of the request
21+
request.on('error',(err)=>reject(err))
22+
})
23+
};
24+
25+
exportdefaultfetch;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
importpolyfillObjectValuesfrom'./object-values';
22

3+
/**
4+
* calls list of polyfills
5+
*@returns void
6+
*/
37
exportdefaultfunctionloadPolyfills():void{
48
polyfillObjectValues();
59
}

‎src/polyfills/object-values.tsrenamed to‎src/utils/polyfills/object-values.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Object.values polyfill
3+
* https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Object/values
4+
*@returns void
5+
*/
16
exportdefaultfunctionpolyfillObjectValues():void{
27
// Object.values (ES7)
38
if(typeofObject.values!=='function'){
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
/**
2+
* checks if system is Windows
3+
*@returns boolean
4+
*/
15
exportconstisWindows=window.navigator.appVersion.indexOf('Win')>-1||false;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp