Open Chinese Convert  0.4.3
A project for conversion between Traditional and Simplified Chinese
demo.js
1 /**
2  * @file
3  * Example of Node.js API.
4  *
5  * @license
6  * Open Chinese Convert
7  *
8  * Copyright 2010-2013 BYVoid <byvoid@byvoid.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 /**
24  * @example node/demo.js
25  * This is an example of how to use the Node.js API.
26  */
27 
28 // In your project you should replace './opencc' with 'opencc'
29 var OpenCC = require('./opencc');
30 
31 // Load the default Simplified to Traditional config
32 var opencc = new OpenCC('zhs2zht.ini');
33 
34 // Set conversion mode
35 opencc.setConversionMode(OpenCC.CONVERSION_FAST);
36 
37 // Sync API
38 var converted = opencc.convertSync("汉字");
39 console.log(converted);
40 
41 // Async API
42 opencc.convert("汉字", function (err, converted) {
43  console.log(converted);
44 });